author | Christian Urban <christian.urban@kcl.ac.uk> |
Fri, 28 Jan 2022 12:02:25 +0000 | |
changeset 398 | dac6d27c99c6 |
parent 397 | e1b74d618f1b |
child 400 | 46e5566ad4ba |
permissions | -rw-r--r-- |
365 | 1 |
|
393 | 2 |
theory SizeBound4 |
365 | 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 fuse :: "bit list \<Rightarrow> arexp \<Rightarrow> arexp" where |
|
122 |
"fuse bs AZERO = AZERO" |
|
123 |
| "fuse bs (AONE cs) = AONE (bs @ cs)" |
|
124 |
| "fuse bs (ACHAR cs c) = ACHAR (bs @ cs) c" |
|
125 |
| "fuse bs (AALTs cs rs) = AALTs (bs @ cs) rs" |
|
126 |
| "fuse bs (ASEQ cs r1 r2) = ASEQ (bs @ cs) r1 r2" |
|
127 |
| "fuse bs (ASTAR cs r) = ASTAR (bs @ cs) r" |
|
128 |
||
129 |
lemma fuse_append: |
|
130 |
shows "fuse (bs1 @ bs2) r = fuse bs1 (fuse bs2 r)" |
|
131 |
apply(induct r) |
|
132 |
apply(auto) |
|
133 |
done |
|
134 |
||
135 |
||
136 |
fun intern :: "rexp \<Rightarrow> arexp" where |
|
137 |
"intern ZERO = AZERO" |
|
138 |
| "intern ONE = AONE []" |
|
139 |
| "intern (CH c) = ACHAR [] c" |
|
140 |
| "intern (ALT r1 r2) = AALT [] (fuse [Z] (intern r1)) |
|
141 |
(fuse [S] (intern r2))" |
|
142 |
| "intern (SEQ r1 r2) = ASEQ [] (intern r1) (intern r2)" |
|
143 |
| "intern (STAR r) = ASTAR [] (intern r)" |
|
144 |
||
145 |
||
146 |
fun retrieve :: "arexp \<Rightarrow> val \<Rightarrow> bit list" where |
|
147 |
"retrieve (AONE bs) Void = bs" |
|
148 |
| "retrieve (ACHAR bs c) (Char d) = bs" |
|
149 |
| "retrieve (AALTs bs [r]) v = bs @ retrieve r v" |
|
150 |
| "retrieve (AALTs bs (r#rs)) (Left v) = bs @ retrieve r v" |
|
151 |
| "retrieve (AALTs bs (r#rs)) (Right v) = bs @ retrieve (AALTs [] rs) v" |
|
152 |
| "retrieve (ASEQ bs r1 r2) (Seq v1 v2) = bs @ retrieve r1 v1 @ retrieve r2 v2" |
|
153 |
| "retrieve (ASTAR bs r) (Stars []) = bs @ [S]" |
|
154 |
| "retrieve (ASTAR bs r) (Stars (v#vs)) = |
|
155 |
bs @ [Z] @ retrieve r v @ retrieve (ASTAR [] r) (Stars vs)" |
|
156 |
||
157 |
||
158 |
||
159 |
fun |
|
160 |
bnullable :: "arexp \<Rightarrow> bool" |
|
161 |
where |
|
162 |
"bnullable (AZERO) = False" |
|
163 |
| "bnullable (AONE bs) = True" |
|
164 |
| "bnullable (ACHAR bs c) = False" |
|
165 |
| "bnullable (AALTs bs rs) = (\<exists>r \<in> set rs. bnullable r)" |
|
166 |
| "bnullable (ASEQ bs r1 r2) = (bnullable r1 \<and> bnullable r2)" |
|
167 |
| "bnullable (ASTAR bs r) = True" |
|
168 |
||
393 | 169 |
abbreviation |
170 |
bnullables :: "arexp list \<Rightarrow> bool" |
|
171 |
where |
|
172 |
"bnullables rs \<equiv> (\<exists>r \<in> set rs. bnullable r)" |
|
173 |
||
365 | 174 |
fun |
393 | 175 |
bmkeps :: "arexp \<Rightarrow> bit list" and |
176 |
bmkepss :: "arexp list \<Rightarrow> bit list" |
|
365 | 177 |
where |
178 |
"bmkeps(AONE bs) = bs" |
|
179 |
| "bmkeps(ASEQ bs r1 r2) = bs @ (bmkeps r1) @ (bmkeps r2)" |
|
393 | 180 |
| "bmkeps(AALTs bs rs) = bs @ (bmkepss rs)" |
365 | 181 |
| "bmkeps(ASTAR bs r) = bs @ [S]" |
393 | 182 |
| "bmkepss [] = []" |
183 |
| "bmkepss (r # rs) = (if bnullable(r) then (bmkeps r) else (bmkepss rs))" |
|
184 |
||
185 |
lemma bmkepss1: |
|
186 |
assumes "\<not> bnullables rs1" |
|
187 |
shows "bmkepss (rs1 @ rs2) = bmkepss rs2" |
|
188 |
using assms |
|
189 |
by (induct rs1) (auto) |
|
190 |
||
191 |
lemma bmkepss2: |
|
192 |
assumes "bnullables rs1" |
|
193 |
shows "bmkepss (rs1 @ rs2) = bmkepss rs1" |
|
194 |
using assms |
|
195 |
by (induct rs1) (auto) |
|
365 | 196 |
|
197 |
||
198 |
fun |
|
199 |
bder :: "char \<Rightarrow> arexp \<Rightarrow> arexp" |
|
200 |
where |
|
201 |
"bder c (AZERO) = AZERO" |
|
202 |
| "bder c (AONE bs) = AZERO" |
|
203 |
| "bder c (ACHAR bs d) = (if c = d then AONE bs else AZERO)" |
|
204 |
| "bder c (AALTs bs rs) = AALTs bs (map (bder c) rs)" |
|
205 |
| "bder c (ASEQ bs r1 r2) = |
|
206 |
(if bnullable r1 |
|
207 |
then AALT bs (ASEQ [] (bder c r1) r2) (fuse (bmkeps r1) (bder c r2)) |
|
208 |
else ASEQ bs (bder c r1) r2)" |
|
209 |
| "bder c (ASTAR bs r) = ASEQ bs (fuse [Z] (bder c r)) (ASTAR [] r)" |
|
210 |
||
211 |
||
212 |
fun |
|
213 |
bders :: "arexp \<Rightarrow> string \<Rightarrow> arexp" |
|
214 |
where |
|
215 |
"bders r [] = r" |
|
216 |
| "bders r (c#s) = bders (bder c r) s" |
|
217 |
||
218 |
lemma bders_append: |
|
398 | 219 |
"bders c (s1 @ s2) = bders (bders c s1) s2" |
220 |
apply(induct s1 arbitrary: c s2) |
|
365 | 221 |
apply(simp_all) |
222 |
done |
|
223 |
||
224 |
lemma bnullable_correctness: |
|
225 |
shows "nullable (erase r) = bnullable r" |
|
226 |
apply(induct r rule: erase.induct) |
|
227 |
apply(simp_all) |
|
228 |
done |
|
229 |
||
230 |
lemma erase_fuse: |
|
231 |
shows "erase (fuse bs r) = erase r" |
|
232 |
apply(induct r rule: erase.induct) |
|
233 |
apply(simp_all) |
|
234 |
done |
|
235 |
||
236 |
lemma erase_intern [simp]: |
|
237 |
shows "erase (intern r) = r" |
|
238 |
apply(induct r) |
|
239 |
apply(simp_all add: erase_fuse) |
|
240 |
done |
|
241 |
||
242 |
lemma erase_bder [simp]: |
|
243 |
shows "erase (bder a r) = der a (erase r)" |
|
244 |
apply(induct r rule: erase.induct) |
|
245 |
apply(simp_all add: erase_fuse bnullable_correctness) |
|
246 |
done |
|
247 |
||
248 |
lemma erase_bders [simp]: |
|
249 |
shows "erase (bders r s) = ders s (erase r)" |
|
250 |
apply(induct s arbitrary: r ) |
|
251 |
apply(simp_all) |
|
252 |
done |
|
253 |
||
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
254 |
lemma bnullable_fuse: |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
255 |
shows "bnullable (fuse bs r) = bnullable r" |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
256 |
apply(induct r arbitrary: bs) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
257 |
apply(auto) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
258 |
done |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
259 |
|
365 | 260 |
lemma retrieve_encode_STARS: |
261 |
assumes "\<forall>v\<in>set vs. \<Turnstile> v : r \<and> code v = retrieve (intern r) v" |
|
262 |
shows "code (Stars vs) = retrieve (ASTAR [] (intern r)) (Stars vs)" |
|
263 |
using assms |
|
264 |
apply(induct vs) |
|
265 |
apply(simp_all) |
|
266 |
done |
|
267 |
||
268 |
lemma retrieve_fuse2: |
|
269 |
assumes "\<Turnstile> v : (erase r)" |
|
270 |
shows "retrieve (fuse bs r) v = bs @ retrieve r v" |
|
271 |
using assms |
|
272 |
apply(induct r arbitrary: v bs) |
|
397
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
273 |
apply(auto elim: Prf_elims)[4] |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
274 |
apply(case_tac x2a) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
275 |
apply(simp) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
276 |
using Prf_elims(1) apply blast |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
277 |
apply(case_tac x2a) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
278 |
apply(simp) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
279 |
apply(simp) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
280 |
apply(case_tac list) |
365 | 281 |
apply(simp) |
397
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
282 |
apply(simp) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
283 |
apply (smt (verit, best) Prf_elims(3) append_assoc retrieve.simps(4) retrieve.simps(5)) |
365 | 284 |
apply(simp) |
397
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
285 |
using retrieve_encode_STARS |
365 | 286 |
apply(auto elim!: Prf_elims)[1] |
397
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
287 |
apply(case_tac vs) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
288 |
apply(simp) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
289 |
apply(simp) |
365 | 290 |
done |
291 |
||
292 |
lemma retrieve_fuse: |
|
293 |
assumes "\<Turnstile> v : r" |
|
294 |
shows "retrieve (fuse bs (intern r)) v = bs @ retrieve (intern r) v" |
|
295 |
using assms |
|
296 |
by (simp_all add: retrieve_fuse2) |
|
297 |
||
298 |
||
299 |
lemma retrieve_code: |
|
300 |
assumes "\<Turnstile> v : r" |
|
301 |
shows "code v = retrieve (intern r) v" |
|
302 |
using assms |
|
303 |
apply(induct v r ) |
|
304 |
apply(simp_all add: retrieve_fuse retrieve_encode_STARS) |
|
305 |
done |
|
306 |
||
307 |
||
397
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
308 |
lemma retrieve_AALTs_bnullable1: |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
309 |
assumes "bnullable r" |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
310 |
shows "retrieve (AALTs bs (r # rs)) (mkeps (erase (AALTs bs (r # rs)))) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
311 |
= bs @ retrieve r (mkeps (erase r))" |
365 | 312 |
using assms |
397
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
313 |
apply(case_tac rs) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
314 |
apply(auto simp add: bnullable_correctness) |
365 | 315 |
done |
316 |
||
397
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
317 |
lemma retrieve_AALTs_bnullable2: |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
318 |
assumes "\<not>bnullable r" "bnullables rs" |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
319 |
shows "retrieve (AALTs bs (r # rs)) (mkeps (erase (AALTs bs (r # rs)))) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
320 |
= retrieve (AALTs bs rs) (mkeps (erase (AALTs bs rs)))" |
365 | 321 |
using assms |
322 |
apply(induct rs arbitrary: r bs) |
|
323 |
apply(auto) |
|
324 |
using bnullable_correctness apply blast |
|
325 |
apply(case_tac rs) |
|
397
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
326 |
apply(auto) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
327 |
using bnullable_correctness apply blast |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
328 |
apply(case_tac rs) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
329 |
apply(auto) |
365 | 330 |
done |
331 |
||
397
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
332 |
lemma bmkeps_retrieve_AALTs: |
393 | 333 |
assumes "\<forall>r \<in> set rs. bnullable r \<longrightarrow> bmkeps r = retrieve r (mkeps (erase r))" |
334 |
"bnullables rs" |
|
335 |
shows "bs @ bmkepss rs = retrieve (AALTs bs rs) (mkeps (erase (AALTs bs rs)))" |
|
336 |
using assms |
|
365 | 337 |
apply(induct rs arbitrary: bs) |
338 |
apply(auto) |
|
397
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
339 |
using retrieve_AALTs_bnullable1 apply presburger |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
340 |
apply (metis retrieve_AALTs_bnullable2) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
341 |
apply (simp add: retrieve_AALTs_bnullable1) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
342 |
by (metis retrieve_AALTs_bnullable2) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
343 |
|
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
344 |
|
365 | 345 |
lemma bmkeps_retrieve: |
393 | 346 |
assumes "bnullable r" |
365 | 347 |
shows "bmkeps r = retrieve r (mkeps (erase r))" |
348 |
using assms |
|
349 |
apply(induct r) |
|
397
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
350 |
apply(auto) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
351 |
using bmkeps_retrieve_AALTs by auto |
365 | 352 |
|
353 |
lemma bder_retrieve: |
|
354 |
assumes "\<Turnstile> v : der c (erase r)" |
|
355 |
shows "retrieve (bder c r) v = retrieve r (injval (erase r) c v)" |
|
393 | 356 |
using assms |
365 | 357 |
apply(induct r arbitrary: v rule: erase.induct) |
397
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
358 |
using Prf_elims(1) apply auto[1] |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
359 |
using Prf_elims(1) apply auto[1] |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
360 |
apply(auto)[1] |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
361 |
apply (metis Prf_elims(4) injval.simps(1) retrieve.simps(1) retrieve.simps(2)) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
362 |
using Prf_elims(1) apply blast |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
363 |
(* AALTs case *) |
365 | 364 |
apply(simp) |
365 |
apply(erule Prf_elims) |
|
397
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
366 |
apply(simp) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
367 |
apply(simp) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
368 |
apply(rename_tac "r\<^sub>1" "r\<^sub>2" rs v) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
369 |
apply(erule Prf_elims) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
370 |
apply(simp) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
371 |
apply(simp) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
372 |
apply(case_tac rs) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
373 |
apply(simp) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
374 |
apply(simp) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
375 |
using Prf_elims(3) apply fastforce |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
376 |
(* ASEQ case *) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
377 |
apply(simp) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
378 |
apply(case_tac "nullable (erase r1)") |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
379 |
apply(simp) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
380 |
apply(erule Prf_elims) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
381 |
using Prf_elims(2) bnullable_correctness apply force |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
382 |
apply (simp add: bmkeps_retrieve bnullable_correctness retrieve_fuse2) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
383 |
apply (simp add: bmkeps_retrieve bnullable_correctness retrieve_fuse2) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
384 |
using Prf_elims(2) apply force |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
385 |
(* ASTAR case *) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
386 |
apply(rename_tac bs r v) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
387 |
apply(simp) |
365 | 388 |
apply(erule Prf_elims) |
389 |
apply(clarify) |
|
397
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
390 |
apply(erule Prf_elims) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
391 |
apply(clarify) |
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
392 |
by (simp add: retrieve_fuse2) |
365 | 393 |
|
394 |
||
395 |
lemma MAIN_decode: |
|
396 |
assumes "\<Turnstile> v : ders s r" |
|
397 |
shows "Some (flex r id s v) = decode (retrieve (bders (intern r) s) v) r" |
|
398 |
using assms |
|
399 |
proof (induct s arbitrary: v rule: rev_induct) |
|
400 |
case Nil |
|
401 |
have "\<Turnstile> v : ders [] r" by fact |
|
402 |
then have "\<Turnstile> v : r" by simp |
|
403 |
then have "Some v = decode (retrieve (intern r) v) r" |
|
404 |
using decode_code retrieve_code by auto |
|
405 |
then show "Some (flex r id [] v) = decode (retrieve (bders (intern r) []) v) r" |
|
406 |
by simp |
|
407 |
next |
|
408 |
case (snoc c s v) |
|
409 |
have IH: "\<And>v. \<Turnstile> v : ders s r \<Longrightarrow> |
|
410 |
Some (flex r id s v) = decode (retrieve (bders (intern r) s) v) r" by fact |
|
411 |
have asm: "\<Turnstile> v : ders (s @ [c]) r" by fact |
|
412 |
then have asm2: "\<Turnstile> injval (ders s r) c v : ders s r" |
|
413 |
by (simp add: Prf_injval ders_append) |
|
414 |
have "Some (flex r id (s @ [c]) v) = Some (flex r id s (injval (ders s r) c v))" |
|
415 |
by (simp add: flex_append) |
|
416 |
also have "... = decode (retrieve (bders (intern r) s) (injval (ders s r) c v)) r" |
|
417 |
using asm2 IH by simp |
|
418 |
also have "... = decode (retrieve (bder c (bders (intern r) s)) v) r" |
|
419 |
using asm by (simp_all add: bder_retrieve ders_append) |
|
420 |
finally show "Some (flex r id (s @ [c]) v) = |
|
421 |
decode (retrieve (bders (intern r) (s @ [c])) v) r" by (simp add: bders_append) |
|
422 |
qed |
|
423 |
||
424 |
definition blexer where |
|
425 |
"blexer r s \<equiv> if bnullable (bders (intern r) s) then |
|
426 |
decode (bmkeps (bders (intern r) s)) r else None" |
|
427 |
||
428 |
lemma blexer_correctness: |
|
429 |
shows "blexer r s = lexer r s" |
|
430 |
proof - |
|
431 |
{ define bds where "bds \<equiv> bders (intern r) s" |
|
432 |
define ds where "ds \<equiv> ders s r" |
|
433 |
assume asm: "nullable ds" |
|
434 |
have era: "erase bds = ds" |
|
435 |
unfolding ds_def bds_def by simp |
|
436 |
have mke: "\<Turnstile> mkeps ds : ds" |
|
437 |
using asm by (simp add: mkeps_nullable) |
|
438 |
have "decode (bmkeps bds) r = decode (retrieve bds (mkeps ds)) r" |
|
439 |
using bmkeps_retrieve |
|
393 | 440 |
using asm era |
441 |
using bnullable_correctness by force |
|
365 | 442 |
also have "... = Some (flex r id s (mkeps ds))" |
443 |
using mke by (simp_all add: MAIN_decode ds_def bds_def) |
|
444 |
finally have "decode (bmkeps bds) r = Some (flex r id s (mkeps ds))" |
|
445 |
unfolding bds_def ds_def . |
|
446 |
} |
|
447 |
then show "blexer r s = lexer r s" |
|
448 |
unfolding blexer_def lexer_flex |
|
393 | 449 |
by (auto simp add: bnullable_correctness[symmetric]) |
365 | 450 |
qed |
451 |
||
452 |
||
453 |
fun distinctBy :: "'a list \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'b set \<Rightarrow> 'a list" |
|
454 |
where |
|
455 |
"distinctBy [] f acc = []" |
|
456 |
| "distinctBy (x#xs) f acc = |
|
457 |
(if (f x) \<in> acc then distinctBy xs f acc |
|
458 |
else x # (distinctBy xs f ({f x} \<union> acc)))" |
|
459 |
||
393 | 460 |
|
365 | 461 |
|
462 |
fun flts :: "arexp list \<Rightarrow> arexp list" |
|
463 |
where |
|
464 |
"flts [] = []" |
|
465 |
| "flts (AZERO # rs) = flts rs" |
|
466 |
| "flts ((AALTs bs rs1) # rs) = (map (fuse bs) rs1) @ flts rs" |
|
467 |
| "flts (r1 # rs) = r1 # flts rs" |
|
468 |
||
469 |
||
470 |
||
471 |
fun bsimp_ASEQ :: "bit list \<Rightarrow> arexp \<Rightarrow> arexp \<Rightarrow> arexp" |
|
472 |
where |
|
473 |
"bsimp_ASEQ _ AZERO _ = AZERO" |
|
474 |
| "bsimp_ASEQ _ _ AZERO = AZERO" |
|
475 |
| "bsimp_ASEQ bs1 (AONE bs2) r2 = fuse (bs1 @ bs2) r2" |
|
476 |
| "bsimp_ASEQ bs1 r1 r2 = ASEQ bs1 r1 r2" |
|
477 |
||
393 | 478 |
lemma bsimp_ASEQ0[simp]: |
479 |
shows "bsimp_ASEQ bs r1 AZERO = AZERO" |
|
480 |
by (case_tac r1)(simp_all) |
|
481 |
||
482 |
lemma bsimp_ASEQ1: |
|
483 |
assumes "r1 \<noteq> AZERO" "r2 \<noteq> AZERO" "\<nexists>bs. r1 = AONE bs" |
|
484 |
shows "bsimp_ASEQ bs r1 r2 = ASEQ bs r1 r2" |
|
485 |
using assms |
|
486 |
apply(induct bs r1 r2 rule: bsimp_ASEQ.induct) |
|
487 |
apply(auto) |
|
488 |
done |
|
489 |
||
490 |
lemma bsimp_ASEQ2[simp]: |
|
491 |
shows "bsimp_ASEQ bs1 (AONE bs2) r2 = fuse (bs1 @ bs2) r2" |
|
492 |
by (case_tac r2) (simp_all) |
|
493 |
||
365 | 494 |
|
495 |
fun bsimp_AALTs :: "bit list \<Rightarrow> arexp list \<Rightarrow> arexp" |
|
496 |
where |
|
497 |
"bsimp_AALTs _ [] = AZERO" |
|
498 |
| "bsimp_AALTs bs1 [r] = fuse bs1 r" |
|
499 |
| "bsimp_AALTs bs1 rs = AALTs bs1 rs" |
|
500 |
||
501 |
||
502 |
fun bsimp :: "arexp \<Rightarrow> arexp" |
|
503 |
where |
|
504 |
"bsimp (ASEQ bs1 r1 r2) = bsimp_ASEQ bs1 (bsimp r1) (bsimp r2)" |
|
374 | 505 |
| "bsimp (AALTs bs1 rs) = bsimp_AALTs bs1 (distinctBy (flts (map bsimp rs)) erase {}) " |
365 | 506 |
| "bsimp r = r" |
507 |
||
508 |
||
509 |
fun |
|
510 |
bders_simp :: "arexp \<Rightarrow> string \<Rightarrow> arexp" |
|
511 |
where |
|
512 |
"bders_simp r [] = r" |
|
513 |
| "bders_simp r (c # s) = bders_simp (bsimp (bder c r)) s" |
|
514 |
||
515 |
definition blexer_simp where |
|
516 |
"blexer_simp r s \<equiv> if bnullable (bders_simp (intern r) s) then |
|
374 | 517 |
decode (bmkeps (bders_simp (intern r) s)) r else None" |
365 | 518 |
|
393 | 519 |
|
365 | 520 |
|
521 |
lemma bders_simp_append: |
|
522 |
shows "bders_simp r (s1 @ s2) = bders_simp (bders_simp r s1) s2" |
|
523 |
apply(induct s1 arbitrary: r s2) |
|
374 | 524 |
apply(simp_all) |
365 | 525 |
done |
526 |
||
527 |
||
393 | 528 |
lemma bmkeps_fuse: |
365 | 529 |
assumes "bnullable r" |
530 |
shows "bmkeps (fuse bs r) = bs @ bmkeps r" |
|
398 | 531 |
using assms |
532 |
by (metis bmkeps_retrieve bnullable_correctness erase_fuse mkeps_nullable retrieve_fuse2) |
|
393 | 533 |
|
534 |
lemma bmkepss_fuse: |
|
535 |
assumes "bnullables rs" |
|
536 |
shows "bmkepss (map (fuse bs) rs) = bs @ bmkepss rs" |
|
537 |
using assms |
|
538 |
apply(induct rs arbitrary: bs) |
|
539 |
apply(auto simp add: bmkeps_fuse bnullable_fuse) |
|
540 |
done |
|
365 | 541 |
|
542 |
lemma bder_fuse: |
|
543 |
shows "bder c (fuse bs a) = fuse bs (bder c a)" |
|
544 |
apply(induct a arbitrary: bs c) |
|
398 | 545 |
apply(simp_all) |
365 | 546 |
done |
547 |
||
385 | 548 |
|
549 |
||
550 |
||
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
551 |
inductive |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
552 |
rrewrite:: "arexp \<Rightarrow> arexp \<Rightarrow> bool" ("_ \<leadsto> _" [99, 99] 99) |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
553 |
and |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
554 |
srewrite:: "arexp list \<Rightarrow> arexp list \<Rightarrow> bool" (" _ s\<leadsto> _" [100, 100] 100) |
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
555 |
where |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
556 |
bs1: "ASEQ bs AZERO r2 \<leadsto> AZERO" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
557 |
| bs2: "ASEQ bs r1 AZERO \<leadsto> AZERO" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
558 |
| bs3: "ASEQ bs1 (AONE bs2) r \<leadsto> fuse (bs1@bs2) r" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
559 |
| bs4: "r1 \<leadsto> r2 \<Longrightarrow> ASEQ bs r1 r3 \<leadsto> ASEQ bs r2 r3" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
560 |
| bs5: "r3 \<leadsto> r4 \<Longrightarrow> ASEQ bs r1 r3 \<leadsto> ASEQ bs r1 r4" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
561 |
| bs6: "AALTs bs [] \<leadsto> AZERO" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
562 |
| bs7: "AALTs bs [r] \<leadsto> fuse bs r" |
398 | 563 |
| bs8: "rs1 s\<leadsto> rs2 \<Longrightarrow> AALTs bs rs1 \<leadsto> AALTs bs rs2" |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
564 |
| ss1: "[] s\<leadsto> []" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
565 |
| ss2: "rs1 s\<leadsto> rs2 \<Longrightarrow> (r # rs1) s\<leadsto> (r # rs2)" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
566 |
| ss3: "r1 \<leadsto> r2 \<Longrightarrow> (r1 # rs) s\<leadsto> (r2 # rs)" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
567 |
| ss4: "(AZERO # rs) s\<leadsto> rs" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
568 |
| ss5: "(AALTs bs1 rs1 # rsb) s\<leadsto> ((map (fuse bs1) rs1) @ rsb)" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
569 |
| ss6: "erase a1 = erase a2 \<Longrightarrow> (rsa@[a1]@rsb@[a2]@rsc) s\<leadsto> (rsa@[a1]@rsb@rsc)" |
365 | 570 |
|
393 | 571 |
|
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
572 |
inductive |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
573 |
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
|
574 |
where |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
575 |
rs1[intro, simp]:"r \<leadsto>* r" |
365 | 576 |
| rs2[intro]: "\<lbrakk>r1 \<leadsto>* r2; r2 \<leadsto> r3\<rbrakk> \<Longrightarrow> r1 \<leadsto>* r3" |
577 |
||
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
578 |
inductive |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
579 |
srewrites:: "arexp list \<Rightarrow> arexp list \<Rightarrow> bool" ("_ s\<leadsto>* _" [100, 100] 100) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
580 |
where |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
581 |
sss1[intro, simp]:"rs s\<leadsto>* rs" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
582 |
| sss2[intro]: "\<lbrakk>rs1 s\<leadsto> rs2; rs2 s\<leadsto>* rs3\<rbrakk> \<Longrightarrow> rs1 s\<leadsto>* rs3" |
365 | 583 |
|
584 |
||
393 | 585 |
lemma r_in_rstar: |
586 |
shows "r1 \<leadsto> r2 \<Longrightarrow> r1 \<leadsto>* r2" |
|
587 |
using rrewrites.intros(1) rrewrites.intros(2) by blast |
|
588 |
||
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
589 |
lemma rrewrites_trans[trans]: |
365 | 590 |
assumes a1: "r1 \<leadsto>* r2" and a2: "r2 \<leadsto>* r3" |
591 |
shows "r1 \<leadsto>* r3" |
|
592 |
using a2 a1 |
|
593 |
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
|
594 |
apply(auto) |
365 | 595 |
done |
596 |
||
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
597 |
lemma srewrites_trans[trans]: |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
598 |
assumes a1: "r1 s\<leadsto>* r2" and a2: "r2 s\<leadsto>* r3" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
599 |
shows "r1 s\<leadsto>* r3" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
600 |
using a1 a2 |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
601 |
apply(induct r1 r2 arbitrary: r3 rule: srewrites.induct) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
602 |
apply(auto) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
603 |
done |
365 | 604 |
|
605 |
||
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
606 |
|
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
607 |
lemma contextrewrites0: |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
608 |
"rs1 s\<leadsto>* rs2 \<Longrightarrow> AALTs bs rs1 \<leadsto>* AALTs bs rs2" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
609 |
apply(induct rs1 rs2 rule: srewrites.inducts) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
610 |
apply simp |
398 | 611 |
using bs8 r_in_rstar rrewrites_trans by blast |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
612 |
|
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
613 |
lemma contextrewrites1: |
393 | 614 |
"r \<leadsto>* r' \<Longrightarrow> AALTs bs (r # rs) \<leadsto>* AALTs bs (r' # rs)" |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
615 |
apply(induct r r' rule: rrewrites.induct) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
616 |
apply simp |
398 | 617 |
using bs8 ss3 by blast |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
618 |
|
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
619 |
lemma srewrite1: |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
620 |
shows "rs1 s\<leadsto> rs2 \<Longrightarrow> (rs @ rs1) s\<leadsto> (rs @ rs2)" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
621 |
apply(induct rs) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
622 |
apply(auto) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
623 |
using ss2 by auto |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
624 |
|
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
625 |
lemma srewrites1: |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
626 |
shows "rs1 s\<leadsto>* rs2 \<Longrightarrow> (rs @ rs1) s\<leadsto>* (rs @ rs2)" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
627 |
apply(induct rs1 rs2 rule: srewrites.induct) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
628 |
apply(auto) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
629 |
using srewrite1 by blast |
365 | 630 |
|
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
631 |
lemma srewrite2: |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
632 |
shows "r1 \<leadsto> r2 \<Longrightarrow> True" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
633 |
and "rs1 s\<leadsto> rs2 \<Longrightarrow> (rs1 @ rs) s\<leadsto>* (rs2 @ rs)" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
634 |
apply(induct rule: rrewrite_srewrite.inducts) |
398 | 635 |
apply(auto) |
636 |
apply (metis append_Cons append_Nil srewrites1) |
|
637 |
apply(meson srewrites.simps ss3) |
|
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
638 |
apply (meson srewrites.simps ss4) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
639 |
apply (meson srewrites.simps ss5) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
640 |
by (metis append_Cons append_Nil srewrites.simps ss6) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
641 |
|
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
642 |
|
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
643 |
lemma srewrites3: |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
644 |
shows "rs1 s\<leadsto>* rs2 \<Longrightarrow> (rs1 @ rs) s\<leadsto>* (rs2 @ rs)" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
645 |
apply(induct rs1 rs2 arbitrary: rs rule: srewrites.induct) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
646 |
apply(auto) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
647 |
by (meson srewrite2(2) srewrites_trans) |
365 | 648 |
|
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
649 |
(* |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
650 |
lemma srewrites4: |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
651 |
assumes "rs3 s\<leadsto>* rs4" "rs1 s\<leadsto>* rs2" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
652 |
shows "(rs1 @ rs3) s\<leadsto>* (rs2 @ rs4)" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
653 |
using assms |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
654 |
apply(induct rs3 rs4 arbitrary: rs1 rs2 rule: srewrites.induct) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
655 |
apply (simp add: srewrites3) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
656 |
using srewrite1 by blast |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
657 |
*) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
658 |
|
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
659 |
lemma srewrites6: |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
660 |
assumes "r1 \<leadsto>* r2" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
661 |
shows "[r1] s\<leadsto>* [r2]" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
662 |
using assms |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
663 |
apply(induct r1 r2 rule: rrewrites.induct) |
398 | 664 |
apply(auto) |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
665 |
by (meson srewrites.simps srewrites_trans ss3) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
666 |
|
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
667 |
lemma srewrites7: |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
668 |
assumes "rs3 s\<leadsto>* rs4" "r1 \<leadsto>* r2" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
669 |
shows "(r1 # rs3) s\<leadsto>* (r2 # rs4)" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
670 |
using assms |
398 | 671 |
by (smt (verit, del_insts) append.simps srewrites1 srewrites3 srewrites6 srewrites_trans) |
672 |
||
393 | 673 |
lemma ss6_stronger_aux: |
674 |
shows "(rs1 @ rs2) s\<leadsto>* (rs1 @ distinctBy rs2 erase (set (map erase rs1)))" |
|
675 |
apply(induct rs2 arbitrary: rs1) |
|
676 |
apply(auto) |
|
677 |
apply (smt (verit, best) append.assoc append.right_neutral append_Cons append_Nil split_list srewrite2(2) srewrites_trans ss6) |
|
678 |
apply(drule_tac x="rs1 @ [a]" in meta_spec) |
|
679 |
apply(simp) |
|
680 |
done |
|
681 |
||
682 |
lemma ss6_stronger: |
|
683 |
shows "rs1 s\<leadsto>* distinctBy rs1 erase {}" |
|
684 |
using ss6_stronger_aux[of "[]" _] by auto |
|
685 |
||
686 |
lemma rewrite_preserves_fuse: |
|
687 |
shows "r2 \<leadsto> r3 \<Longrightarrow> fuse bs r2 \<leadsto> fuse bs r3" |
|
398 | 688 |
and "rs2 s\<leadsto> rs3 \<Longrightarrow> map (fuse bs) rs2 s\<leadsto> map (fuse bs) rs3" |
393 | 689 |
proof(induct rule: rrewrite_srewrite.inducts) |
690 |
case (bs3 bs1 bs2 r) |
|
398 | 691 |
then show "fuse bs (ASEQ bs1 (AONE bs2) r) \<leadsto> fuse bs (fuse (bs1 @ bs2) r)" |
393 | 692 |
by (metis fuse.simps(5) fuse_append rrewrite_srewrite.bs3) |
693 |
next |
|
398 | 694 |
case (bs7 bs1 r) |
695 |
then show "fuse bs (AALTs bs1 [r]) \<leadsto> fuse bs (fuse bs1 r)" |
|
393 | 696 |
by (metis fuse.simps(4) fuse_append rrewrite_srewrite.bs7) |
697 |
next |
|
698 |
case (ss2 rs1 rs2 r) |
|
398 | 699 |
then show "map (fuse bs) (r # rs1) s\<leadsto> map (fuse bs) (r # rs2)" |
700 |
by (simp add: rrewrite_srewrite.ss2) |
|
393 | 701 |
next |
702 |
case (ss3 r1 r2 rs) |
|
398 | 703 |
then show "map (fuse bs) (r1 # rs) s\<leadsto> map (fuse bs) (r2 # rs)" |
704 |
by (simp add: rrewrite_srewrite.ss3) |
|
393 | 705 |
next |
706 |
case (ss5 bs1 rs1 rsb) |
|
398 | 707 |
have "map (fuse bs) (AALTs bs1 rs1 # rsb) = AALTs (bs @ bs1) rs1 # (map (fuse bs) rsb)" by simp |
708 |
also have "... s\<leadsto> ((map (fuse (bs @ bs1)) rs1) @ (map (fuse bs) rsb))" |
|
709 |
by (simp add: rrewrite_srewrite.ss5) |
|
710 |
finally show "map (fuse bs) (AALTs bs1 rs1 # rsb) s\<leadsto> map (fuse bs) (map (fuse bs1) rs1 @ rsb)" |
|
711 |
by (simp add: comp_def fuse_append) |
|
393 | 712 |
next |
713 |
case (ss6 a1 a2 rsa rsb rsc) |
|
398 | 714 |
then show "map (fuse bs) (rsa @ [a1] @ rsb @ [a2] @ rsc) s\<leadsto> map (fuse bs) (rsa @ [a1] @ rsb @ rsc)" |
393 | 715 |
apply(simp) |
716 |
apply(rule rrewrite_srewrite.ss6[simplified]) |
|
717 |
apply(simp add: erase_fuse) |
|
718 |
done |
|
397
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
719 |
qed (auto intro: rrewrite_srewrite.intros) |
393 | 720 |
|
721 |
lemma rewrites_fuse: |
|
722 |
assumes "r1 \<leadsto>* r2" |
|
723 |
shows "fuse bs r1 \<leadsto>* fuse bs r2" |
|
724 |
using assms |
|
725 |
apply(induction r1 r2 arbitrary: bs rule: rrewrites.induct) |
|
398 | 726 |
apply(auto intro: rewrite_preserves_fuse) |
393 | 727 |
done |
365 | 728 |
|
729 |
||
374 | 730 |
lemma star_seq: |
731 |
assumes "r1 \<leadsto>* r2" |
|
732 |
shows "ASEQ bs r1 r3 \<leadsto>* ASEQ bs r2 r3" |
|
733 |
using assms |
|
734 |
apply(induct r1 r2 arbitrary: r3 rule: rrewrites.induct) |
|
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
735 |
apply(auto intro: rrewrite_srewrite.intros) |
374 | 736 |
done |
365 | 737 |
|
374 | 738 |
lemma star_seq2: |
739 |
assumes "r3 \<leadsto>* r4" |
|
740 |
shows "ASEQ bs r1 r3 \<leadsto>* ASEQ bs r1 r4" |
|
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
741 |
using assms |
374 | 742 |
apply(induct r3 r4 arbitrary: r1 rule: rrewrites.induct) |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
743 |
apply(auto intro: rrewrite_srewrite.intros) |
374 | 744 |
done |
365 | 745 |
|
374 | 746 |
lemma continuous_rewrite: |
747 |
assumes "r1 \<leadsto>* AZERO" |
|
748 |
shows "ASEQ bs1 r1 r2 \<leadsto>* AZERO" |
|
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
749 |
using assms bs1 star_seq by blast |
365 | 750 |
|
393 | 751 |
(* |
752 |
lemma continuous_rewrite2: |
|
753 |
assumes "r1 \<leadsto>* AONE bs" |
|
754 |
shows "ASEQ bs1 r1 r2 \<leadsto>* (fuse (bs1 @ bs) r2)" |
|
755 |
using assms by (meson bs3 rrewrites.simps star_seq) |
|
756 |
*) |
|
365 | 757 |
|
374 | 758 |
lemma bsimp_aalts_simpcases: |
759 |
shows "AONE bs \<leadsto>* bsimp (AONE bs)" |
|
760 |
and "AZERO \<leadsto>* bsimp AZERO" |
|
761 |
and "ACHAR bs c \<leadsto>* bsimp (ACHAR bs c)" |
|
762 |
by (simp_all) |
|
365 | 763 |
|
393 | 764 |
lemma bsimp_AALTs_rewrites: |
765 |
shows "AALTs bs1 rs \<leadsto>* bsimp_AALTs bs1 rs" |
|
766 |
by (smt (verit) bs6 bs7 bsimp_AALTs.elims rrewrites.simps) |
|
385 | 767 |
|
768 |
lemma trivialbsimp_srewrites: |
|
398 | 769 |
assumes "\<And>x. x \<in> set rs \<Longrightarrow> x \<leadsto>* f x" |
770 |
shows "rs s\<leadsto>* (map f rs)" |
|
771 |
using assms |
|
365 | 772 |
apply(induction rs) |
398 | 773 |
apply(simp_all add: srewrites7) |
774 |
done |
|
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
775 |
|
393 | 776 |
lemma fltsfrewrites: "rs s\<leadsto>* flts rs" |
777 |
apply(induction rs rule: flts.induct) |
|
778 |
apply(auto intro: rrewrite_srewrite.intros) |
|
779 |
apply (meson srewrites.simps srewrites1 ss5) |
|
780 |
using rs1 srewrites7 apply presburger |
|
781 |
using srewrites7 apply force |
|
782 |
apply (simp add: srewrites7) |
|
783 |
by (simp add: srewrites7) |
|
365 | 784 |
|
393 | 785 |
lemma bnullable0: |
786 |
shows "r1 \<leadsto> r2 \<Longrightarrow> bnullable r1 = bnullable r2" |
|
787 |
and "rs1 s\<leadsto> rs2 \<Longrightarrow> bnullables rs1 = bnullables rs2" |
|
788 |
apply(induct rule: rrewrite_srewrite.inducts) |
|
789 |
apply(auto simp add: bnullable_fuse) |
|
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
790 |
apply (meson UnCI bnullable_fuse imageI) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
791 |
by (metis bnullable_correctness) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
792 |
|
373 | 793 |
|
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
794 |
lemma rewrites_bnullable_eq: |
393 | 795 |
assumes "r1 \<leadsto>* r2" |
796 |
shows "bnullable r1 = bnullable r2" |
|
797 |
using assms |
|
365 | 798 |
apply(induction r1 r2 rule: rrewrites.induct) |
799 |
apply simp |
|
393 | 800 |
using bnullable0(1) by auto |
365 | 801 |
|
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
802 |
lemma rewrite_bmkeps_aux: |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
803 |
shows "r1 \<leadsto> r2 \<Longrightarrow> bnullable r1 \<Longrightarrow> bmkeps r1 = bmkeps r2" |
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
804 |
and "rs1 s\<leadsto> rs2 \<Longrightarrow> bnullables rs1 \<Longrightarrow> bmkepss rs1 = bmkepss rs2" |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
805 |
proof (induct rule: rrewrite_srewrite.inducts) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
806 |
case (bs3 bs1 bs2 r) |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
807 |
have IH2: "bnullable (ASEQ bs1 (AONE bs2) r)" by fact |
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
808 |
then show "bmkeps (ASEQ bs1 (AONE bs2) r) = bmkeps (fuse (bs1 @ bs2) r)" |
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
809 |
by (simp add: bmkeps_fuse) |
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
810 |
next |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
811 |
case (bs7 bs r) |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
812 |
have IH2: "bnullable (AALTs bs [r])" by fact |
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
813 |
then show "bmkeps (AALTs bs [r]) = bmkeps (fuse bs r)" |
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
814 |
by (simp add: bmkeps_fuse) |
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
815 |
next |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
816 |
case (ss3 r1 r2 rs) |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
817 |
have IH1: "bnullable r1 \<Longrightarrow> bmkeps r1 = bmkeps r2" by fact |
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
818 |
have as: "r1 \<leadsto> r2" by fact |
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
819 |
from IH1 as show "bmkepss (r1 # rs) = bmkepss (r2 # rs)" |
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
820 |
by (simp add: bnullable0) |
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
821 |
next |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
822 |
case (ss5 bs1 rs1 rsb) |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
823 |
have "bnullables (AALTs bs1 rs1 # rsb)" by fact |
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
824 |
then show "bmkepss (AALTs bs1 rs1 # rsb) = bmkepss (map (fuse bs1) rs1 @ rsb)" |
393 | 825 |
by (simp add: bmkepss1 bmkepss2 bmkepss_fuse bnullable_fuse) |
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
826 |
next |
393 | 827 |
case (ss6 a1 a2 rsa rsb rsc) |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
828 |
have as1: "erase a1 = erase a2" by fact |
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
829 |
have as3: "bnullables (rsa @ [a1] @ rsb @ [a2] @ rsc)" by fact |
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
830 |
show "bmkepss (rsa @ [a1] @ rsb @ [a2] @ rsc) = bmkepss (rsa @ [a1] @ rsb @ rsc)" using as1 as3 |
393 | 831 |
by (smt (verit, best) append_Cons bmkeps.simps(3) bmkepss.simps(2) bmkepss1 bmkepss2 bnullable_correctness) |
832 |
qed (auto) |
|
365 | 833 |
|
373 | 834 |
lemma rewrites_bmkeps: |
835 |
assumes "r1 \<leadsto>* r2" "bnullable r1" |
|
836 |
shows "bmkeps r1 = bmkeps r2" |
|
837 |
using assms |
|
838 |
proof(induction r1 r2 rule: rrewrites.induct) |
|
839 |
case (rs1 r) |
|
840 |
then show "bmkeps r = bmkeps r" by simp |
|
841 |
next |
|
842 |
case (rs2 r1 r2 r3) |
|
843 |
then have IH: "bmkeps r1 = bmkeps r2" by simp |
|
844 |
have a1: "bnullable r1" by fact |
|
845 |
have a2: "r1 \<leadsto>* r2" by fact |
|
846 |
have a3: "r2 \<leadsto> r3" by fact |
|
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
847 |
have a4: "bnullable r2" using a1 a2 by (simp add: rewrites_bnullable_eq) |
393 | 848 |
then have "bmkeps r2 = bmkeps r3" |
849 |
using a3 bnullable0(1) rewrite_bmkeps_aux(1) by blast |
|
373 | 850 |
then show "bmkeps r1 = bmkeps r3" using IH by simp |
851 |
qed |
|
365 | 852 |
|
393 | 853 |
|
854 |
lemma rewrites_to_bsimp: |
|
855 |
shows "r \<leadsto>* bsimp r" |
|
856 |
proof (induction r rule: bsimp.induct) |
|
857 |
case (1 bs1 r1 r2) |
|
858 |
have IH1: "r1 \<leadsto>* bsimp r1" by fact |
|
859 |
have IH2: "r2 \<leadsto>* bsimp r2" by fact |
|
860 |
{ assume as: "bsimp r1 = AZERO \<or> bsimp r2 = AZERO" |
|
861 |
with IH1 IH2 have "r1 \<leadsto>* AZERO \<or> r2 \<leadsto>* AZERO" by auto |
|
862 |
then have "ASEQ bs1 r1 r2 \<leadsto>* AZERO" |
|
863 |
by (metis bs2 continuous_rewrite rrewrites.simps star_seq2) |
|
864 |
then have "ASEQ bs1 r1 r2 \<leadsto>* bsimp (ASEQ bs1 r1 r2)" using as by auto |
|
865 |
} |
|
866 |
moreover |
|
867 |
{ assume "\<exists>bs. bsimp r1 = AONE bs" |
|
868 |
then obtain bs where as: "bsimp r1 = AONE bs" by blast |
|
869 |
with IH1 have "r1 \<leadsto>* AONE bs" by simp |
|
870 |
then have "ASEQ bs1 r1 r2 \<leadsto>* fuse (bs1 @ bs) r2" using bs3 star_seq by blast |
|
871 |
with IH2 have "ASEQ bs1 r1 r2 \<leadsto>* fuse (bs1 @ bs) (bsimp r2)" |
|
872 |
using rewrites_fuse by (meson rrewrites_trans) |
|
873 |
then have "ASEQ bs1 r1 r2 \<leadsto>* bsimp (ASEQ bs1 (AONE bs) r2)" by simp |
|
874 |
then have "ASEQ bs1 r1 r2 \<leadsto>* bsimp (ASEQ bs1 r1 r2)" by (simp add: as) |
|
875 |
} |
|
876 |
moreover |
|
877 |
{ assume as1: "bsimp r1 \<noteq> AZERO" "bsimp r2 \<noteq> AZERO" and as2: "(\<nexists>bs. bsimp r1 = AONE bs)" |
|
878 |
then have "bsimp_ASEQ bs1 (bsimp r1) (bsimp r2) = ASEQ bs1 (bsimp r1) (bsimp r2)" |
|
879 |
by (simp add: bsimp_ASEQ1) |
|
880 |
then have "ASEQ bs1 r1 r2 \<leadsto>* bsimp_ASEQ bs1 (bsimp r1) (bsimp r2)" using as1 as2 IH1 IH2 |
|
881 |
by (metis rrewrites_trans star_seq star_seq2) |
|
882 |
then have "ASEQ bs1 r1 r2 \<leadsto>* bsimp (ASEQ bs1 r1 r2)" by simp |
|
883 |
} |
|
884 |
ultimately show "ASEQ bs1 r1 r2 \<leadsto>* bsimp (ASEQ bs1 r1 r2)" by blast |
|
885 |
next |
|
886 |
case (2 bs1 rs) |
|
887 |
have IH: "\<And>x. x \<in> set rs \<Longrightarrow> x \<leadsto>* bsimp x" by fact |
|
888 |
then have "rs s\<leadsto>* (map bsimp rs)" by (simp add: trivialbsimp_srewrites) |
|
889 |
also have "... s\<leadsto>* flts (map bsimp rs)" by (simp add: fltsfrewrites) |
|
890 |
also have "... s\<leadsto>* distinctBy (flts (map bsimp rs)) erase {}" by (simp add: ss6_stronger) |
|
891 |
finally have "AALTs bs1 rs \<leadsto>* AALTs bs1 (distinctBy (flts (map bsimp rs)) erase {})" |
|
892 |
using contextrewrites0 by blast |
|
893 |
also have "... \<leadsto>* bsimp_AALTs bs1 (distinctBy (flts (map bsimp rs)) erase {})" |
|
894 |
by (simp add: bsimp_AALTs_rewrites) |
|
895 |
finally show "AALTs bs1 rs \<leadsto>* bsimp (AALTs bs1 rs)" by simp |
|
896 |
qed (simp_all) |
|
897 |
||
898 |
||
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
899 |
lemma to_zero_in_alt: |
393 | 900 |
shows "AALT bs (ASEQ [] AZERO r) r2 \<leadsto> AALT bs AZERO r2" |
398 | 901 |
by (simp add: bs1 bs8 ss3) |
365 | 902 |
|
903 |
||
904 |
||
374 | 905 |
lemma bder_fuse_list: |
906 |
shows "map (bder c \<circ> fuse bs1) rs1 = map (fuse bs1 \<circ> bder c) rs1" |
|
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
907 |
apply(induction rs1) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
908 |
apply(simp_all add: bder_fuse) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
909 |
done |
365 | 910 |
|
393 | 911 |
lemma rewrite_preserves_bder: |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
912 |
shows "r1 \<leadsto> r2 \<Longrightarrow> bder c r1 \<leadsto>* bder c r2" |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
913 |
and "rs1 s\<leadsto> rs2 \<Longrightarrow> map (bder c) rs1 s\<leadsto>* map (bder c) rs2" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
914 |
proof(induction rule: rrewrite_srewrite.inducts) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
915 |
case (bs1 bs r2) |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
916 |
show "bder c (ASEQ bs AZERO r2) \<leadsto>* bder c AZERO" |
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
917 |
by (simp add: continuous_rewrite) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
918 |
next |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
919 |
case (bs2 bs r1) |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
920 |
show "bder c (ASEQ bs r1 AZERO) \<leadsto>* bder c AZERO" |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
921 |
apply(auto) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
922 |
apply (meson bs6 contextrewrites0 rrewrite_srewrite.bs2 rs2 ss3 ss4 sss1 sss2) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
923 |
by (simp add: r_in_rstar rrewrite_srewrite.bs2) |
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
924 |
next |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
925 |
case (bs3 bs1 bs2 r) |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
926 |
show "bder c (ASEQ bs1 (AONE bs2) r) \<leadsto>* bder c (fuse (bs1 @ bs2) r)" |
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
927 |
apply(simp) |
398 | 928 |
by (metis (no_types, lifting) bder_fuse bs8 bs7 fuse_append rrewrites.simps ss4 to_zero_in_alt) |
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
929 |
next |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
930 |
case (bs4 r1 r2 bs r3) |
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
931 |
have as: "r1 \<leadsto> r2" by fact |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
932 |
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
|
933 |
from as IH show "bder c (ASEQ bs r1 r3) \<leadsto>* bder c (ASEQ bs r2 r3)" |
393 | 934 |
by (metis bder.simps(5) bnullable0(1) contextrewrites1 rewrite_bmkeps_aux(1) star_seq) |
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
935 |
next |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
936 |
case (bs5 r3 r4 bs r1) |
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
937 |
have as: "r3 \<leadsto> r4" by fact |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
938 |
have IH: "bder c r3 \<leadsto>* bder c r4" by fact |
385 | 939 |
from as IH show "bder c (ASEQ bs r1 r3) \<leadsto>* bder c (ASEQ bs r1 r4)" |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
940 |
apply(simp) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
941 |
apply(auto) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
942 |
using contextrewrites0 r_in_rstar rewrites_fuse srewrites6 srewrites7 star_seq2 apply presburger |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
943 |
using star_seq2 by blast |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
944 |
next |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
945 |
case (bs6 bs) |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
946 |
show "bder c (AALTs bs []) \<leadsto>* bder c AZERO" |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
947 |
using rrewrite_srewrite.bs6 by force |
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
948 |
next |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
949 |
case (bs7 bs r) |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
950 |
show "bder c (AALTs bs [r]) \<leadsto>* bder c (fuse bs r)" |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
951 |
by (simp add: bder_fuse r_in_rstar rrewrite_srewrite.bs7) |
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
952 |
next |
398 | 953 |
case (bs8 rs1 rs2 bs) |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
954 |
have IH1: "map (bder c) rs1 s\<leadsto>* map (bder c) rs2" by fact |
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
955 |
then show "bder c (AALTs bs rs1) \<leadsto>* bder c (AALTs bs rs2)" |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
956 |
using contextrewrites0 by force |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
957 |
next |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
958 |
case ss1 |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
959 |
show "map (bder c) [] s\<leadsto>* map (bder c) []" by simp |
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
960 |
next |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
961 |
case (ss2 rs1 rs2 r) |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
962 |
have IH1: "map (bder c) rs1 s\<leadsto>* map (bder c) rs2" by fact |
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
963 |
then show "map (bder c) (r # rs1) s\<leadsto>* map (bder c) (r # rs2)" |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
964 |
by (simp add: srewrites7) |
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
965 |
next |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
966 |
case (ss3 r1 r2 rs) |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
967 |
have IH: "bder c r1 \<leadsto>* bder c r2" by fact |
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
968 |
then show "map (bder c) (r1 # rs) s\<leadsto>* map (bder c) (r2 # rs)" |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
969 |
by (simp add: srewrites7) |
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
970 |
next |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
971 |
case (ss4 rs) |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
972 |
show "map (bder c) (AZERO # rs) s\<leadsto>* map (bder c) rs" |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
973 |
using rrewrite_srewrite.ss4 by fastforce |
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
974 |
next |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
975 |
case (ss5 bs1 rs1 rsb) |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
976 |
show "map (bder c) (AALTs bs1 rs1 # rsb) s\<leadsto>* map (bder c) (map (fuse bs1) rs1 @ rsb)" |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
977 |
apply(simp) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
978 |
using bder_fuse_list map_map rrewrite_srewrite.ss5 srewrites.simps by blast |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
979 |
next |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
980 |
case (ss6 a1 a2 bs rsa rsb) |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
981 |
have as: "erase a1 = erase a2" by fact |
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
982 |
show "map (bder c) (bs @ [a1] @ rsa @ [a2] @ rsb) s\<leadsto>* map (bder c) (bs @ [a1] @ rsa @ rsb)" |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
983 |
apply(simp only: map_append) |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
984 |
by (smt (verit, best) erase_bder list.simps(8) list.simps(9) as rrewrite_srewrite.ss6 srewrites.simps) |
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
985 |
qed |
365 | 986 |
|
393 | 987 |
lemma rewrites_preserves_bder: |
373 | 988 |
assumes "r1 \<leadsto>* r2" |
989 |
shows "bder c r1 \<leadsto>* bder c r2" |
|
990 |
using assms |
|
991 |
apply(induction r1 r2 rule: rrewrites.induct) |
|
393 | 992 |
apply(simp_all add: rewrite_preserves_bder rrewrites_trans) |
373 | 993 |
done |
365 | 994 |
|
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
995 |
|
373 | 996 |
lemma central: |
997 |
shows "bders r s \<leadsto>* bders_simp r s" |
|
998 |
proof(induct s arbitrary: r rule: rev_induct) |
|
999 |
case Nil |
|
1000 |
then show "bders r [] \<leadsto>* bders_simp r []" by simp |
|
1001 |
next |
|
1002 |
case (snoc x xs) |
|
1003 |
have IH: "\<And>r. bders r xs \<leadsto>* bders_simp r xs" by fact |
|
1004 |
have "bders r (xs @ [x]) = bders (bders r xs) [x]" by (simp add: bders_append) |
|
1005 |
also have "... \<leadsto>* bders (bders_simp r xs) [x]" using IH |
|
393 | 1006 |
by (simp add: rewrites_preserves_bder) |
373 | 1007 |
also have "... \<leadsto>* bders_simp (bders_simp r xs) [x]" using IH |
393 | 1008 |
by (simp add: rewrites_to_bsimp) |
373 | 1009 |
finally show "bders r (xs @ [x]) \<leadsto>* bders_simp r (xs @ [x])" |
1010 |
by (simp add: bders_simp_append) |
|
1011 |
qed |
|
365 | 1012 |
|
393 | 1013 |
lemma main_aux: |
373 | 1014 |
assumes "bnullable (bders r s)" |
1015 |
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
|
1016 |
proof - |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1017 |
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
|
1018 |
then |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1019 |
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
|
1020 |
by (rule rewrites_bmkeps) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1021 |
qed |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1022 |
|
365 | 1023 |
|
393 | 1024 |
theorem main_blexer_simp: |
373 | 1025 |
shows "blexer r s = blexer_simp r s" |
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1026 |
unfolding blexer_def blexer_simp_def |
397
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
1027 |
by (metis central main_aux rewrites_bnullable_eq) |
365 | 1028 |
|
1029 |
||
373 | 1030 |
theorem blexersimp_correctness: |
1031 |
shows "lexer r s = blexer_simp r s" |
|
393 | 1032 |
using blexer_correctness main_blexer_simp by simp |
365 | 1033 |
|
1034 |
||
378 | 1035 |
|
398 | 1036 |
lemma asize_idem: |
1037 |
shows "asize (bsimp (bsimp r)) = asize (bsimp r)" |
|
1038 |
apply(induct r rule: bsimp.induct) |
|
1039 |
apply(auto) |
|
1040 |
prefer 2 |
|
1041 |
oops |
|
1042 |
||
378 | 1043 |
export_code blexer_simp blexer lexer bders bders_simp in Scala module_name VerifiedLexers |
1044 |
||
1045 |
||
365 | 1046 |
unused_thms |
1047 |
||
1048 |
||
378 | 1049 |
inductive aggressive:: "arexp \<Rightarrow> arexp \<Rightarrow> bool" ("_ \<leadsto>? _" [99, 99] 99) |
1050 |
where |
|
1051 |
"ASEQ bs (AALTs bs1 rs) r \<leadsto>? AALTs (bs@bs1) (map (\<lambda>r'. ASEQ [] r' r) rs) " |
|
1052 |
||
1053 |
||
1054 |
||
365 | 1055 |
end |