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