author | Christian Urban <christian.urban@kcl.ac.uk> |
Fri, 07 Jan 2022 22:25:26 +0000 | |
changeset 381 | 0c666a0c57d7 |
parent 379 | 28458dec90f8 |
child 385 | c80720289645 |
permissions | -rw-r--r-- |
365 | 1 |
|
2 |
theory SizeBound |
|
3 |
imports "Lexer" |
|
4 |
begin |
|
5 |
||
6 |
section \<open>Bit-Encodings\<close> |
|
7 |
||
8 |
datatype bit = Z | S |
|
9 |
||
10 |
fun code :: "val \<Rightarrow> bit list" |
|
11 |
where |
|
12 |
"code Void = []" |
|
13 |
| "code (Char c) = []" |
|
14 |
| "code (Left v) = Z # (code v)" |
|
15 |
| "code (Right v) = S # (code v)" |
|
16 |
| "code (Seq v1 v2) = (code v1) @ (code v2)" |
|
17 |
| "code (Stars []) = [S]" |
|
18 |
| "code (Stars (v # vs)) = (Z # code v) @ code (Stars vs)" |
|
19 |
||
20 |
||
21 |
fun |
|
22 |
Stars_add :: "val \<Rightarrow> val \<Rightarrow> val" |
|
23 |
where |
|
24 |
"Stars_add v (Stars vs) = Stars (v # vs)" |
|
25 |
||
26 |
function |
|
27 |
decode' :: "bit list \<Rightarrow> rexp \<Rightarrow> (val * bit list)" |
|
28 |
where |
|
29 |
"decode' ds ZERO = (Void, [])" |
|
30 |
| "decode' ds ONE = (Void, ds)" |
|
31 |
| "decode' ds (CH d) = (Char d, ds)" |
|
32 |
| "decode' [] (ALT r1 r2) = (Void, [])" |
|
33 |
| "decode' (Z # ds) (ALT r1 r2) = (let (v, ds') = decode' ds r1 in (Left v, ds'))" |
|
34 |
| "decode' (S # ds) (ALT r1 r2) = (let (v, ds') = decode' ds r2 in (Right v, ds'))" |
|
35 |
| "decode' ds (SEQ r1 r2) = (let (v1, ds') = decode' ds r1 in |
|
36 |
let (v2, ds'') = decode' ds' r2 in (Seq v1 v2, ds''))" |
|
37 |
| "decode' [] (STAR r) = (Void, [])" |
|
38 |
| "decode' (S # ds) (STAR r) = (Stars [], ds)" |
|
39 |
| "decode' (Z # ds) (STAR r) = (let (v, ds') = decode' ds r in |
|
40 |
let (vs, ds'') = decode' ds' (STAR r) |
|
41 |
in (Stars_add v vs, ds''))" |
|
42 |
by pat_completeness auto |
|
43 |
||
44 |
lemma decode'_smaller: |
|
45 |
assumes "decode'_dom (ds, r)" |
|
46 |
shows "length (snd (decode' ds r)) \<le> length ds" |
|
47 |
using assms |
|
48 |
apply(induct ds r) |
|
49 |
apply(auto simp add: decode'.psimps split: prod.split) |
|
50 |
using dual_order.trans apply blast |
|
51 |
by (meson dual_order.trans le_SucI) |
|
52 |
||
53 |
termination "decode'" |
|
54 |
apply(relation "inv_image (measure(%cs. size cs) <*lex*> measure(%s. size s)) (%(ds,r). (r,ds))") |
|
55 |
apply(auto dest!: decode'_smaller) |
|
56 |
by (metis less_Suc_eq_le snd_conv) |
|
57 |
||
58 |
definition |
|
59 |
decode :: "bit list \<Rightarrow> rexp \<Rightarrow> val option" |
|
60 |
where |
|
61 |
"decode ds r \<equiv> (let (v, ds') = decode' ds r |
|
62 |
in (if ds' = [] then Some v else None))" |
|
63 |
||
64 |
lemma decode'_code_Stars: |
|
65 |
assumes "\<forall>v\<in>set vs. \<Turnstile> v : r \<and> (\<forall>x. decode' (code v @ x) r = (v, x)) \<and> flat v \<noteq> []" |
|
66 |
shows "decode' (code (Stars vs) @ ds) (STAR r) = (Stars vs, ds)" |
|
67 |
using assms |
|
68 |
apply(induct vs) |
|
69 |
apply(auto) |
|
70 |
done |
|
71 |
||
72 |
lemma decode'_code: |
|
73 |
assumes "\<Turnstile> v : r" |
|
74 |
shows "decode' ((code v) @ ds) r = (v, ds)" |
|
75 |
using assms |
|
76 |
apply(induct v r arbitrary: ds) |
|
77 |
apply(auto) |
|
78 |
using decode'_code_Stars by blast |
|
79 |
||
80 |
lemma decode_code: |
|
81 |
assumes "\<Turnstile> v : r" |
|
82 |
shows "decode (code v) r = Some v" |
|
83 |
using assms unfolding decode_def |
|
84 |
by (smt append_Nil2 decode'_code old.prod.case) |
|
85 |
||
86 |
||
87 |
section {* Annotated Regular Expressions *} |
|
88 |
||
89 |
datatype arexp = |
|
90 |
AZERO |
|
91 |
| AONE "bit list" |
|
92 |
| ACHAR "bit list" char |
|
93 |
| ASEQ "bit list" arexp arexp |
|
94 |
| AALTs "bit list" "arexp list" |
|
95 |
| ASTAR "bit list" arexp |
|
96 |
||
97 |
abbreviation |
|
98 |
"AALT bs r1 r2 \<equiv> AALTs bs [r1, r2]" |
|
99 |
||
100 |
fun asize :: "arexp \<Rightarrow> nat" where |
|
101 |
"asize AZERO = 1" |
|
102 |
| "asize (AONE cs) = 1" |
|
103 |
| "asize (ACHAR cs c) = 1" |
|
104 |
| "asize (AALTs cs rs) = Suc (sum_list (map asize rs))" |
|
105 |
| "asize (ASEQ cs r1 r2) = Suc (asize r1 + asize r2)" |
|
106 |
| "asize (ASTAR cs r) = Suc (asize r)" |
|
107 |
||
108 |
fun |
|
109 |
erase :: "arexp \<Rightarrow> rexp" |
|
110 |
where |
|
111 |
"erase AZERO = ZERO" |
|
112 |
| "erase (AONE _) = ONE" |
|
113 |
| "erase (ACHAR _ c) = CH c" |
|
114 |
| "erase (AALTs _ []) = ZERO" |
|
115 |
| "erase (AALTs _ [r]) = (erase r)" |
|
116 |
| "erase (AALTs bs (r#rs)) = ALT (erase r) (erase (AALTs bs rs))" |
|
117 |
| "erase (ASEQ _ r1 r2) = SEQ (erase r1) (erase r2)" |
|
118 |
| "erase (ASTAR _ r) = STAR (erase r)" |
|
119 |
||
120 |
||
121 |
fun nonalt :: "arexp \<Rightarrow> bool" |
|
122 |
where |
|
123 |
"nonalt (AALTs bs2 rs) = False" |
|
124 |
| "nonalt r = True" |
|
125 |
||
126 |
||
127 |
fun fuse :: "bit list \<Rightarrow> arexp \<Rightarrow> arexp" where |
|
128 |
"fuse bs AZERO = AZERO" |
|
129 |
| "fuse bs (AONE cs) = AONE (bs @ cs)" |
|
130 |
| "fuse bs (ACHAR cs c) = ACHAR (bs @ cs) c" |
|
131 |
| "fuse bs (AALTs cs rs) = AALTs (bs @ cs) rs" |
|
132 |
| "fuse bs (ASEQ cs r1 r2) = ASEQ (bs @ cs) r1 r2" |
|
133 |
| "fuse bs (ASTAR cs r) = ASTAR (bs @ cs) r" |
|
134 |
||
135 |
lemma fuse_append: |
|
136 |
shows "fuse (bs1 @ bs2) r = fuse bs1 (fuse bs2 r)" |
|
137 |
apply(induct r) |
|
138 |
apply(auto) |
|
139 |
done |
|
140 |
||
141 |
||
142 |
fun intern :: "rexp \<Rightarrow> arexp" where |
|
143 |
"intern ZERO = AZERO" |
|
144 |
| "intern ONE = AONE []" |
|
145 |
| "intern (CH c) = ACHAR [] c" |
|
146 |
| "intern (ALT r1 r2) = AALT [] (fuse [Z] (intern r1)) |
|
147 |
(fuse [S] (intern r2))" |
|
148 |
| "intern (SEQ r1 r2) = ASEQ [] (intern r1) (intern r2)" |
|
149 |
| "intern (STAR r) = ASTAR [] (intern r)" |
|
150 |
||
151 |
||
152 |
fun retrieve :: "arexp \<Rightarrow> val \<Rightarrow> bit list" where |
|
153 |
"retrieve (AONE bs) Void = bs" |
|
154 |
| "retrieve (ACHAR bs c) (Char d) = bs" |
|
155 |
| "retrieve (AALTs bs [r]) v = bs @ retrieve r v" |
|
156 |
| "retrieve (AALTs bs (r#rs)) (Left v) = bs @ retrieve r v" |
|
157 |
| "retrieve (AALTs bs (r#rs)) (Right v) = bs @ retrieve (AALTs [] rs) v" |
|
158 |
| "retrieve (ASEQ bs r1 r2) (Seq v1 v2) = bs @ retrieve r1 v1 @ retrieve r2 v2" |
|
159 |
| "retrieve (ASTAR bs r) (Stars []) = bs @ [S]" |
|
160 |
| "retrieve (ASTAR bs r) (Stars (v#vs)) = |
|
161 |
bs @ [Z] @ retrieve r v @ retrieve (ASTAR [] r) (Stars vs)" |
|
162 |
||
163 |
||
164 |
||
165 |
fun |
|
166 |
bnullable :: "arexp \<Rightarrow> bool" |
|
167 |
where |
|
168 |
"bnullable (AZERO) = False" |
|
169 |
| "bnullable (AONE bs) = True" |
|
170 |
| "bnullable (ACHAR bs c) = False" |
|
171 |
| "bnullable (AALTs bs rs) = (\<exists>r \<in> set rs. bnullable r)" |
|
172 |
| "bnullable (ASEQ bs r1 r2) = (bnullable r1 \<and> bnullable r2)" |
|
173 |
| "bnullable (ASTAR bs r) = True" |
|
174 |
||
175 |
fun |
|
176 |
bmkeps :: "arexp \<Rightarrow> bit list" |
|
177 |
where |
|
178 |
"bmkeps(AONE bs) = bs" |
|
179 |
| "bmkeps(ASEQ bs r1 r2) = bs @ (bmkeps r1) @ (bmkeps r2)" |
|
180 |
| "bmkeps(AALTs bs [r]) = bs @ (bmkeps r)" |
|
181 |
| "bmkeps(AALTs bs (r#rs)) = (if bnullable(r) then bs @ (bmkeps r) else (bmkeps (AALTs bs rs)))" |
|
182 |
| "bmkeps(ASTAR bs r) = bs @ [S]" |
|
183 |
||
184 |
||
185 |
fun |
|
186 |
bder :: "char \<Rightarrow> arexp \<Rightarrow> arexp" |
|
187 |
where |
|
188 |
"bder c (AZERO) = AZERO" |
|
189 |
| "bder c (AONE bs) = AZERO" |
|
190 |
| "bder c (ACHAR bs d) = (if c = d then AONE bs else AZERO)" |
|
191 |
| "bder c (AALTs bs rs) = AALTs bs (map (bder c) rs)" |
|
192 |
| "bder c (ASEQ bs r1 r2) = |
|
193 |
(if bnullable r1 |
|
194 |
then AALT bs (ASEQ [] (bder c r1) r2) (fuse (bmkeps r1) (bder c r2)) |
|
195 |
else ASEQ bs (bder c r1) r2)" |
|
196 |
| "bder c (ASTAR bs r) = ASEQ bs (fuse [Z] (bder c r)) (ASTAR [] r)" |
|
197 |
||
198 |
||
199 |
fun |
|
200 |
bders :: "arexp \<Rightarrow> string \<Rightarrow> arexp" |
|
201 |
where |
|
202 |
"bders r [] = r" |
|
203 |
| "bders r (c#s) = bders (bder c r) s" |
|
204 |
||
205 |
lemma bders_append: |
|
206 |
"bders r (s1 @ s2) = bders (bders r s1) s2" |
|
207 |
apply(induct s1 arbitrary: r s2) |
|
208 |
apply(simp_all) |
|
209 |
done |
|
210 |
||
211 |
lemma bnullable_correctness: |
|
212 |
shows "nullable (erase r) = bnullable r" |
|
213 |
apply(induct r rule: erase.induct) |
|
214 |
apply(simp_all) |
|
215 |
done |
|
216 |
||
217 |
lemma erase_fuse: |
|
218 |
shows "erase (fuse bs r) = erase r" |
|
219 |
apply(induct r rule: erase.induct) |
|
220 |
apply(simp_all) |
|
221 |
done |
|
222 |
||
223 |
lemma erase_intern [simp]: |
|
224 |
shows "erase (intern r) = r" |
|
225 |
apply(induct r) |
|
226 |
apply(simp_all add: erase_fuse) |
|
227 |
done |
|
228 |
||
229 |
lemma erase_bder [simp]: |
|
230 |
shows "erase (bder a r) = der a (erase r)" |
|
231 |
apply(induct r rule: erase.induct) |
|
232 |
apply(simp_all add: erase_fuse bnullable_correctness) |
|
233 |
done |
|
234 |
||
235 |
lemma erase_bders [simp]: |
|
236 |
shows "erase (bders r s) = ders s (erase r)" |
|
237 |
apply(induct s arbitrary: r ) |
|
238 |
apply(simp_all) |
|
239 |
done |
|
240 |
||
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
241 |
lemma bnullable_fuse: |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
242 |
shows "bnullable (fuse bs r) = bnullable r" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
243 |
apply(induct r arbitrary: bs) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
244 |
apply(auto) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
245 |
done |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
246 |
|
365 | 247 |
lemma retrieve_encode_STARS: |
248 |
assumes "\<forall>v\<in>set vs. \<Turnstile> v : r \<and> code v = retrieve (intern r) v" |
|
249 |
shows "code (Stars vs) = retrieve (ASTAR [] (intern r)) (Stars vs)" |
|
250 |
using assms |
|
251 |
apply(induct vs) |
|
252 |
apply(simp_all) |
|
253 |
done |
|
254 |
||
255 |
||
256 |
lemma retrieve_fuse2: |
|
257 |
assumes "\<Turnstile> v : (erase r)" |
|
258 |
shows "retrieve (fuse bs r) v = bs @ retrieve r v" |
|
259 |
using assms |
|
260 |
apply(induct r arbitrary: v bs) |
|
261 |
apply(auto elim: Prf_elims)[4] |
|
262 |
defer |
|
263 |
using retrieve_encode_STARS |
|
264 |
apply(auto elim!: Prf_elims)[1] |
|
265 |
apply(case_tac vs) |
|
266 |
apply(simp) |
|
267 |
apply(simp) |
|
268 |
(* AALTs case *) |
|
269 |
apply(simp) |
|
270 |
apply(case_tac x2a) |
|
271 |
apply(simp) |
|
272 |
apply(auto elim!: Prf_elims)[1] |
|
273 |
apply(simp) |
|
274 |
apply(case_tac list) |
|
275 |
apply(simp) |
|
276 |
apply(auto) |
|
277 |
apply(auto elim!: Prf_elims)[1] |
|
278 |
done |
|
279 |
||
280 |
lemma retrieve_fuse: |
|
281 |
assumes "\<Turnstile> v : r" |
|
282 |
shows "retrieve (fuse bs (intern r)) v = bs @ retrieve (intern r) v" |
|
283 |
using assms |
|
284 |
by (simp_all add: retrieve_fuse2) |
|
285 |
||
286 |
||
287 |
lemma retrieve_code: |
|
288 |
assumes "\<Turnstile> v : r" |
|
289 |
shows "code v = retrieve (intern r) v" |
|
290 |
using assms |
|
291 |
apply(induct v r ) |
|
292 |
apply(simp_all add: retrieve_fuse retrieve_encode_STARS) |
|
293 |
done |
|
294 |
||
295 |
||
296 |
lemma bnullable_Hdbmkeps_Hd: |
|
297 |
assumes "bnullable a" |
|
298 |
shows "bmkeps (AALTs bs (a # rs)) = bs @ (bmkeps a)" |
|
299 |
using assms |
|
300 |
by (metis bmkeps.simps(3) bmkeps.simps(4) list.exhaust) |
|
301 |
||
302 |
lemma r1: |
|
303 |
assumes "\<not> bnullable a" "bnullable (AALTs bs rs)" |
|
304 |
shows "bmkeps (AALTs bs (a # rs)) = bmkeps (AALTs bs rs)" |
|
305 |
using assms |
|
306 |
apply(induct rs) |
|
307 |
apply(auto) |
|
308 |
done |
|
309 |
||
310 |
lemma r2: |
|
311 |
assumes "x \<in> set rs" "bnullable x" |
|
312 |
shows "bnullable (AALTs bs rs)" |
|
313 |
using assms |
|
314 |
apply(induct rs) |
|
315 |
apply(auto) |
|
316 |
done |
|
317 |
||
318 |
lemma r3: |
|
319 |
assumes "\<not> bnullable r" |
|
320 |
" \<exists> x \<in> set rs. bnullable x" |
|
321 |
shows "retrieve (AALTs bs rs) (mkeps (erase (AALTs bs rs))) = |
|
322 |
retrieve (AALTs bs (r # rs)) (mkeps (erase (AALTs bs (r # rs))))" |
|
323 |
using assms |
|
324 |
apply(induct rs arbitrary: r bs) |
|
325 |
apply(auto)[1] |
|
326 |
apply(auto) |
|
327 |
using bnullable_correctness apply blast |
|
328 |
apply(auto simp add: bnullable_correctness mkeps_nullable retrieve_fuse2) |
|
329 |
apply(subst retrieve_fuse2[symmetric]) |
|
330 |
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) |
|
331 |
apply(simp) |
|
332 |
apply(case_tac "bnullable a") |
|
333 |
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) |
|
334 |
apply(drule_tac x="a" in meta_spec) |
|
335 |
apply(drule_tac x="bs" in meta_spec) |
|
336 |
apply(drule meta_mp) |
|
337 |
apply(simp) |
|
338 |
apply(drule meta_mp) |
|
339 |
apply(auto) |
|
340 |
apply(subst retrieve_fuse2[symmetric]) |
|
341 |
apply(case_tac rs) |
|
342 |
apply(simp) |
|
343 |
apply(auto)[1] |
|
344 |
apply (simp add: bnullable_correctness) |
|
345 |
apply (metis append_Nil2 bnullable_correctness erase_fuse fuse.simps(4) list.set_intros(1) mkeps.simps(3) mkeps_nullable nullable.simps(4) r2) |
|
346 |
apply (simp add: bnullable_correctness) |
|
347 |
apply (metis append_Nil2 bnullable_correctness erase.simps(6) erase_fuse fuse.simps(4) list.set_intros(2) mkeps.simps(3) mkeps_nullable r2) |
|
348 |
apply(simp) |
|
349 |
done |
|
350 |
||
351 |
||
352 |
lemma t: |
|
353 |
assumes "\<forall>r \<in> set rs. nullable (erase r) \<longrightarrow> bmkeps r = retrieve r (mkeps (erase r))" |
|
354 |
"nullable (erase (AALTs bs rs))" |
|
355 |
shows " bmkeps (AALTs bs rs) = retrieve (AALTs bs rs) (mkeps (erase (AALTs bs rs)))" |
|
356 |
using assms |
|
357 |
apply(induct rs arbitrary: bs) |
|
358 |
apply(simp) |
|
359 |
apply(auto simp add: bnullable_correctness) |
|
360 |
apply(case_tac rs) |
|
361 |
apply(auto simp add: bnullable_correctness)[2] |
|
362 |
apply(subst r1) |
|
363 |
apply(simp) |
|
364 |
apply(rule r2) |
|
365 |
apply(assumption) |
|
366 |
apply(simp) |
|
367 |
apply(drule_tac x="bs" in meta_spec) |
|
368 |
apply(drule meta_mp) |
|
369 |
apply(auto)[1] |
|
370 |
prefer 2 |
|
371 |
apply(case_tac "bnullable a") |
|
372 |
apply(subst bnullable_Hdbmkeps_Hd) |
|
373 |
apply blast |
|
374 |
apply(subgoal_tac "nullable (erase a)") |
|
375 |
prefer 2 |
|
376 |
using bnullable_correctness apply blast |
|
377 |
apply (metis (no_types, lifting) erase.simps(5) erase.simps(6) list.exhaust mkeps.simps(3) retrieve.simps(3) retrieve.simps(4)) |
|
378 |
apply(subst r1) |
|
379 |
apply(simp) |
|
380 |
using r2 apply blast |
|
381 |
apply(drule_tac x="bs" in meta_spec) |
|
382 |
apply(drule meta_mp) |
|
383 |
apply(auto)[1] |
|
384 |
apply(simp) |
|
385 |
using r3 apply blast |
|
386 |
apply(auto) |
|
387 |
using r3 by blast |
|
388 |
||
389 |
lemma bmkeps_retrieve: |
|
390 |
assumes "nullable (erase r)" |
|
391 |
shows "bmkeps r = retrieve r (mkeps (erase r))" |
|
392 |
using assms |
|
393 |
apply(induct r) |
|
394 |
apply(simp) |
|
395 |
apply(simp) |
|
396 |
apply(simp) |
|
397 |
apply(simp) |
|
398 |
defer |
|
399 |
apply(simp) |
|
400 |
apply(rule t) |
|
401 |
apply(auto) |
|
402 |
done |
|
403 |
||
404 |
lemma bder_retrieve: |
|
405 |
assumes "\<Turnstile> v : der c (erase r)" |
|
406 |
shows "retrieve (bder c r) v = retrieve r (injval (erase r) c v)" |
|
407 |
using assms |
|
408 |
apply(induct r arbitrary: v rule: erase.induct) |
|
409 |
apply(simp) |
|
410 |
apply(erule Prf_elims) |
|
411 |
apply(simp) |
|
412 |
apply(erule Prf_elims) |
|
413 |
apply(simp) |
|
414 |
apply(case_tac "c = ca") |
|
415 |
apply(simp) |
|
416 |
apply(erule Prf_elims) |
|
417 |
apply(simp) |
|
418 |
apply(simp) |
|
419 |
apply(erule Prf_elims) |
|
420 |
apply(simp) |
|
421 |
apply(erule Prf_elims) |
|
422 |
apply(simp) |
|
423 |
apply(simp) |
|
424 |
apply(rename_tac "r\<^sub>1" "r\<^sub>2" rs v) |
|
425 |
apply(erule Prf_elims) |
|
426 |
apply(simp) |
|
427 |
apply(simp) |
|
428 |
apply(case_tac rs) |
|
429 |
apply(simp) |
|
430 |
apply(simp) |
|
431 |
apply (smt Prf_elims(3) injval.simps(2) injval.simps(3) retrieve.simps(4) retrieve.simps(5) same_append_eq) |
|
432 |
apply(simp) |
|
433 |
apply(case_tac "nullable (erase r1)") |
|
434 |
apply(simp) |
|
435 |
apply(erule Prf_elims) |
|
436 |
apply(subgoal_tac "bnullable r1") |
|
437 |
prefer 2 |
|
438 |
using bnullable_correctness apply blast |
|
439 |
apply(simp) |
|
440 |
apply(erule Prf_elims) |
|
441 |
apply(simp) |
|
442 |
apply(subgoal_tac "bnullable r1") |
|
443 |
prefer 2 |
|
444 |
using bnullable_correctness apply blast |
|
445 |
apply(simp) |
|
446 |
apply(simp add: retrieve_fuse2) |
|
447 |
apply(simp add: bmkeps_retrieve) |
|
448 |
apply(simp) |
|
449 |
apply(erule Prf_elims) |
|
450 |
apply(simp) |
|
451 |
using bnullable_correctness apply blast |
|
452 |
apply(rename_tac bs r v) |
|
453 |
apply(simp) |
|
454 |
apply(erule Prf_elims) |
|
455 |
apply(clarify) |
|
456 |
apply(erule Prf_elims) |
|
457 |
apply(clarify) |
|
458 |
apply(subst injval.simps) |
|
459 |
apply(simp del: retrieve.simps) |
|
460 |
apply(subst retrieve.simps) |
|
461 |
apply(subst retrieve.simps) |
|
462 |
apply(simp) |
|
463 |
apply(simp add: retrieve_fuse2) |
|
464 |
done |
|
465 |
||
466 |
||
467 |
||
468 |
lemma MAIN_decode: |
|
469 |
assumes "\<Turnstile> v : ders s r" |
|
470 |
shows "Some (flex r id s v) = decode (retrieve (bders (intern r) s) v) r" |
|
471 |
using assms |
|
472 |
proof (induct s arbitrary: v rule: rev_induct) |
|
473 |
case Nil |
|
474 |
have "\<Turnstile> v : ders [] r" by fact |
|
475 |
then have "\<Turnstile> v : r" by simp |
|
476 |
then have "Some v = decode (retrieve (intern r) v) r" |
|
477 |
using decode_code retrieve_code by auto |
|
478 |
then show "Some (flex r id [] v) = decode (retrieve (bders (intern r) []) v) r" |
|
479 |
by simp |
|
480 |
next |
|
481 |
case (snoc c s v) |
|
482 |
have IH: "\<And>v. \<Turnstile> v : ders s r \<Longrightarrow> |
|
483 |
Some (flex r id s v) = decode (retrieve (bders (intern r) s) v) r" by fact |
|
484 |
have asm: "\<Turnstile> v : ders (s @ [c]) r" by fact |
|
485 |
then have asm2: "\<Turnstile> injval (ders s r) c v : ders s r" |
|
486 |
by (simp add: Prf_injval ders_append) |
|
487 |
have "Some (flex r id (s @ [c]) v) = Some (flex r id s (injval (ders s r) c v))" |
|
488 |
by (simp add: flex_append) |
|
489 |
also have "... = decode (retrieve (bders (intern r) s) (injval (ders s r) c v)) r" |
|
490 |
using asm2 IH by simp |
|
491 |
also have "... = decode (retrieve (bder c (bders (intern r) s)) v) r" |
|
492 |
using asm by (simp_all add: bder_retrieve ders_append) |
|
493 |
finally show "Some (flex r id (s @ [c]) v) = |
|
494 |
decode (retrieve (bders (intern r) (s @ [c])) v) r" by (simp add: bders_append) |
|
495 |
qed |
|
496 |
||
497 |
||
498 |
definition blex where |
|
499 |
"blex a s \<equiv> if bnullable (bders a s) then Some (bmkeps (bders a s)) else None" |
|
500 |
||
501 |
||
502 |
||
503 |
definition blexer where |
|
504 |
"blexer r s \<equiv> if bnullable (bders (intern r) s) then |
|
505 |
decode (bmkeps (bders (intern r) s)) r else None" |
|
506 |
||
507 |
lemma blexer_correctness: |
|
508 |
shows "blexer r s = lexer r s" |
|
509 |
proof - |
|
510 |
{ define bds where "bds \<equiv> bders (intern r) s" |
|
511 |
define ds where "ds \<equiv> ders s r" |
|
512 |
assume asm: "nullable ds" |
|
513 |
have era: "erase bds = ds" |
|
514 |
unfolding ds_def bds_def by simp |
|
515 |
have mke: "\<Turnstile> mkeps ds : ds" |
|
516 |
using asm by (simp add: mkeps_nullable) |
|
517 |
have "decode (bmkeps bds) r = decode (retrieve bds (mkeps ds)) r" |
|
518 |
using bmkeps_retrieve |
|
519 |
using asm era by (simp add: bmkeps_retrieve) |
|
520 |
also have "... = Some (flex r id s (mkeps ds))" |
|
521 |
using mke by (simp_all add: MAIN_decode ds_def bds_def) |
|
522 |
finally have "decode (bmkeps bds) r = Some (flex r id s (mkeps ds))" |
|
523 |
unfolding bds_def ds_def . |
|
524 |
} |
|
525 |
then show "blexer r s = lexer r s" |
|
526 |
unfolding blexer_def lexer_flex |
|
527 |
apply(subst bnullable_correctness[symmetric]) |
|
528 |
apply(simp) |
|
529 |
done |
|
530 |
qed |
|
531 |
||
532 |
||
533 |
fun distinctBy :: "'a list \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'b set \<Rightarrow> 'a list" |
|
534 |
where |
|
535 |
"distinctBy [] f acc = []" |
|
536 |
| "distinctBy (x#xs) f acc = |
|
537 |
(if (f x) \<in> acc then distinctBy xs f acc |
|
538 |
else x # (distinctBy xs f ({f x} \<union> acc)))" |
|
539 |
||
374 | 540 |
lemma dB_single_step: |
541 |
shows "distinctBy (a#rs) f {} = a # distinctBy rs f {f a}" |
|
542 |
by simp |
|
365 | 543 |
|
544 |
fun flts :: "arexp list \<Rightarrow> arexp list" |
|
545 |
where |
|
546 |
"flts [] = []" |
|
547 |
| "flts (AZERO # rs) = flts rs" |
|
548 |
| "flts ((AALTs bs rs1) # rs) = (map (fuse bs) rs1) @ flts rs" |
|
549 |
| "flts (r1 # rs) = r1 # flts rs" |
|
550 |
||
551 |
||
552 |
||
553 |
fun bsimp_ASEQ :: "bit list \<Rightarrow> arexp \<Rightarrow> arexp \<Rightarrow> arexp" |
|
554 |
where |
|
555 |
"bsimp_ASEQ _ AZERO _ = AZERO" |
|
556 |
| "bsimp_ASEQ _ _ AZERO = AZERO" |
|
557 |
| "bsimp_ASEQ bs1 (AONE bs2) r2 = fuse (bs1 @ bs2) r2" |
|
558 |
| "bsimp_ASEQ bs1 r1 r2 = ASEQ bs1 r1 r2" |
|
559 |
||
560 |
||
561 |
fun bsimp_AALTs :: "bit list \<Rightarrow> arexp list \<Rightarrow> arexp" |
|
562 |
where |
|
563 |
"bsimp_AALTs _ [] = AZERO" |
|
564 |
| "bsimp_AALTs bs1 [r] = fuse bs1 r" |
|
565 |
| "bsimp_AALTs bs1 rs = AALTs bs1 rs" |
|
566 |
||
567 |
||
568 |
fun bsimp :: "arexp \<Rightarrow> arexp" |
|
569 |
where |
|
570 |
"bsimp (ASEQ bs1 r1 r2) = bsimp_ASEQ bs1 (bsimp r1) (bsimp r2)" |
|
374 | 571 |
| "bsimp (AALTs bs1 rs) = bsimp_AALTs bs1 (distinctBy (flts (map bsimp rs)) erase {}) " |
365 | 572 |
| "bsimp r = r" |
573 |
||
574 |
||
575 |
fun |
|
576 |
bders_simp :: "arexp \<Rightarrow> string \<Rightarrow> arexp" |
|
577 |
where |
|
578 |
"bders_simp r [] = r" |
|
579 |
| "bders_simp r (c # s) = bders_simp (bsimp (bder c r)) s" |
|
580 |
||
581 |
definition blexer_simp where |
|
582 |
"blexer_simp r s \<equiv> if bnullable (bders_simp (intern r) s) then |
|
374 | 583 |
decode (bmkeps (bders_simp (intern r) s)) r else None" |
365 | 584 |
|
585 |
export_code bders_simp in Scala module_name Example |
|
586 |
||
587 |
lemma bders_simp_append: |
|
588 |
shows "bders_simp r (s1 @ s2) = bders_simp (bders_simp r s1) s2" |
|
589 |
apply(induct s1 arbitrary: r s2) |
|
374 | 590 |
apply(simp_all) |
365 | 591 |
done |
592 |
||
593 |
lemma L_bsimp_ASEQ: |
|
594 |
"L (SEQ (erase r1) (erase r2)) = L (erase (bsimp_ASEQ bs r1 r2))" |
|
595 |
apply(induct bs r1 r2 rule: bsimp_ASEQ.induct) |
|
596 |
apply(simp_all) |
|
597 |
by (metis erase_fuse fuse.simps(4)) |
|
598 |
||
599 |
lemma L_bsimp_AALTs: |
|
600 |
"L (erase (AALTs bs rs)) = L (erase (bsimp_AALTs bs rs))" |
|
601 |
apply(induct bs rs rule: bsimp_AALTs.induct) |
|
602 |
apply(simp_all add: erase_fuse) |
|
603 |
done |
|
604 |
||
605 |
lemma L_erase_AALTs: |
|
606 |
shows "L (erase (AALTs bs rs)) = \<Union> (L ` erase ` (set rs))" |
|
607 |
apply(induct rs) |
|
608 |
apply(simp) |
|
609 |
apply(simp) |
|
610 |
apply(case_tac rs) |
|
611 |
apply(simp) |
|
612 |
apply(simp) |
|
613 |
done |
|
614 |
||
615 |
lemma L_erase_flts: |
|
616 |
shows "\<Union> (L ` erase ` (set (flts rs))) = \<Union> (L ` erase ` (set rs))" |
|
617 |
apply(induct rs rule: flts.induct) |
|
618 |
apply(simp_all) |
|
619 |
apply(auto) |
|
620 |
using L_erase_AALTs erase_fuse apply auto[1] |
|
621 |
by (simp add: L_erase_AALTs erase_fuse) |
|
622 |
||
623 |
lemma L_erase_dB_acc: |
|
624 |
shows "( \<Union>(L ` acc) \<union> ( \<Union> (L ` erase ` (set (distinctBy rs erase acc) ) ) )) = \<Union>(L ` acc) \<union> \<Union> (L ` erase ` (set rs))" |
|
625 |
apply(induction rs arbitrary: acc) |
|
626 |
apply simp |
|
627 |
apply simp |
|
628 |
by (smt (z3) SUP_absorb UN_insert sup_assoc sup_commute) |
|
629 |
||
630 |
lemma L_erase_dB: |
|
631 |
shows " ( \<Union> (L ` erase ` (set (distinctBy rs erase {}) ) ) ) = \<Union> (L ` erase ` (set rs))" |
|
632 |
by (metis L_erase_dB_acc Un_commute Union_image_empty) |
|
633 |
||
634 |
lemma L_bsimp_erase: |
|
635 |
shows "L (erase r) = L (erase (bsimp r))" |
|
636 |
apply(induct r) |
|
637 |
apply(simp) |
|
638 |
apply(simp) |
|
639 |
apply(simp) |
|
640 |
apply(auto simp add: Sequ_def)[1] |
|
641 |
apply(subst L_bsimp_ASEQ[symmetric]) |
|
642 |
apply(auto simp add: Sequ_def)[1] |
|
643 |
apply(subst (asm) L_bsimp_ASEQ[symmetric]) |
|
644 |
apply(auto simp add: Sequ_def)[1] |
|
374 | 645 |
apply(simp) |
646 |
apply(subst L_bsimp_AALTs[symmetric]) |
|
647 |
defer |
|
648 |
apply(simp) |
|
365 | 649 |
apply(subst (2)L_erase_AALTs) |
650 |
apply(subst L_erase_dB) |
|
651 |
apply(subst L_erase_flts) |
|
652 |
apply(auto) |
|
374 | 653 |
apply (simp add: L_erase_AALTs) |
365 | 654 |
using L_erase_AALTs by blast |
655 |
||
374 | 656 |
|
657 |
||
365 | 658 |
lemma bsimp_ASEQ0: |
659 |
shows "bsimp_ASEQ bs r1 AZERO = AZERO" |
|
660 |
apply(induct r1) |
|
661 |
apply(auto) |
|
662 |
done |
|
663 |
||
664 |
lemma bsimp_ASEQ1: |
|
665 |
assumes "r1 \<noteq> AZERO" "r2 \<noteq> AZERO" "\<forall>bs. r1 \<noteq> AONE bs" |
|
666 |
shows "bsimp_ASEQ bs r1 r2 = ASEQ bs r1 r2" |
|
667 |
using assms |
|
668 |
apply(induct bs r1 r2 rule: bsimp_ASEQ.induct) |
|
669 |
apply(auto) |
|
670 |
done |
|
671 |
||
672 |
lemma bsimp_ASEQ2: |
|
673 |
shows "bsimp_ASEQ bs (AONE bs1) r2 = fuse (bs @ bs1) r2" |
|
674 |
apply(induct r2) |
|
675 |
apply(auto) |
|
676 |
done |
|
677 |
||
678 |
||
679 |
lemma L_bders_simp: |
|
680 |
shows "L (erase (bders_simp r s)) = L (erase (bders r s))" |
|
681 |
apply(induct s arbitrary: r rule: rev_induct) |
|
374 | 682 |
apply(simp) |
365 | 683 |
apply(simp) |
684 |
apply(simp add: ders_append) |
|
685 |
apply(simp add: bders_simp_append) |
|
686 |
apply(simp add: L_bsimp_erase[symmetric]) |
|
687 |
by (simp add: der_correctness) |
|
688 |
||
689 |
||
690 |
lemma b2: |
|
691 |
assumes "bnullable r" |
|
692 |
shows "bmkeps (fuse bs r) = bs @ bmkeps r" |
|
693 |
by (simp add: assms bmkeps_retrieve bnullable_correctness erase_fuse mkeps_nullable retrieve_fuse2) |
|
694 |
||
695 |
||
696 |
lemma b4: |
|
697 |
shows "bnullable (bders_simp r s) = bnullable (bders r s)" |
|
698 |
by (metis L_bders_simp bnullable_correctness lexer.simps(1) lexer_correct_None option.distinct(1)) |
|
699 |
||
700 |
lemma qq1: |
|
701 |
assumes "\<exists>r \<in> set rs. bnullable r" |
|
702 |
shows "bmkeps (AALTs bs (rs @ rs1)) = bmkeps (AALTs bs rs)" |
|
703 |
using assms |
|
704 |
apply(induct rs arbitrary: rs1 bs) |
|
705 |
apply(simp) |
|
706 |
apply(simp) |
|
707 |
by (metis Nil_is_append_conv bmkeps.simps(4) neq_Nil_conv bnullable_Hdbmkeps_Hd split_list_last) |
|
708 |
||
709 |
lemma qq2: |
|
710 |
assumes "\<forall>r \<in> set rs. \<not> bnullable r" "\<exists>r \<in> set rs1. bnullable r" |
|
711 |
shows "bmkeps (AALTs bs (rs @ rs1)) = bmkeps (AALTs bs rs1)" |
|
712 |
using assms |
|
713 |
apply(induct rs arbitrary: rs1 bs) |
|
714 |
apply(simp) |
|
715 |
apply(simp) |
|
716 |
by (metis append_assoc in_set_conv_decomp r1 r2) |
|
717 |
||
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
718 |
lemma qq3: |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
719 |
assumes "bnullable (AALTs bs (rs @ rs1))" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
720 |
"bnullable (AALTs bs (rs @ rs2))" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
721 |
"\<lbrakk>bnullable (AALTs bs rs1); bnullable (AALTs bs rs2); \<forall>r\<in>set rs. \<not>bnullable r\<rbrakk> \<Longrightarrow> |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
722 |
bmkeps (AALTs bs rs1) = bmkeps (AALTs bs rs2)" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
723 |
shows "bmkeps (AALTs bs (rs @ rs1)) = bmkeps (AALTs bs (rs @ rs2))" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
724 |
using assms |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
725 |
apply(case_tac "\<exists>r \<in> set rs. bnullable r") |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
726 |
using qq1 apply auto[1] |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
727 |
by (metis UnE bnullable.simps(4) qq2 set_append) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
728 |
|
365 | 729 |
|
373 | 730 |
lemma flts_append: |
731 |
shows "flts (xs1 @ xs2) = flts xs1 @ flts xs2" |
|
732 |
by (induct xs1 arbitrary: xs2 rule: flts.induct)(auto) |
|
365 | 733 |
|
734 |
lemma k0a: |
|
735 |
shows "flts [AALTs bs rs] = map (fuse bs) rs" |
|
736 |
apply(simp) |
|
737 |
done |
|
738 |
||
739 |
||
740 |
lemma bsimp_AALTs_qq: |
|
741 |
assumes "1 < length rs" |
|
742 |
shows "bsimp_AALTs bs rs = AALTs bs rs" |
|
743 |
using assms |
|
744 |
apply(case_tac rs) |
|
745 |
apply(simp) |
|
746 |
apply(case_tac list) |
|
747 |
apply(simp_all) |
|
748 |
done |
|
749 |
||
750 |
||
751 |
||
752 |
lemma bbbbs1: |
|
753 |
shows "nonalt r \<or> (\<exists>bs rs. r = AALTs bs rs)" |
|
754 |
using nonalt.elims(3) by auto |
|
755 |
||
756 |
||
757 |
||
758 |
fun nonazero :: "arexp \<Rightarrow> bool" |
|
759 |
where |
|
760 |
"nonazero AZERO = False" |
|
761 |
| "nonazero r = True" |
|
762 |
||
763 |
||
764 |
lemma flts_single1: |
|
765 |
assumes "nonalt r" "nonazero r" |
|
766 |
shows "flts [r] = [r]" |
|
767 |
using assms |
|
768 |
apply(induct r) |
|
769 |
apply(auto) |
|
770 |
done |
|
771 |
||
772 |
||
773 |
||
774 |
lemma q3a: |
|
775 |
assumes "\<exists>r \<in> set rs. bnullable r" |
|
776 |
shows "bmkeps (AALTs bs (map (fuse bs1) rs)) = bmkeps (AALTs (bs@bs1) rs)" |
|
777 |
using assms |
|
778 |
apply(induct rs arbitrary: bs bs1) |
|
779 |
apply(simp) |
|
780 |
apply(simp) |
|
781 |
apply(auto) |
|
782 |
apply (metis append_assoc b2 bnullable_correctness erase_fuse bnullable_Hdbmkeps_Hd) |
|
783 |
apply(case_tac "bnullable a") |
|
784 |
apply (metis append.assoc b2 bnullable_correctness erase_fuse bnullable_Hdbmkeps_Hd) |
|
785 |
apply(case_tac rs) |
|
786 |
apply(simp) |
|
787 |
apply(simp) |
|
788 |
apply(auto)[1] |
|
789 |
apply (metis bnullable_correctness erase_fuse)+ |
|
790 |
done |
|
791 |
||
792 |
lemma qq4: |
|
793 |
assumes "\<exists>x\<in>set list. bnullable x" |
|
794 |
shows "\<exists>x\<in>set (flts list). bnullable x" |
|
795 |
using assms |
|
796 |
apply(induct list rule: flts.induct) |
|
797 |
apply(auto) |
|
798 |
by (metis UnCI bnullable_correctness erase_fuse imageI) |
|
799 |
||
800 |
||
801 |
lemma qs3: |
|
802 |
assumes "\<exists>r \<in> set rs. bnullable r" |
|
803 |
shows "bmkeps (AALTs bs rs) = bmkeps (AALTs bs (flts rs))" |
|
804 |
using assms |
|
805 |
apply(induct rs arbitrary: bs taking: size rule: measure_induct) |
|
806 |
apply(case_tac x) |
|
807 |
apply(simp) |
|
808 |
apply(simp) |
|
809 |
apply(case_tac a) |
|
810 |
apply(simp) |
|
811 |
apply (simp add: r1) |
|
812 |
apply(simp) |
|
813 |
apply (simp add: bnullable_Hdbmkeps_Hd) |
|
814 |
apply(simp) |
|
815 |
apply(case_tac "flts list") |
|
816 |
apply(simp) |
|
817 |
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) |
|
818 |
apply(simp) |
|
819 |
apply (simp add: r1) |
|
820 |
prefer 3 |
|
821 |
apply(simp) |
|
822 |
apply (simp add: bnullable_Hdbmkeps_Hd) |
|
823 |
prefer 2 |
|
824 |
apply(simp) |
|
825 |
apply(case_tac "\<exists>x\<in>set x52. bnullable x") |
|
826 |
apply(case_tac "list") |
|
827 |
apply(simp) |
|
828 |
apply (metis b2 fuse.simps(4) q3a r2) |
|
829 |
apply(erule disjE) |
|
830 |
apply(subst qq1) |
|
831 |
apply(auto)[1] |
|
832 |
apply (metis bnullable_correctness erase_fuse) |
|
833 |
apply(simp) |
|
834 |
apply (metis b2 fuse.simps(4) q3a r2) |
|
835 |
apply(simp) |
|
836 |
apply(auto)[1] |
|
837 |
apply(subst qq1) |
|
838 |
apply (metis bnullable_correctness erase_fuse image_eqI set_map) |
|
839 |
apply (metis b2 fuse.simps(4) q3a r2) |
|
840 |
apply(subst qq1) |
|
841 |
apply (metis bnullable_correctness erase_fuse image_eqI set_map) |
|
842 |
apply (metis b2 fuse.simps(4) q3a r2) |
|
843 |
apply(simp) |
|
844 |
apply(subst qq2) |
|
845 |
apply (metis bnullable_correctness erase_fuse imageE set_map) |
|
846 |
prefer 2 |
|
847 |
apply(case_tac "list") |
|
848 |
apply(simp) |
|
849 |
apply(simp) |
|
850 |
apply (simp add: qq4) |
|
851 |
apply(simp) |
|
852 |
apply(auto) |
|
853 |
apply(case_tac list) |
|
854 |
apply(simp) |
|
855 |
apply(simp) |
|
856 |
apply (simp add: bnullable_Hdbmkeps_Hd) |
|
857 |
apply(case_tac "bnullable (ASEQ x41 x42 x43)") |
|
858 |
apply(case_tac list) |
|
859 |
apply(simp) |
|
860 |
apply(simp) |
|
861 |
apply (simp add: bnullable_Hdbmkeps_Hd) |
|
862 |
apply(simp) |
|
863 |
using qq4 r1 r2 by auto |
|
864 |
||
865 |
lemma bder_fuse: |
|
866 |
shows "bder c (fuse bs a) = fuse bs (bder c a)" |
|
867 |
apply(induct a arbitrary: bs c) |
|
868 |
apply(simp_all) |
|
869 |
done |
|
870 |
||
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
871 |
inductive |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
872 |
rrewrite:: "arexp \<Rightarrow> arexp \<Rightarrow> bool" ("_ \<leadsto> _" [99, 99] 99) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
873 |
where |
365 | 874 |
"ASEQ bs AZERO r2 \<leadsto> AZERO" |
875 |
| "ASEQ bs r1 AZERO \<leadsto> AZERO" |
|
876 |
| "ASEQ bs (AONE bs1) r \<leadsto> fuse (bs@bs1) r" |
|
877 |
| "r1 \<leadsto> r2 \<Longrightarrow> ASEQ bs r1 r3 \<leadsto> ASEQ bs r2 r3" |
|
878 |
| "r3 \<leadsto> r4 \<Longrightarrow> ASEQ bs r1 r3 \<leadsto> ASEQ bs r1 r4" |
|
879 |
| "r \<leadsto> r' \<Longrightarrow> (AALTs bs (rs1 @ [r] @ rs2)) \<leadsto> (AALTs bs (rs1 @ [r'] @ rs2))" |
|
880 |
(*context rule for eliminating 0, alts--corresponds to the recursive call flts r::rs = r::(flts rs)*) |
|
377 | 881 |
| "AALTs bs (rsa@ [AZERO] @ rsb) \<leadsto> AALTs bs (rsa @ rsb)" |
882 |
| "AALTs bs (rsa@ [AALTs bs1 rs1] @ rsb) \<leadsto> AALTs bs (rsa@(map (fuse bs1) rs1)@rsb)" |
|
365 | 883 |
(*the below rule for extracting common prefixes between a list of rexp's bitcodes*) |
375
f83271c585d2
deleted one rewrite rule
Christian Urban <christian.urban@kcl.ac.uk>
parents:
374
diff
changeset
|
884 |
(***| "AALTs bs (map (fuse bs1) rs) \<leadsto> AALTs (bs@bs1) rs"******) |
365 | 885 |
(*opposite direction also allowed, which means bits are free to be moved around |
886 |
as long as they are on the right path*) |
|
887 |
| "AALTs (bs@bs1) rs \<leadsto> AALTs bs (map (fuse bs1) rs)" |
|
888 |
| "AALTs bs [] \<leadsto> AZERO" |
|
889 |
| "AALTs bs [r] \<leadsto> fuse bs r" |
|
890 |
| "erase a1 = erase a2 \<Longrightarrow> AALTs bs (rsa@[a1]@rsb@[a2]@rsc) \<leadsto> AALTs bs (rsa@[a1]@rsb@rsc)" |
|
891 |
||
892 |
||
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
893 |
inductive |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
894 |
rrewrites:: "arexp \<Rightarrow> arexp \<Rightarrow> bool" ("_ \<leadsto>* _" [100, 100] 100) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
895 |
where |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
896 |
rs1[intro, simp]:"r \<leadsto>* r" |
365 | 897 |
| rs2[intro]: "\<lbrakk>r1 \<leadsto>* r2; r2 \<leadsto> r3\<rbrakk> \<Longrightarrow> r1 \<leadsto>* r3" |
898 |
||
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
899 |
inductive |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
900 |
srewrites:: "arexp list \<Rightarrow> arexp list \<Rightarrow> bool" (" _ s\<leadsto>* _" [100, 100] 100) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
901 |
where |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
902 |
ss1: "[] s\<leadsto>* []" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
903 |
| ss2: "\<lbrakk>r \<leadsto>* r'; rs s\<leadsto>* rs'\<rbrakk> \<Longrightarrow> (r#rs) s\<leadsto>* (r'#rs')" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
904 |
|
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
905 |
(* |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
906 |
rs1 = [r1, r2, ..., rn] rs2 = [r1', r2', ..., rn'] |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
907 |
[r1, r2, ..., rn] \<leadsto>* [r1', r2, ..., rn] \<leadsto>* [...r2',...] \<leadsto>* [r1', r2',... rn'] |
365 | 908 |
*) |
909 |
||
910 |
||
911 |
||
912 |
lemma r_in_rstar : "r1 \<leadsto> r2 \<Longrightarrow> r1 \<leadsto>* r2" |
|
913 |
using rrewrites.intros(1) rrewrites.intros(2) by blast |
|
914 |
||
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
915 |
lemma real_trans[trans]: |
365 | 916 |
assumes a1: "r1 \<leadsto>* r2" and a2: "r2 \<leadsto>* r3" |
917 |
shows "r1 \<leadsto>* r3" |
|
918 |
using a2 a1 |
|
919 |
apply(induct r2 r3 arbitrary: r1 rule: rrewrites.induct) |
|
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
920 |
apply(auto) |
365 | 921 |
done |
922 |
||
923 |
||
924 |
lemma many_steps_later: "\<lbrakk>r1 \<leadsto> r2; r2 \<leadsto>* r3 \<rbrakk> \<Longrightarrow> r1 \<leadsto>* r3" |
|
925 |
by (meson r_in_rstar real_trans) |
|
926 |
||
927 |
||
928 |
lemma contextrewrites1: "r \<leadsto>* r' \<Longrightarrow> (AALTs bs (r#rs)) \<leadsto>* (AALTs bs (r'#rs))" |
|
929 |
apply(induct r r' rule: rrewrites.induct) |
|
930 |
apply simp |
|
931 |
by (metis append_Cons append_Nil rrewrite.intros(6) rs2) |
|
932 |
||
933 |
||
934 |
lemma contextrewrites2: "r \<leadsto>* r' \<Longrightarrow> (AALTs bs (rs1@[r]@rs)) \<leadsto>* (AALTs bs (rs1@[r']@rs))" |
|
935 |
apply(induct r r' rule: rrewrites.induct) |
|
936 |
apply simp |
|
937 |
using rrewrite.intros(6) by blast |
|
938 |
||
939 |
||
940 |
||
941 |
lemma srewrites_alt: "rs1 s\<leadsto>* rs2 \<Longrightarrow> (AALTs bs (rs@rs1)) \<leadsto>* (AALTs bs (rs@rs2))" |
|
942 |
||
943 |
apply(induct rs1 rs2 arbitrary: bs rs rule: srewrites.induct) |
|
944 |
apply(rule rs1) |
|
945 |
apply(drule_tac x = "bs" in meta_spec) |
|
946 |
apply(drule_tac x = "rsa@[r']" in meta_spec) |
|
947 |
apply simp |
|
948 |
apply(rule real_trans) |
|
949 |
prefer 2 |
|
950 |
apply(assumption) |
|
951 |
apply(drule contextrewrites2) |
|
952 |
apply auto |
|
953 |
done |
|
954 |
||
955 |
||
374 | 956 |
corollary srewrites_alt1: |
957 |
assumes "rs1 s\<leadsto>* rs2" |
|
958 |
shows "AALTs bs rs1 \<leadsto>* AALTs bs rs2" |
|
959 |
using assms |
|
365 | 960 |
by (metis append.left_neutral srewrites_alt) |
961 |
||
962 |
||
374 | 963 |
lemma star_seq: |
964 |
assumes "r1 \<leadsto>* r2" |
|
965 |
shows "ASEQ bs r1 r3 \<leadsto>* ASEQ bs r2 r3" |
|
966 |
using assms |
|
967 |
apply(induct r1 r2 arbitrary: r3 rule: rrewrites.induct) |
|
968 |
apply(auto intro: rrewrite.intros) |
|
969 |
done |
|
365 | 970 |
|
374 | 971 |
lemma star_seq2: |
972 |
assumes "r3 \<leadsto>* r4" |
|
973 |
shows "ASEQ bs r1 r3 \<leadsto>* ASEQ bs r1 r4" |
|
974 |
using assms |
|
975 |
apply(induct r3 r4 arbitrary: r1 rule: rrewrites.induct) |
|
976 |
apply(auto intro: rrewrite.intros) |
|
977 |
done |
|
365 | 978 |
|
374 | 979 |
lemma continuous_rewrite: |
980 |
assumes "r1 \<leadsto>* AZERO" |
|
981 |
shows "ASEQ bs1 r1 r2 \<leadsto>* AZERO" |
|
982 |
using assms |
|
365 | 983 |
apply(induction ra\<equiv>"r1" rb\<equiv>"AZERO" arbitrary: bs1 r1 r2 rule: rrewrites.induct) |
374 | 984 |
apply(auto intro: rrewrite.intros r_in_rstar star_seq) |
985 |
by (meson rrewrite.intros(1) rs2 star_seq) |
|
365 | 986 |
|
987 |
||
988 |
||
374 | 989 |
lemma bsimp_aalts_simpcases: |
990 |
shows "AONE bs \<leadsto>* bsimp (AONE bs)" |
|
991 |
and "AZERO \<leadsto>* bsimp AZERO" |
|
992 |
and "ACHAR bs c \<leadsto>* bsimp (ACHAR bs c)" |
|
993 |
by (simp_all) |
|
365 | 994 |
|
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
995 |
lemma trivialbsimpsrewrites: |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
996 |
"\<lbrakk>\<And>x. x \<in> set rs \<Longrightarrow> x \<leadsto>* f x \<rbrakk> \<Longrightarrow> rs s\<leadsto>* (map f rs)" |
365 | 997 |
|
998 |
apply(induction rs) |
|
999 |
apply simp |
|
1000 |
apply(rule ss1) |
|
1001 |
by (metis insert_iff list.simps(15) list.simps(9) srewrites.simps) |
|
1002 |
||
1003 |
||
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1004 |
lemma bsimp_AALTsrewrites: |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1005 |
"AALTs bs1 rs \<leadsto>* bsimp_AALTs bs1 rs" |
365 | 1006 |
apply(induction rs) |
1007 |
apply simp |
|
1008 |
apply(rule r_in_rstar) |
|
375
f83271c585d2
deleted one rewrite rule
Christian Urban <christian.urban@kcl.ac.uk>
parents:
374
diff
changeset
|
1009 |
apply (simp add: rrewrite.intros(10)) |
365 | 1010 |
apply(case_tac "rs = Nil") |
1011 |
apply(simp) |
|
1012 |
using rrewrite.intros(12) apply auto[1] |
|
375
f83271c585d2
deleted one rewrite rule
Christian Urban <christian.urban@kcl.ac.uk>
parents:
374
diff
changeset
|
1013 |
using r_in_rstar rrewrite.intros(11) apply presburger |
365 | 1014 |
apply(subgoal_tac "length (a#rs) > 1") |
1015 |
apply(simp add: bsimp_AALTs_qq) |
|
1016 |
apply(simp) |
|
1017 |
done |
|
1018 |
||
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1019 |
(* rewrites for lists *) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1020 |
inductive |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1021 |
frewrites:: "arexp list \<Rightarrow> arexp list \<Rightarrow> bool" (" _ f\<leadsto>* _" [100, 100] 100) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1022 |
where |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1023 |
fs1: "[] f\<leadsto>* []" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1024 |
| fs2: "\<lbrakk>rs f\<leadsto>* rs'\<rbrakk> \<Longrightarrow> (AZERO#rs) f\<leadsto>* rs'" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1025 |
| fs3: "\<lbrakk>rs f\<leadsto>* rs'\<rbrakk> \<Longrightarrow> ((AALTs bs rs1) # rs) f\<leadsto>* ((map (fuse bs) rs1) @ rs')" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1026 |
| fs4: "\<lbrakk>rs f\<leadsto>* rs'; nonalt r; nonazero r\<rbrakk> \<Longrightarrow> (r#rs) f\<leadsto>* (r#rs')" |
365 | 1027 |
|
1028 |
||
1029 |
||
1030 |
lemma flts_prepend: "\<lbrakk>nonalt a; nonazero a\<rbrakk> \<Longrightarrow> flts (a#rs) = a # (flts rs)" |
|
373 | 1031 |
by (metis append_Cons append_Nil flts_single1 flts_append) |
365 | 1032 |
|
1033 |
lemma fltsfrewrites: "rs f\<leadsto>* (flts rs)" |
|
1034 |
apply(induction rs) |
|
1035 |
apply simp |
|
1036 |
apply(rule fs1) |
|
1037 |
||
1038 |
apply(case_tac "a = AZERO") |
|
1039 |
||
1040 |
||
1041 |
using fs2 apply auto[1] |
|
1042 |
apply(case_tac "\<exists>bs rs. a = AALTs bs rs") |
|
1043 |
apply(erule exE)+ |
|
1044 |
||
1045 |
apply (simp add: fs3) |
|
1046 |
apply(subst flts_prepend) |
|
1047 |
apply(rule nonalt.elims(2)) |
|
1048 |
prefer 2 |
|
1049 |
thm nonalt.elims |
|
1050 |
||
1051 |
apply blast |
|
1052 |
||
1053 |
using bbbbs1 apply blast |
|
374 | 1054 |
apply(simp)+ |
365 | 1055 |
|
1056 |
apply (meson nonazero.elims(3)) |
|
1057 |
||
1058 |
by (meson fs4 nonalt.elims(3) nonazero.elims(3)) |
|
1059 |
||
1060 |
||
374 | 1061 |
lemma rrewrite0away: "AALTs bs (AZERO # rsb) \<leadsto> AALTs bs rsb" |
377 | 1062 |
by (metis append_Cons append_Nil rrewrite.intros(7)) |
365 | 1063 |
|
1064 |
||
1065 |
lemma frewritesaalts:"rs f\<leadsto>* rs' \<Longrightarrow> (AALTs bs (rs1@rs)) \<leadsto>* (AALTs bs (rs1@rs'))" |
|
1066 |
apply(induct rs rs' arbitrary: bs rs1 rule:frewrites.induct) |
|
1067 |
apply(rule rs1) |
|
1068 |
apply(drule_tac x = "bs" in meta_spec) |
|
1069 |
apply(drule_tac x = "rs1 @ [AZERO]" in meta_spec) |
|
1070 |
apply(rule real_trans) |
|
1071 |
apply simp |
|
377 | 1072 |
using rrewrite.intros(7) apply auto[1] |
365 | 1073 |
apply(drule_tac x = "bsa" in meta_spec) |
1074 |
apply(drule_tac x = "rs1a @ [AALTs bs rs1]" in meta_spec) |
|
1075 |
apply(rule real_trans) |
|
1076 |
apply simp |
|
377 | 1077 |
using r_in_rstar rrewrite.intros(8) apply auto[1] |
365 | 1078 |
apply(drule_tac x = "bs" in meta_spec) |
1079 |
apply(drule_tac x = "rs1@[r]" in meta_spec) |
|
1080 |
apply(rule real_trans) |
|
1081 |
apply simp |
|
1082 |
apply auto |
|
1083 |
done |
|
1084 |
||
1085 |
lemma fltsrewrites: " AALTs bs1 rs \<leadsto>* AALTs bs1 (flts rs)" |
|
1086 |
apply(induction rs) |
|
1087 |
apply simp |
|
1088 |
apply(case_tac "a = AZERO") |
|
377 | 1089 |
apply (metis flts.simps(2) many_steps_later rrewrite0away) |
365 | 1090 |
|
1091 |
apply(case_tac "\<exists>bs2 rs2. a = AALTs bs2 rs2") |
|
1092 |
apply(erule exE)+ |
|
374 | 1093 |
apply(simp) |
365 | 1094 |
prefer 2 |
1095 |
||
1096 |
apply(subst flts_prepend) |
|
1097 |
||
1098 |
apply (meson nonalt.elims(3)) |
|
1099 |
||
1100 |
apply (meson nonazero.elims(3)) |
|
1101 |
apply(subgoal_tac "(a#rs) f\<leadsto>* (a#flts rs)") |
|
1102 |
apply (metis append_Nil frewritesaalts) |
|
1103 |
apply (meson fltsfrewrites fs4 nonalt.elims(3) nonazero.elims(3)) |
|
373 | 1104 |
by (metis append_Cons append_Nil fltsfrewrites frewritesaalts flts_append k0a) |
365 | 1105 |
|
1106 |
lemma alts_simpalts: "\<And>bs1 rs. (\<And>x. x \<in> set rs \<Longrightarrow> x \<leadsto>* bsimp x) \<Longrightarrow> |
|
1107 |
AALTs bs1 rs \<leadsto>* AALTs bs1 (map bsimp rs)" |
|
1108 |
apply(subgoal_tac " rs s\<leadsto>* (map bsimp rs)") |
|
1109 |
prefer 2 |
|
1110 |
using trivialbsimpsrewrites apply auto[1] |
|
1111 |
using srewrites_alt1 by auto |
|
1112 |
||
1113 |
||
1114 |
lemma threelistsappend: "rsa@a#rsb = (rsa@[a])@rsb" |
|
1115 |
apply auto |
|
1116 |
done |
|
1117 |
||
1118 |
||
1119 |
lemma somewhereInside: "r \<in> set rs \<Longrightarrow> \<exists>rs1 rs2. rs = rs1@[r]@rs2" |
|
1120 |
using split_list by fastforce |
|
1121 |
||
1122 |
lemma somewhereMapInside: "f r \<in> f ` set rs \<Longrightarrow> \<exists>rs1 rs2 a. rs = rs1@[a]@rs2 \<and> f a = f r" |
|
1123 |
apply auto |
|
1124 |
by (metis split_list) |
|
1125 |
||
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1126 |
lemma alts_dBrewrites_withFront: |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1127 |
"AALTs bs (rsa @ rs) \<leadsto>* AALTs bs (rsa @ distinctBy rs erase (erase ` set rsa))" |
365 | 1128 |
apply(induction rs arbitrary: rsa) |
1129 |
apply simp |
|
1130 |
apply(drule_tac x = "rsa@[a]" in meta_spec) |
|
1131 |
apply(subst threelistsappend) |
|
1132 |
apply(rule real_trans) |
|
1133 |
apply simp |
|
1134 |
apply(case_tac "a \<in> set rsa") |
|
1135 |
apply simp |
|
1136 |
apply(drule somewhereInside) |
|
1137 |
apply(erule exE)+ |
|
1138 |
apply simp |
|
1139 |
apply(subgoal_tac " AALTs bs |
|
1140 |
(rs1 @ |
|
1141 |
a # |
|
1142 |
rs2 @ |
|
1143 |
a # |
|
1144 |
distinctBy rs erase |
|
1145 |
(insert (erase a) |
|
1146 |
(erase ` |
|
1147 |
(set rs1 \<union> set rs2)))) \<leadsto> AALTs bs (rs1@ a # rs2 @ distinctBy rs erase |
|
1148 |
(insert (erase a) |
|
1149 |
(erase ` |
|
1150 |
(set rs1 \<union> set rs2)))) ") |
|
1151 |
prefer 2 |
|
375
f83271c585d2
deleted one rewrite rule
Christian Urban <christian.urban@kcl.ac.uk>
parents:
374
diff
changeset
|
1152 |
using rrewrite.intros(12) apply force |
365 | 1153 |
using r_in_rstar apply force |
1154 |
apply(subgoal_tac "erase ` set (rsa @ [a]) = insert (erase a) (erase ` set rsa)") |
|
1155 |
prefer 2 |
|
1156 |
||
1157 |
apply auto[1] |
|
1158 |
apply(case_tac "erase a \<in> erase `set rsa") |
|
1159 |
||
1160 |
apply simp |
|
1161 |
apply(subgoal_tac "AALTs bs (rsa @ a # distinctBy rs erase (insert (erase a) (erase ` set rsa))) \<leadsto> |
|
1162 |
AALTs bs (rsa @ distinctBy rs erase (insert (erase a) (erase ` set rsa)))") |
|
1163 |
apply force |
|
375
f83271c585d2
deleted one rewrite rule
Christian Urban <christian.urban@kcl.ac.uk>
parents:
374
diff
changeset
|
1164 |
apply (smt (verit, ccfv_threshold) append_Cons append_assoc append_self_conv2 r_in_rstar rrewrite.intros(12) same_append_eq somewhereMapInside) |
365 | 1165 |
by force |
1166 |
||
1167 |
||
1168 |
||
1169 |
lemma alts_dBrewrites: "AALTs bs rs \<leadsto>* AALTs bs (distinctBy rs erase {})" |
|
1170 |
apply(induction rs) |
|
1171 |
apply simp |
|
1172 |
apply simp |
|
1173 |
using alts_dBrewrites_withFront |
|
1174 |
by (metis append_Nil dB_single_step empty_set image_empty) |
|
1175 |
||
374 | 1176 |
lemma bsimp_rewrite: |
1177 |
shows "r \<leadsto>* bsimp r" |
|
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1178 |
proof (induction r rule: bsimp.induct) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1179 |
case (1 bs1 r1 r2) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1180 |
then show "ASEQ bs1 r1 r2 \<leadsto>* bsimp (ASEQ bs1 r1 r2)" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1181 |
apply(simp) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1182 |
apply(case_tac "bsimp r1 = AZERO") |
365 | 1183 |
apply simp |
1184 |
using continuous_rewrite apply blast |
|
1185 |
apply(case_tac "\<exists>bs. bsimp r1 = AONE bs") |
|
1186 |
apply(erule exE) |
|
1187 |
apply simp |
|
1188 |
apply(subst bsimp_ASEQ2) |
|
1189 |
apply (meson real_trans rrewrite.intros(3) rrewrites.intros(2) star_seq star_seq2) |
|
1190 |
apply (smt (verit, best) bsimp_ASEQ0 bsimp_ASEQ1 real_trans rrewrite.intros(2) rs2 star_seq star_seq2) |
|
1191 |
done |
|
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1192 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1193 |
case (2 bs1 rs) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1194 |
then show "AALTs bs1 rs \<leadsto>* bsimp (AALTs bs1 rs)" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1195 |
by (metis alts_dBrewrites alts_simpalts bsimp.simps(2) bsimp_AALTsrewrites fltsrewrites real_trans) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1196 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1197 |
case "3_1" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1198 |
then show "AZERO \<leadsto>* bsimp AZERO" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1199 |
by simp |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1200 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1201 |
case ("3_2" v) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1202 |
then show "AONE v \<leadsto>* bsimp (AONE v)" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1203 |
by simp |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1204 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1205 |
case ("3_3" v va) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1206 |
then show "ACHAR v va \<leadsto>* bsimp (ACHAR v va)" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1207 |
by simp |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1208 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1209 |
case ("3_4" v va) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1210 |
then show "ASTAR v va \<leadsto>* bsimp (ASTAR v va)" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1211 |
by simp |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1212 |
qed |
365 | 1213 |
|
373 | 1214 |
lemma rewrite_non_nullable_strong: |
1215 |
assumes "r1 \<leadsto> r2" |
|
1216 |
shows "bnullable r1 = bnullable r2" |
|
1217 |
using assms |
|
1218 |
apply(induction r1 r2 rule: rrewrite.induct) |
|
1219 |
apply(auto) |
|
1220 |
apply(metis bnullable_correctness erase_fuse)+ |
|
1221 |
apply(metis UnCI bnullable_correctness erase_fuse imageI) |
|
1222 |
apply(metis bnullable_correctness erase_fuse)+ |
|
1223 |
done |
|
365 | 1224 |
|
373 | 1225 |
lemma rewrite_nullable: |
1226 |
assumes "r1 \<leadsto> r2" "bnullable r1" |
|
1227 |
shows "bnullable r2" |
|
1228 |
using assms rewrite_non_nullable_strong |
|
1229 |
by auto |
|
1230 |
||
1231 |
lemma rewritesnullable: |
|
1232 |
assumes "r1 \<leadsto>* r2" "bnullable r1" |
|
1233 |
shows "bnullable r2" |
|
1234 |
using assms |
|
365 | 1235 |
apply(induction r1 r2 rule: rrewrites.induct) |
1236 |
apply simp |
|
373 | 1237 |
using rewrite_non_nullable_strong by blast |
365 | 1238 |
|
1239 |
||
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1240 |
lemma bnullable_segment: |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1241 |
"bnullable (AALTs bs (rs1@[r]@rs2)) \<Longrightarrow> bnullable (AALTs bs rs1) \<or> bnullable (AALTs bs rs2) \<or> bnullable r" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1242 |
by auto |
365 | 1243 |
|
1244 |
lemma bnullablewhichbmkeps: "\<lbrakk>bnullable (AALTs bs (rs1@[r]@rs2)); \<not> bnullable (AALTs bs rs1); bnullable r \<rbrakk> |
|
1245 |
\<Longrightarrow> bmkeps (AALTs bs (rs1@[r]@rs2)) = bs @ (bmkeps r)" |
|
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1246 |
|
365 | 1247 |
using qq2 bnullable_Hdbmkeps_Hd by force |
1248 |
||
1249 |
lemma spillbmkepslistr: "bnullable (AALTs bs1 rs1) |
|
1250 |
\<Longrightarrow> bmkeps (AALTs bs (AALTs bs1 rs1 # rsb)) = bmkeps (AALTs bs ( map (fuse bs1) rs1 @ rsb))" |
|
1251 |
apply(subst bnullable_Hdbmkeps_Hd) |
|
1252 |
||
1253 |
apply simp |
|
1254 |
by (metis bmkeps.simps(3) k0a list.set_intros(1) qq1 qq4 qs3) |
|
1255 |
||
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1256 |
lemma third_segment_bnullable: |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1257 |
"\<lbrakk>bnullable (AALTs bs (rs1@rs2@rs3)); \<not>bnullable (AALTs bs rs1); \<not>bnullable (AALTs bs rs2)\<rbrakk> \<Longrightarrow> |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1258 |
bnullable (AALTs bs rs3)" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1259 |
apply(auto) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1260 |
done |
365 | 1261 |
|
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1262 |
lemma third_segment_bmkeps: |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1263 |
"\<lbrakk>bnullable (AALTs bs (rs1@rs2@rs3)); \<not>bnullable (AALTs bs rs1); \<not>bnullable (AALTs bs rs2)\<rbrakk> \<Longrightarrow> |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1264 |
bmkeps (AALTs bs (rs1@rs2@rs3) ) = bmkeps (AALTs bs rs3)" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1265 |
by (metis bnullable.simps(1) bnullable.simps(4) bsimp_AALTs.simps(1) bsimp_AALTsrewrites qq2 rewritesnullable self_append_conv third_segment_bnullable) |
365 | 1266 |
|
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1267 |
lemma rewrite_bmkepsalt: |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1268 |
"\<lbrakk>bnullable (AALTs bs (rsa @ AALTs bs1 rs1 # rsb)); bnullable (AALTs bs (rsa @ map (fuse bs1) rs1 @ rsb))\<rbrakk> |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1269 |
\<Longrightarrow> bmkeps (AALTs bs (rsa @ AALTs bs1 rs1 # rsb)) = bmkeps (AALTs bs (rsa @ map (fuse bs1) rs1 @ rsb))" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1270 |
apply(rule qq3) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1271 |
apply(simp) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1272 |
apply(simp) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1273 |
apply(case_tac "bnullable (AALTs bs1 rs1)") |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1274 |
using spillbmkepslistr apply blast |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1275 |
apply(subst qq2) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1276 |
apply(auto simp add: bnullable_fuse r1) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1277 |
done |
365 | 1278 |
|
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1279 |
lemma rewrite_bmkeps_aux: |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1280 |
assumes "r1 \<leadsto> r2" "bnullable r1" "bnullable r2" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1281 |
shows "bmkeps r1 = bmkeps r2" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1282 |
using assms |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1283 |
proof (induction r1 r2 rule: rrewrite.induct) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1284 |
case (1 bs r2) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1285 |
then show ?case by simp |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1286 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1287 |
case (2 bs r1) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1288 |
then show ?case by simp |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1289 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1290 |
case (3 bs bs1 r) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1291 |
then show ?case by (simp add: b2) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1292 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1293 |
case (4 r1 r2 bs r3) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1294 |
then show ?case by simp |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1295 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1296 |
case (5 r3 r4 bs r1) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1297 |
then show ?case by simp |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1298 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1299 |
case (6 r r' bs rs1 rs2) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1300 |
then show ?case |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1301 |
by (metis append_Cons append_Nil bnullable.simps(4) bnullable_segment bnullablewhichbmkeps qq3 r1 rewrite_non_nullable_strong) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1302 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1303 |
case (7 bs rsa rsb) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1304 |
then show ?case |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1305 |
by (metis bnullable.simps(1) bnullable.simps(4) bnullable_segment qq1 qq2 rewrite_nullable rrewrite.intros(10) rrewrite0away third_segment_bmkeps) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1306 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1307 |
case (8 bs rsa bs1 rs1 rsb) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1308 |
then show ?case |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1309 |
by (simp add: rewrite_bmkepsalt) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1310 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1311 |
case (9 bs bs1 rs) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1312 |
then show ?case |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1313 |
by (simp add: q3a) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1314 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1315 |
case (10 bs) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1316 |
then show ?case |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1317 |
by fastforce |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1318 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1319 |
case (11 bs r) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1320 |
then show ?case |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1321 |
by (simp add: b2) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1322 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1323 |
case (12 a1 a2 bs rsa rsb rsc) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1324 |
then show ?case |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1325 |
by (smt (verit, ccfv_threshold) append_Cons append_eq_appendI append_self_conv2 bnullable_correctness list.set_intros(1) qq3 r1) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1326 |
qed |
365 | 1327 |
|
1328 |
||
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1329 |
lemma rewrite_bmkeps: |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1330 |
assumes "r1 \<leadsto> r2" "bnullable r1" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1331 |
shows "bmkeps r1 = bmkeps r2" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1332 |
using assms(1) assms(2) rewrite_bmkeps_aux rewrite_nullable by blast |
365 | 1333 |
|
1334 |
||
373 | 1335 |
lemma rewrites_bmkeps: |
1336 |
assumes "r1 \<leadsto>* r2" "bnullable r1" |
|
1337 |
shows "bmkeps r1 = bmkeps r2" |
|
1338 |
using assms |
|
1339 |
proof(induction r1 r2 rule: rrewrites.induct) |
|
1340 |
case (rs1 r) |
|
1341 |
then show "bmkeps r = bmkeps r" by simp |
|
1342 |
next |
|
1343 |
case (rs2 r1 r2 r3) |
|
1344 |
then have IH: "bmkeps r1 = bmkeps r2" by simp |
|
1345 |
have a1: "bnullable r1" by fact |
|
1346 |
have a2: "r1 \<leadsto>* r2" by fact |
|
1347 |
have a3: "r2 \<leadsto> r3" by fact |
|
1348 |
have a4: "bnullable r2" using a1 a2 by (simp add: rewritesnullable) |
|
1349 |
then have "bmkeps r2 = bmkeps r3" using rewrite_bmkeps a3 a4 by simp |
|
1350 |
then show "bmkeps r1 = bmkeps r3" using IH by simp |
|
1351 |
qed |
|
365 | 1352 |
|
1353 |
lemma alts_rewrite_front: "r \<leadsto> r' \<Longrightarrow> AALTs bs (r # rs) \<leadsto> AALTs bs (r' # rs)" |
|
1354 |
by (metis append_Cons append_Nil rrewrite.intros(6)) |
|
1355 |
||
1356 |
lemma to_zero_in_alt: " AALT bs (ASEQ [] AZERO r) r2 \<leadsto> AALT bs AZERO r2" |
|
1357 |
by (simp add: alts_rewrite_front rrewrite.intros(1)) |
|
1358 |
||
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1359 |
lemma rewrite_fuse: |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1360 |
assumes "r2 \<leadsto> r3" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1361 |
shows "fuse bs r2 \<leadsto>* fuse bs r3" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1362 |
using assms |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1363 |
proof(induction r2 r3 arbitrary: bs rule: rrewrite.induct) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1364 |
case (1 bs r2) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1365 |
then show ?case |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1366 |
by (simp add: continuous_rewrite) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1367 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1368 |
case (2 bs r1) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1369 |
then show ?case |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1370 |
using rrewrite.intros(2) by force |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1371 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1372 |
case (3 bs bs1 r) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1373 |
then show ?case |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1374 |
by (metis fuse.simps(5) fuse_append r_in_rstar rrewrite.intros(3)) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1375 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1376 |
case (4 r1 r2 bs r3) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1377 |
then show ?case |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1378 |
by (simp add: r_in_rstar star_seq) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1379 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1380 |
case (5 r3 r4 bs r1) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1381 |
then show ?case |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1382 |
using fuse.simps(5) r_in_rstar star_seq2 by auto |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1383 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1384 |
case (6 r r' bs rs1 rs2) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1385 |
then show ?case |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1386 |
using contextrewrites2 r_in_rstar by force |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1387 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1388 |
case (7 bs rsa rsb) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1389 |
then show ?case |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1390 |
using rrewrite.intros(7) by force |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1391 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1392 |
case (8 bs rsa bs1 rs1 rsb) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1393 |
then show ?case |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1394 |
using rrewrite.intros(8) by force |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1395 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1396 |
case (9 bs bs1 rs) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1397 |
then show ?case |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1398 |
by (metis append.assoc fuse.simps(4) r_in_rstar rrewrite.intros(9)) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1399 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1400 |
case (10 bs) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1401 |
then show ?case |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1402 |
by (simp add: r_in_rstar rrewrite.intros(10)) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1403 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1404 |
case (11 bs r) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1405 |
then show ?case |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1406 |
by (metis fuse.simps(4) fuse_append r_in_rstar rrewrite.intros(11)) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1407 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1408 |
case (12 a1 a2 bs rsa rsb rsc) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1409 |
then show ?case |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1410 |
using fuse.simps(4) r_in_rstar rrewrite.intros(12) by auto |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1411 |
qed |
365 | 1412 |
|
374 | 1413 |
lemma rewrites_fuse: |
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1414 |
assumes "r1 \<leadsto>* r2" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1415 |
shows "fuse bs r1 \<leadsto>* fuse bs r2" |
374 | 1416 |
using assms |
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1417 |
apply(induction r1 r2 arbitrary: bs rule: rrewrites.induct) |
374 | 1418 |
apply(auto intro: rewrite_fuse real_trans) |
1419 |
done |
|
365 | 1420 |
|
374 | 1421 |
lemma bder_fuse_list: |
1422 |
shows "map (bder c \<circ> fuse bs1) rs1 = map (fuse bs1 \<circ> bder c) rs1" |
|
1423 |
apply(induction rs1) |
|
1424 |
apply(simp_all add: bder_fuse) |
|
1425 |
done |
|
365 | 1426 |
|
1427 |
||
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1428 |
lemma rewrite_der_altmiddle: |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1429 |
"bder c (AALTs bs (rsa @ AALTs bs1 rs1 # rsb)) \<leadsto>* bder c (AALTs bs (rsa @ map (fuse bs1) rs1 @ rsb))" |
365 | 1430 |
apply simp |
377 | 1431 |
apply(simp add: bder_fuse_list del: append.simps) |
1432 |
by (metis append.assoc map_map r_in_rstar rrewrite.intros(8) threelistsappend) |
|
365 | 1433 |
|
1434 |
lemma lock_step_der_removal: |
|
1435 |
shows " erase a1 = erase a2 \<Longrightarrow> |
|
1436 |
bder c (AALTs bs (rsa @ [a1] @ rsb @ [a2] @ rsc)) \<leadsto>* |
|
1437 |
bder c (AALTs bs (rsa @ [a1] @ rsb @ rsc))" |
|
1438 |
apply(simp) |
|
1439 |
||
375
f83271c585d2
deleted one rewrite rule
Christian Urban <christian.urban@kcl.ac.uk>
parents:
374
diff
changeset
|
1440 |
using rrewrite.intros(12) by auto |
365 | 1441 |
|
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1442 |
lemma rewrite_after_der: |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1443 |
assumes "r1 \<leadsto> r2" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1444 |
shows "(bder c r1) \<leadsto>* (bder c r2)" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1445 |
using assms |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1446 |
proof(induction r1 r2 rule: rrewrite.induct) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1447 |
case (1 bs r2) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1448 |
then show "bder c (ASEQ bs AZERO r2) \<leadsto>* bder c AZERO" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1449 |
by (simp add: continuous_rewrite) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1450 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1451 |
case (2 bs r1) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1452 |
then show "bder c (ASEQ bs r1 AZERO) \<leadsto>* bder c AZERO" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1453 |
apply(simp) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1454 |
by (meson contextrewrites1 r_in_rstar real_trans rrewrite.intros(10) rrewrite.intros(2) rrewrite0away) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1455 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1456 |
case (3 bs bs1 r) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1457 |
then show "bder c (ASEQ bs (AONE bs1) r) \<leadsto>* bder c (fuse (bs @ bs1) r)" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1458 |
apply(simp) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1459 |
by (metis bder_fuse fuse_append rrewrite.intros(11) rrewrite0away rrewrites.simps to_zero_in_alt) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1460 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1461 |
case (4 r1 r2 bs r3) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1462 |
have as: "r1 \<leadsto> r2" by fact |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1463 |
have IH: "bder c r1 \<leadsto>* bder c r2" by fact |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1464 |
from as IH show "bder c (ASEQ bs r1 r3) \<leadsto>* bder c (ASEQ bs r2 r3)" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1465 |
by (simp add: contextrewrites1 rewrite_bmkeps rewrite_non_nullable_strong star_seq) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1466 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1467 |
case (5 r3 r4 bs r1) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1468 |
have as: "r3 \<leadsto> r4" by fact |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1469 |
have IH: "bder c r3 \<leadsto>* bder c r4" by fact |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1470 |
from as IH show "bder c (ASEQ bs r1 r3) \<leadsto>* bder c (ASEQ bs r1 r4)" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1471 |
apply(simp) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1472 |
using r_in_rstar rewrites_fuse srewrites_alt1 ss1 ss2 star_seq2 by presburger |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1473 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1474 |
case (6 r r' bs rs1 rs2) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1475 |
have as: "r \<leadsto> r'" by fact |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1476 |
have IH: "bder c r \<leadsto>* bder c r'" by fact |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1477 |
from as IH show "bder c (AALTs bs (rs1 @ [r] @ rs2)) \<leadsto>* bder c (AALTs bs (rs1 @ [r'] @ rs2))" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1478 |
apply(simp) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1479 |
using contextrewrites2 by force |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1480 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1481 |
case (7 bs rsa rsb) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1482 |
then show "bder c (AALTs bs (rsa @ [AZERO] @ rsb)) \<leadsto>* bder c (AALTs bs (rsa @ rsb))" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1483 |
apply(simp) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1484 |
using rrewrite.intros(7) by auto |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1485 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1486 |
case (8 bs rsa bs1 rs1 rsb) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1487 |
then show |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1488 |
"bder c (AALTs bs (rsa @ [AALTs bs1 rs1] @ rsb)) \<leadsto>* bder c (AALTs bs (rsa @ map (fuse bs1) rs1 @ rsb))" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1489 |
using rewrite_der_altmiddle by auto |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1490 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1491 |
case (9 bs bs1 rs) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1492 |
then show "bder c (AALTs (bs @ bs1) rs) \<leadsto>* bder c (AALTs bs (map (fuse bs1) rs))" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1493 |
by (metis bder.simps(4) bder_fuse_list list.map_comp r_in_rstar rrewrite.intros(9)) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1494 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1495 |
case (10 bs) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1496 |
then show "bder c (AALTs bs []) \<leadsto>* bder c AZERO" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1497 |
by (simp add: r_in_rstar rrewrite.intros(10)) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1498 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1499 |
case (11 bs r) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1500 |
then show "bder c (AALTs bs [r]) \<leadsto>* bder c (fuse bs r)" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1501 |
by (simp add: bder_fuse r_in_rstar rrewrite.intros(11)) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1502 |
next |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1503 |
case (12 a1 a2 bs rsa rsb rsc) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1504 |
have as: "erase a1 = erase a2" by fact |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1505 |
then show "bder c (AALTs bs (rsa @ [a1] @ rsb @ [a2] @ rsc)) \<leadsto>* bder c (AALTs bs (rsa @ [a1] @ rsb @ rsc))" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1506 |
using lock_step_der_removal by force |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1507 |
qed |
365 | 1508 |
|
1509 |
||
373 | 1510 |
lemma rewrites_after_der: |
1511 |
assumes "r1 \<leadsto>* r2" |
|
1512 |
shows "bder c r1 \<leadsto>* bder c r2" |
|
1513 |
using assms |
|
1514 |
apply(induction r1 r2 rule: rrewrites.induct) |
|
1515 |
apply(simp_all add: rewrite_after_der real_trans) |
|
1516 |
done |
|
365 | 1517 |
|
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1518 |
|
373 | 1519 |
lemma central: |
1520 |
shows "bders r s \<leadsto>* bders_simp r s" |
|
1521 |
proof(induct s arbitrary: r rule: rev_induct) |
|
1522 |
case Nil |
|
1523 |
then show "bders r [] \<leadsto>* bders_simp r []" by simp |
|
1524 |
next |
|
1525 |
case (snoc x xs) |
|
1526 |
have IH: "\<And>r. bders r xs \<leadsto>* bders_simp r xs" by fact |
|
1527 |
have "bders r (xs @ [x]) = bders (bders r xs) [x]" by (simp add: bders_append) |
|
1528 |
also have "... \<leadsto>* bders (bders_simp r xs) [x]" using IH |
|
1529 |
by (simp add: rewrites_after_der) |
|
1530 |
also have "... \<leadsto>* bders_simp (bders_simp r xs) [x]" using IH |
|
1531 |
by (simp add: bsimp_rewrite) |
|
1532 |
finally show "bders r (xs @ [x]) \<leadsto>* bders_simp r (xs @ [x])" |
|
1533 |
by (simp add: bders_simp_append) |
|
1534 |
qed |
|
365 | 1535 |
|
373 | 1536 |
lemma quasi_main: |
1537 |
assumes "bnullable (bders r s)" |
|
1538 |
shows "bmkeps (bders r s) = bmkeps (bders_simp r s)" |
|
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1539 |
using assms central rewrites_bmkeps |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1540 |
proof - |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1541 |
have "bders r s \<leadsto>* bders_simp r s" by (rule central) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1542 |
then |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1543 |
show "bmkeps (bders r s) = bmkeps (bders_simp r s)" using assms |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1544 |
by (rule rewrites_bmkeps) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1545 |
qed |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1546 |
|
365 | 1547 |
|
373 | 1548 |
theorem main_main: |
1549 |
shows "blexer r s = blexer_simp r s" |
|
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1550 |
unfolding blexer_def blexer_simp_def |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1551 |
using b4 quasi_main by simp |
365 | 1552 |
|
1553 |
||
373 | 1554 |
theorem blexersimp_correctness: |
1555 |
shows "lexer r s = blexer_simp r s" |
|
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1556 |
using blexer_correctness main_main by simp |
365 | 1557 |
|
1558 |
||
378 | 1559 |
|
1560 |
export_code blexer_simp blexer lexer bders bders_simp in Scala module_name VerifiedLexers |
|
1561 |
||
1562 |
||
365 | 1563 |
unused_thms |
1564 |
||
1565 |
||
378 | 1566 |
inductive aggressive:: "arexp \<Rightarrow> arexp \<Rightarrow> bool" ("_ \<leadsto>? _" [99, 99] 99) |
1567 |
where |
|
1568 |
"ASEQ bs (AALTs bs1 rs) r \<leadsto>? AALTs (bs@bs1) (map (\<lambda>r'. ASEQ [] r' r) rs) " |
|
1569 |
||
1570 |
||
1571 |
||
365 | 1572 |
end |