author | Christian Urban <christian.urban@kcl.ac.uk> |
Sun, 06 Feb 2022 00:02:04 +0000 | |
changeset 416 | 57182b36ec01 |
parent 411 | 97f0221add25 |
child 418 | 41a2a3b63853 |
permissions | -rw-r--r-- |
365 | 1 |
|
393 | 2 |
theory SizeBound4 |
405
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
3 |
imports "Lexer" "PDerivs" |
365 | 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 |
|
405
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
29 |
"decode' bs ZERO = (undefined, bs)" |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
30 |
| "decode' bs ONE = (Void, bs)" |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
31 |
| "decode' bs (CH d) = (Char d, bs)" |
365 | 32 |
| "decode' [] (ALT r1 r2) = (Void, [])" |
405
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
33 |
| "decode' (Z # bs) (ALT r1 r2) = (let (v, bs') = decode' bs r1 in (Left v, bs'))" |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
34 |
| "decode' (S # bs) (ALT r1 r2) = (let (v, bs') = decode' bs r2 in (Right v, bs'))" |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
35 |
| "decode' bs (SEQ r1 r2) = (let (v1, bs') = decode' bs r1 in |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
36 |
let (v2, bs'') = decode' bs' r2 in (Seq v1 v2, bs''))" |
365 | 37 |
| "decode' [] (STAR r) = (Void, [])" |
405
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
38 |
| "decode' (S # bs) (STAR r) = (Stars [], bs)" |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
39 |
| "decode' (Z # bs) (STAR r) = (let (v, bs') = decode' bs r in |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
40 |
let (vs, bs'') = decode' bs' (STAR r) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
41 |
in (Stars_add v vs, bs''))" |
365 | 42 |
by pat_completeness auto |
43 |
||
44 |
lemma decode'_smaller: |
|
405
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
45 |
assumes "decode'_dom (bs, r)" |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
46 |
shows "length (snd (decode' bs r)) \<le> length bs" |
365 | 47 |
using assms |
405
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
48 |
apply(induct bs r) |
365 | 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" |
|
402
1612f2a77bf6
more definitions in the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
400
diff
changeset
|
149 |
| "retrieve (AALTs bs [r]) v = bs @ retrieve r v" |
365 | 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)" |
|
416
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
209 |
| "bder c (ASTAR bs r) = ASEQ (bs @ [Z]) (bder c r) (ASTAR [] r)" |
365 | 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 |
||
402
1612f2a77bf6
more definitions in the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
400
diff
changeset
|
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" |
407 | 564 |
(*| ss1: "[] s\<leadsto> []"*) |
392
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)" |
416
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
569 |
| ss6: "L(erase a2) \<subseteq> L(erase a1) \<Longrightarrow> (rsa@[a1]@rsb@[a2]@rsc) s\<leadsto> (rsa@[a1]@rsb@rsc)" |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
570 |
(*| extra: "bnullable r1 \<Longrightarrow> ASEQ bs0 (ASEQ bs1 r1 r2) r3 \<leadsto> |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
571 |
ASEQ (bs0 @ bs1) r1 (ASEQ [] r2 r3)" |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
572 |
*) |
393 | 573 |
|
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
574 |
inductive |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
575 |
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
|
576 |
where |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
577 |
rs1[intro, simp]:"r \<leadsto>* r" |
365 | 578 |
| rs2[intro]: "\<lbrakk>r1 \<leadsto>* r2; r2 \<leadsto> r3\<rbrakk> \<Longrightarrow> r1 \<leadsto>* r3" |
579 |
||
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
580 |
inductive |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
581 |
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
|
582 |
where |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
583 |
sss1[intro, simp]:"rs s\<leadsto>* rs" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
584 |
| sss2[intro]: "\<lbrakk>rs1 s\<leadsto> rs2; rs2 s\<leadsto>* rs3\<rbrakk> \<Longrightarrow> rs1 s\<leadsto>* rs3" |
365 | 585 |
|
586 |
||
393 | 587 |
lemma r_in_rstar: |
588 |
shows "r1 \<leadsto> r2 \<Longrightarrow> r1 \<leadsto>* r2" |
|
589 |
using rrewrites.intros(1) rrewrites.intros(2) by blast |
|
590 |
||
416
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
591 |
lemma rs_in_rstar: |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
592 |
shows "r1 s\<leadsto> r2 \<Longrightarrow> r1 s\<leadsto>* r2" |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
593 |
using rrewrites.intros(1) rrewrites.intros(2) by blast |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
594 |
|
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
595 |
lemma rrewrites_trans[trans]: |
365 | 596 |
assumes a1: "r1 \<leadsto>* r2" and a2: "r2 \<leadsto>* r3" |
597 |
shows "r1 \<leadsto>* r3" |
|
598 |
using a2 a1 |
|
599 |
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
|
600 |
apply(auto) |
365 | 601 |
done |
602 |
||
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
603 |
lemma srewrites_trans[trans]: |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
604 |
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
|
605 |
shows "r1 s\<leadsto>* r3" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
606 |
using a1 a2 |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
607 |
apply(induct r1 r2 arbitrary: r3 rule: srewrites.induct) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
608 |
apply(auto) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
609 |
done |
365 | 610 |
|
611 |
||
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 contextrewrites0: |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
614 |
"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
|
615 |
apply(induct rs1 rs2 rule: srewrites.inducts) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
616 |
apply simp |
398 | 617 |
using bs8 r_in_rstar rrewrites_trans 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 contextrewrites1: |
393 | 620 |
"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
|
621 |
apply(induct r r' rule: rrewrites.induct) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
622 |
apply simp |
398 | 623 |
using bs8 ss3 by blast |
392
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 srewrite1: |
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 rs) |
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 ss2 by auto |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
630 |
|
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
631 |
lemma srewrites1: |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
632 |
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
|
633 |
apply(induct rs1 rs2 rule: srewrites.induct) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
634 |
apply(auto) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
635 |
using srewrite1 by blast |
365 | 636 |
|
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
637 |
lemma srewrite2: |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
638 |
shows "r1 \<leadsto> r2 \<Longrightarrow> True" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
639 |
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
|
640 |
apply(induct rule: rrewrite_srewrite.inducts) |
398 | 641 |
apply(auto) |
642 |
apply (metis append_Cons append_Nil srewrites1) |
|
643 |
apply(meson srewrites.simps ss3) |
|
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
644 |
apply (meson srewrites.simps ss4) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
645 |
apply (meson srewrites.simps ss5) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
646 |
by (metis append_Cons append_Nil srewrites.simps ss6) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
647 |
|
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
648 |
|
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
649 |
lemma srewrites3: |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
650 |
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
|
651 |
apply(induct rs1 rs2 arbitrary: rs rule: srewrites.induct) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
652 |
apply(auto) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
653 |
by (meson srewrite2(2) srewrites_trans) |
365 | 654 |
|
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
655 |
(* |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
656 |
lemma srewrites4: |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
657 |
assumes "rs3 s\<leadsto>* rs4" "rs1 s\<leadsto>* rs2" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
658 |
shows "(rs1 @ rs3) s\<leadsto>* (rs2 @ rs4)" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
659 |
using assms |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
660 |
apply(induct rs3 rs4 arbitrary: rs1 rs2 rule: srewrites.induct) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
661 |
apply (simp add: srewrites3) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
662 |
using srewrite1 by blast |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
663 |
*) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
664 |
|
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
665 |
lemma srewrites6: |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
666 |
assumes "r1 \<leadsto>* r2" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
667 |
shows "[r1] s\<leadsto>* [r2]" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
668 |
using assms |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
669 |
apply(induct r1 r2 rule: rrewrites.induct) |
398 | 670 |
apply(auto) |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
671 |
by (meson srewrites.simps srewrites_trans ss3) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
672 |
|
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
673 |
lemma srewrites7: |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
674 |
assumes "rs3 s\<leadsto>* rs4" "r1 \<leadsto>* r2" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
675 |
shows "(r1 # rs3) s\<leadsto>* (r2 # rs4)" |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
676 |
using assms |
398 | 677 |
by (smt (verit, del_insts) append.simps srewrites1 srewrites3 srewrites6 srewrites_trans) |
678 |
||
393 | 679 |
lemma ss6_stronger_aux: |
680 |
shows "(rs1 @ rs2) s\<leadsto>* (rs1 @ distinctBy rs2 erase (set (map erase rs1)))" |
|
681 |
apply(induct rs2 arbitrary: rs1) |
|
682 |
apply(auto) |
|
416
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
683 |
prefer 2 |
393 | 684 |
apply(drule_tac x="rs1 @ [a]" in meta_spec) |
416
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
685 |
apply(simp) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
686 |
apply(drule_tac x="rs1" in meta_spec) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
687 |
apply(subgoal_tac "(rs1 @ a # rs2) s\<leadsto>* (rs1 @ rs2)") |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
688 |
using srewrites_trans apply blast |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
689 |
apply(subgoal_tac "\<exists>rs1a rs1b. rs1 = rs1a @ [x] @ rs1b") |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
690 |
prefer 2 |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
691 |
apply (simp add: split_list) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
692 |
apply(erule exE)+ |
393 | 693 |
apply(simp) |
416
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
694 |
using ss6[simplified] |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
695 |
using rs_in_rstar by force |
393 | 696 |
|
697 |
lemma ss6_stronger: |
|
698 |
shows "rs1 s\<leadsto>* distinctBy rs1 erase {}" |
|
699 |
using ss6_stronger_aux[of "[]" _] by auto |
|
700 |
||
701 |
lemma rewrite_preserves_fuse: |
|
702 |
shows "r2 \<leadsto> r3 \<Longrightarrow> fuse bs r2 \<leadsto> fuse bs r3" |
|
398 | 703 |
and "rs2 s\<leadsto> rs3 \<Longrightarrow> map (fuse bs) rs2 s\<leadsto> map (fuse bs) rs3" |
393 | 704 |
proof(induct rule: rrewrite_srewrite.inducts) |
705 |
case (bs3 bs1 bs2 r) |
|
398 | 706 |
then show "fuse bs (ASEQ bs1 (AONE bs2) r) \<leadsto> fuse bs (fuse (bs1 @ bs2) r)" |
393 | 707 |
by (metis fuse.simps(5) fuse_append rrewrite_srewrite.bs3) |
708 |
next |
|
398 | 709 |
case (bs7 bs1 r) |
710 |
then show "fuse bs (AALTs bs1 [r]) \<leadsto> fuse bs (fuse bs1 r)" |
|
393 | 711 |
by (metis fuse.simps(4) fuse_append rrewrite_srewrite.bs7) |
712 |
next |
|
713 |
case (ss2 rs1 rs2 r) |
|
398 | 714 |
then show "map (fuse bs) (r # rs1) s\<leadsto> map (fuse bs) (r # rs2)" |
715 |
by (simp add: rrewrite_srewrite.ss2) |
|
393 | 716 |
next |
717 |
case (ss3 r1 r2 rs) |
|
398 | 718 |
then show "map (fuse bs) (r1 # rs) s\<leadsto> map (fuse bs) (r2 # rs)" |
719 |
by (simp add: rrewrite_srewrite.ss3) |
|
393 | 720 |
next |
721 |
case (ss5 bs1 rs1 rsb) |
|
398 | 722 |
have "map (fuse bs) (AALTs bs1 rs1 # rsb) = AALTs (bs @ bs1) rs1 # (map (fuse bs) rsb)" by simp |
723 |
also have "... s\<leadsto> ((map (fuse (bs @ bs1)) rs1) @ (map (fuse bs) rsb))" |
|
724 |
by (simp add: rrewrite_srewrite.ss5) |
|
725 |
finally show "map (fuse bs) (AALTs bs1 rs1 # rsb) s\<leadsto> map (fuse bs) (map (fuse bs1) rs1 @ rsb)" |
|
726 |
by (simp add: comp_def fuse_append) |
|
393 | 727 |
next |
416
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
728 |
case (ss6 a2 a1 rsa rsb rsc) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
729 |
have "L (erase a2) \<subseteq> L (erase a1)" by fact |
398 | 730 |
then show "map (fuse bs) (rsa @ [a1] @ rsb @ [a2] @ rsc) s\<leadsto> map (fuse bs) (rsa @ [a1] @ rsb @ rsc)" |
393 | 731 |
apply(simp) |
732 |
apply(rule rrewrite_srewrite.ss6[simplified]) |
|
733 |
apply(simp add: erase_fuse) |
|
734 |
done |
|
416
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
735 |
(*next |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
736 |
case (extra bs0 bs1 r1 r2 r3) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
737 |
then show ?case |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
738 |
by (metis append_assoc fuse.simps(5) rrewrite_srewrite.extra)*) |
397
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
739 |
qed (auto intro: rrewrite_srewrite.intros) |
393 | 740 |
|
741 |
lemma rewrites_fuse: |
|
742 |
assumes "r1 \<leadsto>* r2" |
|
743 |
shows "fuse bs r1 \<leadsto>* fuse bs r2" |
|
744 |
using assms |
|
745 |
apply(induction r1 r2 arbitrary: bs rule: rrewrites.induct) |
|
398 | 746 |
apply(auto intro: rewrite_preserves_fuse) |
393 | 747 |
done |
365 | 748 |
|
749 |
||
374 | 750 |
lemma star_seq: |
751 |
assumes "r1 \<leadsto>* r2" |
|
752 |
shows "ASEQ bs r1 r3 \<leadsto>* ASEQ bs r2 r3" |
|
753 |
using assms |
|
754 |
apply(induct r1 r2 arbitrary: r3 rule: rrewrites.induct) |
|
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
755 |
apply(auto intro: rrewrite_srewrite.intros) |
374 | 756 |
done |
365 | 757 |
|
374 | 758 |
lemma star_seq2: |
759 |
assumes "r3 \<leadsto>* r4" |
|
760 |
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
|
761 |
using assms |
374 | 762 |
apply(induct r3 r4 arbitrary: r1 rule: rrewrites.induct) |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
763 |
apply(auto intro: rrewrite_srewrite.intros) |
374 | 764 |
done |
365 | 765 |
|
374 | 766 |
lemma continuous_rewrite: |
767 |
assumes "r1 \<leadsto>* AZERO" |
|
768 |
shows "ASEQ bs1 r1 r2 \<leadsto>* AZERO" |
|
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
769 |
using assms bs1 star_seq by blast |
365 | 770 |
|
393 | 771 |
(* |
772 |
lemma continuous_rewrite2: |
|
773 |
assumes "r1 \<leadsto>* AONE bs" |
|
774 |
shows "ASEQ bs1 r1 r2 \<leadsto>* (fuse (bs1 @ bs) r2)" |
|
775 |
using assms by (meson bs3 rrewrites.simps star_seq) |
|
776 |
*) |
|
365 | 777 |
|
374 | 778 |
lemma bsimp_aalts_simpcases: |
779 |
shows "AONE bs \<leadsto>* bsimp (AONE bs)" |
|
780 |
and "AZERO \<leadsto>* bsimp AZERO" |
|
781 |
and "ACHAR bs c \<leadsto>* bsimp (ACHAR bs c)" |
|
782 |
by (simp_all) |
|
365 | 783 |
|
393 | 784 |
lemma bsimp_AALTs_rewrites: |
785 |
shows "AALTs bs1 rs \<leadsto>* bsimp_AALTs bs1 rs" |
|
786 |
by (smt (verit) bs6 bs7 bsimp_AALTs.elims rrewrites.simps) |
|
385 | 787 |
|
788 |
lemma trivialbsimp_srewrites: |
|
398 | 789 |
assumes "\<And>x. x \<in> set rs \<Longrightarrow> x \<leadsto>* f x" |
790 |
shows "rs s\<leadsto>* (map f rs)" |
|
791 |
using assms |
|
365 | 792 |
apply(induction rs) |
398 | 793 |
apply(simp_all add: srewrites7) |
794 |
done |
|
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
795 |
|
393 | 796 |
lemma fltsfrewrites: "rs s\<leadsto>* flts rs" |
797 |
apply(induction rs rule: flts.induct) |
|
798 |
apply(auto intro: rrewrite_srewrite.intros) |
|
799 |
apply (meson srewrites.simps srewrites1 ss5) |
|
800 |
using rs1 srewrites7 apply presburger |
|
801 |
using srewrites7 apply force |
|
802 |
apply (simp add: srewrites7) |
|
803 |
by (simp add: srewrites7) |
|
365 | 804 |
|
393 | 805 |
lemma bnullable0: |
806 |
shows "r1 \<leadsto> r2 \<Longrightarrow> bnullable r1 = bnullable r2" |
|
807 |
and "rs1 s\<leadsto> rs2 \<Longrightarrow> bnullables rs1 = bnullables rs2" |
|
808 |
apply(induct rule: rrewrite_srewrite.inducts) |
|
809 |
apply(auto simp add: bnullable_fuse) |
|
416
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
810 |
apply (meson UnCI bnullable_fuse imageI) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
811 |
|
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
812 |
using bnullable_correctness nullable_correctness by blast |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
813 |
|
373 | 814 |
|
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
815 |
lemma rewrites_bnullable_eq: |
393 | 816 |
assumes "r1 \<leadsto>* r2" |
817 |
shows "bnullable r1 = bnullable r2" |
|
818 |
using assms |
|
365 | 819 |
apply(induction r1 r2 rule: rrewrites.induct) |
820 |
apply simp |
|
393 | 821 |
using bnullable0(1) by auto |
365 | 822 |
|
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
823 |
lemma rewrite_bmkeps_aux: |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
824 |
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
|
825 |
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
|
826 |
proof (induct rule: rrewrite_srewrite.inducts) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
827 |
case (bs3 bs1 bs2 r) |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
828 |
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
|
829 |
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
|
830 |
by (simp add: bmkeps_fuse) |
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
831 |
next |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
832 |
case (bs7 bs r) |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
833 |
have IH2: "bnullable (AALTs bs [r])" by fact |
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
834 |
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
|
835 |
by (simp add: bmkeps_fuse) |
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
836 |
next |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
837 |
case (ss3 r1 r2 rs) |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
838 |
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
|
839 |
have as: "r1 \<leadsto> r2" by fact |
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
840 |
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
|
841 |
by (simp add: bnullable0) |
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
842 |
next |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
843 |
case (ss5 bs1 rs1 rsb) |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
844 |
have "bnullables (AALTs bs1 rs1 # rsb)" by fact |
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
845 |
then show "bmkepss (AALTs bs1 rs1 # rsb) = bmkepss (map (fuse bs1) rs1 @ rsb)" |
393 | 846 |
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
|
847 |
next |
416
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
848 |
case (ss6 a2 a1 rsa rsb rsc) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
849 |
have as1: "L(erase a2) \<subseteq> L(erase a1)" by fact |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
850 |
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
|
851 |
show "bmkepss (rsa @ [a1] @ rsb @ [a2] @ rsc) = bmkepss (rsa @ [a1] @ rsb @ rsc)" using as1 as3 |
416
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
852 |
by (smt (verit, ccfv_SIG) append_Cons bmkepss.simps(2) bmkepss1 bmkepss2 bnullable_correctness nullable_correctness subset_eq) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
853 |
(*next |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
854 |
case (extra bs0 bs1 r1 bs2 r2 bs4 bs3) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
855 |
then show ?case |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
856 |
apply(subst bmkeps.simps) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
857 |
apply(subst bmkeps.simps) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
858 |
apply(subst bmkeps.simps) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
859 |
apply(subst bmkeps.simps) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
860 |
apply(subst bmkeps.simps) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
861 |
apply(subst bmkeps.simps) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
862 |
apply(simp) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
863 |
done*) |
393 | 864 |
qed (auto) |
365 | 865 |
|
373 | 866 |
lemma rewrites_bmkeps: |
867 |
assumes "r1 \<leadsto>* r2" "bnullable r1" |
|
868 |
shows "bmkeps r1 = bmkeps r2" |
|
869 |
using assms |
|
870 |
proof(induction r1 r2 rule: rrewrites.induct) |
|
871 |
case (rs1 r) |
|
872 |
then show "bmkeps r = bmkeps r" by simp |
|
873 |
next |
|
874 |
case (rs2 r1 r2 r3) |
|
875 |
then have IH: "bmkeps r1 = bmkeps r2" by simp |
|
876 |
have a1: "bnullable r1" by fact |
|
877 |
have a2: "r1 \<leadsto>* r2" by fact |
|
878 |
have a3: "r2 \<leadsto> r3" by fact |
|
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
879 |
have a4: "bnullable r2" using a1 a2 by (simp add: rewrites_bnullable_eq) |
393 | 880 |
then have "bmkeps r2 = bmkeps r3" |
881 |
using a3 bnullable0(1) rewrite_bmkeps_aux(1) by blast |
|
373 | 882 |
then show "bmkeps r1 = bmkeps r3" using IH by simp |
883 |
qed |
|
365 | 884 |
|
393 | 885 |
|
886 |
lemma rewrites_to_bsimp: |
|
887 |
shows "r \<leadsto>* bsimp r" |
|
888 |
proof (induction r rule: bsimp.induct) |
|
889 |
case (1 bs1 r1 r2) |
|
890 |
have IH1: "r1 \<leadsto>* bsimp r1" by fact |
|
891 |
have IH2: "r2 \<leadsto>* bsimp r2" by fact |
|
892 |
{ assume as: "bsimp r1 = AZERO \<or> bsimp r2 = AZERO" |
|
893 |
with IH1 IH2 have "r1 \<leadsto>* AZERO \<or> r2 \<leadsto>* AZERO" by auto |
|
894 |
then have "ASEQ bs1 r1 r2 \<leadsto>* AZERO" |
|
895 |
by (metis bs2 continuous_rewrite rrewrites.simps star_seq2) |
|
896 |
then have "ASEQ bs1 r1 r2 \<leadsto>* bsimp (ASEQ bs1 r1 r2)" using as by auto |
|
897 |
} |
|
898 |
moreover |
|
899 |
{ assume "\<exists>bs. bsimp r1 = AONE bs" |
|
900 |
then obtain bs where as: "bsimp r1 = AONE bs" by blast |
|
901 |
with IH1 have "r1 \<leadsto>* AONE bs" by simp |
|
902 |
then have "ASEQ bs1 r1 r2 \<leadsto>* fuse (bs1 @ bs) r2" using bs3 star_seq by blast |
|
903 |
with IH2 have "ASEQ bs1 r1 r2 \<leadsto>* fuse (bs1 @ bs) (bsimp r2)" |
|
904 |
using rewrites_fuse by (meson rrewrites_trans) |
|
905 |
then have "ASEQ bs1 r1 r2 \<leadsto>* bsimp (ASEQ bs1 (AONE bs) r2)" by simp |
|
906 |
then have "ASEQ bs1 r1 r2 \<leadsto>* bsimp (ASEQ bs1 r1 r2)" by (simp add: as) |
|
907 |
} |
|
908 |
moreover |
|
909 |
{ assume as1: "bsimp r1 \<noteq> AZERO" "bsimp r2 \<noteq> AZERO" and as2: "(\<nexists>bs. bsimp r1 = AONE bs)" |
|
910 |
then have "bsimp_ASEQ bs1 (bsimp r1) (bsimp r2) = ASEQ bs1 (bsimp r1) (bsimp r2)" |
|
911 |
by (simp add: bsimp_ASEQ1) |
|
912 |
then have "ASEQ bs1 r1 r2 \<leadsto>* bsimp_ASEQ bs1 (bsimp r1) (bsimp r2)" using as1 as2 IH1 IH2 |
|
913 |
by (metis rrewrites_trans star_seq star_seq2) |
|
914 |
then have "ASEQ bs1 r1 r2 \<leadsto>* bsimp (ASEQ bs1 r1 r2)" by simp |
|
915 |
} |
|
916 |
ultimately show "ASEQ bs1 r1 r2 \<leadsto>* bsimp (ASEQ bs1 r1 r2)" by blast |
|
917 |
next |
|
918 |
case (2 bs1 rs) |
|
919 |
have IH: "\<And>x. x \<in> set rs \<Longrightarrow> x \<leadsto>* bsimp x" by fact |
|
920 |
then have "rs s\<leadsto>* (map bsimp rs)" by (simp add: trivialbsimp_srewrites) |
|
921 |
also have "... s\<leadsto>* flts (map bsimp rs)" by (simp add: fltsfrewrites) |
|
922 |
also have "... s\<leadsto>* distinctBy (flts (map bsimp rs)) erase {}" by (simp add: ss6_stronger) |
|
923 |
finally have "AALTs bs1 rs \<leadsto>* AALTs bs1 (distinctBy (flts (map bsimp rs)) erase {})" |
|
924 |
using contextrewrites0 by blast |
|
925 |
also have "... \<leadsto>* bsimp_AALTs bs1 (distinctBy (flts (map bsimp rs)) erase {})" |
|
926 |
by (simp add: bsimp_AALTs_rewrites) |
|
927 |
finally show "AALTs bs1 rs \<leadsto>* bsimp (AALTs bs1 rs)" by simp |
|
928 |
qed (simp_all) |
|
929 |
||
930 |
||
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
931 |
lemma to_zero_in_alt: |
393 | 932 |
shows "AALT bs (ASEQ [] AZERO r) r2 \<leadsto> AALT bs AZERO r2" |
398 | 933 |
by (simp add: bs1 bs8 ss3) |
365 | 934 |
|
935 |
||
936 |
||
374 | 937 |
lemma bder_fuse_list: |
938 |
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
|
939 |
apply(induction rs1) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
940 |
apply(simp_all add: bder_fuse) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
941 |
done |
365 | 942 |
|
416
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
943 |
lemma map_single: |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
944 |
shows "map f [x] = [f x]" |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
945 |
by simp |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
946 |
|
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
947 |
|
393 | 948 |
lemma rewrite_preserves_bder: |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
949 |
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
|
950 |
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
|
951 |
proof(induction rule: rrewrite_srewrite.inducts) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
952 |
case (bs1 bs r2) |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
953 |
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
|
954 |
by (simp add: continuous_rewrite) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
955 |
next |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
956 |
case (bs2 bs r1) |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
957 |
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
|
958 |
apply(auto) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
959 |
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
|
960 |
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
|
961 |
next |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
962 |
case (bs3 bs1 bs2 r) |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
963 |
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
|
964 |
apply(simp) |
398 | 965 |
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
|
966 |
next |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
967 |
case (bs4 r1 r2 bs r3) |
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
968 |
have as: "r1 \<leadsto> r2" by fact |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
969 |
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
|
970 |
from as IH show "bder c (ASEQ bs r1 r3) \<leadsto>* bder c (ASEQ bs r2 r3)" |
393 | 971 |
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
|
972 |
next |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
973 |
case (bs5 r3 r4 bs r1) |
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
974 |
have as: "r3 \<leadsto> r4" by fact |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
975 |
have IH: "bder c r3 \<leadsto>* bder c r4" by fact |
385 | 976 |
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
|
977 |
apply(simp) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
978 |
apply(auto) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
979 |
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
|
980 |
using star_seq2 by blast |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
981 |
next |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
982 |
case (bs6 bs) |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
983 |
show "bder c (AALTs bs []) \<leadsto>* bder c AZERO" |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
984 |
using rrewrite_srewrite.bs6 by force |
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
985 |
next |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
986 |
case (bs7 bs r) |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
987 |
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
|
988 |
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
|
989 |
next |
398 | 990 |
case (bs8 rs1 rs2 bs) |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
991 |
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
|
992 |
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
|
993 |
using contextrewrites0 by force |
407 | 994 |
(*next |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
995 |
case ss1 |
407 | 996 |
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
|
997 |
next |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
998 |
case (ss2 rs1 rs2 r) |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
999 |
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
|
1000 |
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
|
1001 |
by (simp add: srewrites7) |
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1002 |
next |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
1003 |
case (ss3 r1 r2 rs) |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
1004 |
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
|
1005 |
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
|
1006 |
by (simp add: srewrites7) |
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1007 |
next |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
1008 |
case (ss4 rs) |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
1009 |
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
|
1010 |
using rrewrite_srewrite.ss4 by fastforce |
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1011 |
next |
392
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
1012 |
case (ss5 bs1 rs1 rsb) |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
1013 |
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
|
1014 |
apply(simp) |
8194086c2a8a
simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents:
385
diff
changeset
|
1015 |
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
|
1016 |
next |
416
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1017 |
case (ss6 a2 a1 bs rsa rsb) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1018 |
have as: "L(erase a2) \<subseteq> L(erase a1)" by fact |
396
cc8e231529fb
added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
393
diff
changeset
|
1019 |
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
|
1020 |
apply(simp only: map_append) |
416
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1021 |
apply(simp only: map_single) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1022 |
apply(rule rs_in_rstar) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1023 |
thm rrewrite_srewrite.intros |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1024 |
apply(rule rrewrite_srewrite.ss6) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1025 |
using as |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1026 |
apply(auto simp add: der_correctness Der_def) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1027 |
done |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1028 |
(*next |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1029 |
case (extra bs0 bs1 r1 r2 r3) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1030 |
then show ?case |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1031 |
apply(auto simp add: comp_def) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1032 |
|
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1033 |
defer |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1034 |
using r_in_rstar rrewrite_srewrite.extra apply presburger |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1035 |
prefer 2 |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1036 |
using r_in_rstar rrewrite_srewrite.extra apply presburger |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1037 |
prefer 2 |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1038 |
sorry*) |
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1039 |
qed |
365 | 1040 |
|
416
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1041 |
|
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1042 |
|
393 | 1043 |
lemma rewrites_preserves_bder: |
373 | 1044 |
assumes "r1 \<leadsto>* r2" |
1045 |
shows "bder c r1 \<leadsto>* bder c r2" |
|
1046 |
using assms |
|
1047 |
apply(induction r1 r2 rule: rrewrites.induct) |
|
393 | 1048 |
apply(simp_all add: rewrite_preserves_bder rrewrites_trans) |
416
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1049 |
done |
365 | 1050 |
|
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1051 |
|
373 | 1052 |
lemma central: |
1053 |
shows "bders r s \<leadsto>* bders_simp r s" |
|
1054 |
proof(induct s arbitrary: r rule: rev_induct) |
|
1055 |
case Nil |
|
1056 |
then show "bders r [] \<leadsto>* bders_simp r []" by simp |
|
1057 |
next |
|
1058 |
case (snoc x xs) |
|
1059 |
have IH: "\<And>r. bders r xs \<leadsto>* bders_simp r xs" by fact |
|
1060 |
have "bders r (xs @ [x]) = bders (bders r xs) [x]" by (simp add: bders_append) |
|
1061 |
also have "... \<leadsto>* bders (bders_simp r xs) [x]" using IH |
|
393 | 1062 |
by (simp add: rewrites_preserves_bder) |
373 | 1063 |
also have "... \<leadsto>* bders_simp (bders_simp r xs) [x]" using IH |
393 | 1064 |
by (simp add: rewrites_to_bsimp) |
373 | 1065 |
finally show "bders r (xs @ [x]) \<leadsto>* bders_simp r (xs @ [x])" |
1066 |
by (simp add: bders_simp_append) |
|
1067 |
qed |
|
365 | 1068 |
|
393 | 1069 |
lemma main_aux: |
373 | 1070 |
assumes "bnullable (bders r s)" |
1071 |
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
|
1072 |
proof - |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1073 |
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
|
1074 |
then |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1075 |
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
|
1076 |
by (rule rewrites_bmkeps) |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1077 |
qed |
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1078 |
|
365 | 1079 |
|
393 | 1080 |
theorem main_blexer_simp: |
373 | 1081 |
shows "blexer r s = blexer_simp r s" |
381
0c666a0c57d7
isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents:
379
diff
changeset
|
1082 |
unfolding blexer_def blexer_simp_def |
397
e1b74d618f1b
updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
396
diff
changeset
|
1083 |
by (metis central main_aux rewrites_bnullable_eq) |
365 | 1084 |
|
1085 |
||
373 | 1086 |
theorem blexersimp_correctness: |
1087 |
shows "lexer r s = blexer_simp r s" |
|
393 | 1088 |
using blexer_correctness main_blexer_simp by simp |
365 | 1089 |
|
1090 |
||
405
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1091 |
(* some tests *) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1092 |
|
416
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1093 |
definition |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1094 |
bders_simp_Set :: "string set \<Rightarrow> arexp \<Rightarrow> arexp set" |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1095 |
where |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1096 |
"bders_simp_Set A r \<equiv> bders_simp r ` A" |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1097 |
|
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1098 |
lemma pders_Set_union: |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1099 |
shows "bders_simp_Set (A \<union> B) r = (bders_simp_Set A r \<union> bders_simp_Set B r)" |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1100 |
apply (simp add: bders_simp_Set_def) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1101 |
by (simp add: image_Un) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1102 |
|
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1103 |
lemma pders_Set_subset: |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1104 |
shows "A \<subseteq> B \<Longrightarrow> bders_simp_Set A r \<subseteq> bders_simp_Set B r" |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1105 |
apply (auto simp add: bders_simp_Set_def) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1106 |
done |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1107 |
|
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1108 |
|
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1109 |
lemma AZERO_r: |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1110 |
"bders_simp AZERO s = AZERO" |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1111 |
apply(induct s) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1112 |
apply(auto) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1113 |
done |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1114 |
|
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1115 |
lemma bders_simp_Set_ZERO [simp]: |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1116 |
shows "bders_simp_Set UNIV1 AZERO \<subseteq> {AZERO}" |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1117 |
unfolding UNIV1_def bders_simp_Set_def |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1118 |
apply(auto) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1119 |
using AZERO_r by blast |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1120 |
|
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1121 |
lemma AONE_r: |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1122 |
shows "bders_simp (AONE bs) s = AZERO \<or> bders_simp (AONE bs) s = AONE bs" |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1123 |
apply(induct s) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1124 |
apply(auto) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1125 |
using AZERO_r apply blast |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1126 |
using AZERO_r by blast |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1127 |
|
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1128 |
lemma bders_simp_Set_ONE [simp]: |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1129 |
shows "bders_simp_Set UNIV1 (AONE bs) \<subseteq> {AZERO, AONE bs}" |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1130 |
unfolding UNIV1_def bders_simp_Set_def |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1131 |
apply(auto split: if_splits) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1132 |
using AONE_r by blast |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1133 |
|
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1134 |
lemma ACHAR_r: |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1135 |
shows "bders_simp (ACHAR bs c) s = AZERO \<or> |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1136 |
bders_simp (ACHAR bs c) s = AONE bs \<or> |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1137 |
bders_simp (ACHAR bs c) s = ACHAR bs c" |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1138 |
apply(induct s) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1139 |
apply(auto) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1140 |
using AONE_r apply blast |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1141 |
using AZERO_r apply force |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1142 |
using AONE_r apply blast |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1143 |
using AZERO_r apply blast |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1144 |
using AONE_r apply blast |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1145 |
using AZERO_r by blast |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1146 |
|
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1147 |
lemma bders_simp_Set_CHAR [simp]: |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1148 |
shows "bders_simp_Set UNIV1 (ACHAR bs c) \<subseteq> {AZERO, AONE bs, ACHAR bs c}" |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1149 |
unfolding UNIV1_def bders_simp_Set_def |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1150 |
apply(auto) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1151 |
using ACHAR_r by blast |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1152 |
|
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1153 |
lemma bders_simp_Set_ALT [simp]: |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1154 |
shows "bders_simp_Set UNIV1 (AALT bs r1 r2) = bders_simp_Set UNIV1 r1 \<union> bders_simp_Set UNIV1 r2" |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1155 |
unfolding UNIV1_def bders_simp_Set_def |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1156 |
apply(auto) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1157 |
oops |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1158 |
|
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1159 |
|
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1160 |
|
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1161 |
|
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1162 |
(* |
407 | 1163 |
lemma asize_fuse: |
1164 |
shows "asize (fuse bs r) = asize r" |
|
1165 |
apply(induct r arbitrary: bs) |
|
1166 |
apply(auto) |
|
1167 |
done |
|
1168 |
||
1169 |
lemma asize_rewrite2: |
|
1170 |
shows "r1 \<leadsto> r2 \<Longrightarrow> asize r1 \<ge> asize r2" |
|
1171 |
and "rs1 s\<leadsto> rs2 \<Longrightarrow> (sum_list (map asize rs1)) \<ge> (sum_list (map asize rs2))" |
|
1172 |
apply(induct rule: rrewrite_srewrite.inducts) |
|
1173 |
apply(auto simp add: asize_fuse comp_def) |
|
1174 |
done |
|
1175 |
||
1176 |
lemma asize_rrewrites: |
|
1177 |
assumes "r1 \<leadsto>* r2" |
|
1178 |
shows "asize r1 \<ge> asize r2" |
|
1179 |
using assms |
|
1180 |
apply(induct rule: rrewrites.induct) |
|
1181 |
apply(auto) |
|
1182 |
using asize_rewrite2(1) le_trans by blast |
|
1183 |
||
1184 |
||
1185 |
||
1186 |
fun asize2 :: "arexp \<Rightarrow> nat" where |
|
1187 |
"asize2 AZERO = 1" |
|
1188 |
| "asize2 (AONE cs) = 1" |
|
1189 |
| "asize2 (ACHAR cs c) = 1" |
|
1190 |
| "asize2 (AALTs cs rs) = Suc (Suc (sum_list (map asize2 rs)))" |
|
1191 |
| "asize2 (ASEQ cs r1 r2) = Suc (asize2 r1 + asize2 r2)" |
|
1192 |
| "asize2 (ASTAR cs r) = Suc (asize2 r)" |
|
1193 |
||
1194 |
||
410 | 1195 |
|
407 | 1196 |
lemma asize2_fuse: |
1197 |
shows "asize2 (fuse bs r) = asize2 r" |
|
1198 |
apply(induct r arbitrary: bs) |
|
1199 |
apply(auto) |
|
1200 |
done |
|
1201 |
||
1202 |
lemma asize2_not_zero: |
|
1203 |
shows "0 < asize2 r" |
|
1204 |
apply(induct r) |
|
1205 |
apply(auto) |
|
1206 |
done |
|
1207 |
||
1208 |
lemma asize_rewrite: |
|
1209 |
shows "r1 \<leadsto> r2 \<Longrightarrow> asize2 r1 > asize2 r2" |
|
1210 |
and "rs1 s\<leadsto> rs2 \<Longrightarrow> (sum_list (map asize2 rs1)) > (sum_list (map asize2 rs2))" |
|
1211 |
apply(induct rule: rrewrite_srewrite.inducts) |
|
1212 |
apply(auto simp add: asize2_fuse comp_def) |
|
1213 |
apply(simp add: asize2_not_zero) |
|
1214 |
done |
|
1215 |
||
1216 |
lemma asize2_bsimp_ASEQ: |
|
1217 |
shows "asize2 (bsimp_ASEQ bs r1 r2) \<le> Suc (asize2 r1 + asize2 r2)" |
|
1218 |
apply(induct bs r1 r2 rule: bsimp_ASEQ.induct) |
|
1219 |
apply(auto) |
|
1220 |
done |
|
1221 |
||
1222 |
lemma asize2_bsimp_AALTs: |
|
1223 |
shows "asize2 (bsimp_AALTs bs rs) \<le> Suc (Suc (sum_list (map asize2 rs)))" |
|
1224 |
apply(induct bs rs rule: bsimp_AALTs.induct) |
|
1225 |
apply(auto simp add: asize2_fuse) |
|
1226 |
done |
|
1227 |
||
1228 |
lemma distinctBy_asize2: |
|
1229 |
shows "sum_list (map asize2 (distinctBy rs f acc)) \<le> sum_list (map asize2 rs)" |
|
1230 |
apply(induct rs f acc rule: distinctBy.induct) |
|
1231 |
apply(auto) |
|
1232 |
done |
|
1233 |
||
1234 |
lemma flts_asize2: |
|
1235 |
shows "sum_list (map asize2 (flts rs)) \<le> sum_list (map asize2 rs)" |
|
1236 |
apply(induct rs rule: flts.induct) |
|
1237 |
apply(auto simp add: comp_def asize2_fuse) |
|
1238 |
done |
|
1239 |
||
1240 |
lemma sumlist_asize2: |
|
1241 |
assumes "\<And>x. x \<in> set rs \<Longrightarrow> asize2 (f x) \<le> asize2 x" |
|
1242 |
shows "sum_list (map asize2 (map f rs)) \<le> sum_list (map asize2 rs)" |
|
1243 |
using assms |
|
1244 |
apply(induct rs) |
|
1245 |
apply(auto simp add: comp_def) |
|
1246 |
by (simp add: add_le_mono) |
|
1247 |
||
1248 |
lemma test0: |
|
1249 |
assumes "r1 \<leadsto>* r2" |
|
1250 |
shows "r1 = r2 \<or> (\<exists>r3. r1 \<leadsto> r3 \<and> r3 \<leadsto>* r2)" |
|
1251 |
using assms |
|
1252 |
apply(induct r1 r2 rule: rrewrites.induct) |
|
1253 |
apply(auto) |
|
1254 |
done |
|
1255 |
||
1256 |
lemma test2: |
|
1257 |
assumes "r1 \<leadsto>* r2" |
|
1258 |
shows "asize2 r1 \<ge> asize2 r2" |
|
1259 |
using assms |
|
1260 |
apply(induct r1 r2 rule: rrewrites.induct) |
|
1261 |
apply(auto) |
|
1262 |
using asize_rewrite(1) by fastforce |
|
1263 |
||
1264 |
||
1265 |
lemma test3: |
|
1266 |
shows "r = bsimp r \<or> (asize2 (bsimp r) < asize2 r)" |
|
1267 |
proof - |
|
1268 |
have "r \<leadsto>* bsimp r" |
|
1269 |
by (simp add: rewrites_to_bsimp) |
|
1270 |
then have "r = bsimp r \<or> (\<exists>r3. r \<leadsto> r3 \<and> r3 \<leadsto>* bsimp r)" |
|
1271 |
using test0 by blast |
|
1272 |
then show ?thesis |
|
1273 |
by (meson asize_rewrite(1) dual_order.strict_trans2 test2) |
|
1274 |
qed |
|
1275 |
||
1276 |
lemma test3Q: |
|
1277 |
shows "r = bsimp r \<or> (asize (bsimp r) \<le> asize r)" |
|
1278 |
proof - |
|
1279 |
have "r \<leadsto>* bsimp r" |
|
1280 |
by (simp add: rewrites_to_bsimp) |
|
1281 |
then have "r = bsimp r \<or> (\<exists>r3. r \<leadsto> r3 \<and> r3 \<leadsto>* bsimp r)" |
|
1282 |
using test0 by blast |
|
1283 |
then show ?thesis |
|
1284 |
using asize_rewrite2(1) asize_rrewrites le_trans by blast |
|
1285 |
qed |
|
1286 |
||
1287 |
lemma test4: |
|
1288 |
shows "asize2 (bsimp (bsimp r)) \<le> asize2 (bsimp r)" |
|
1289 |
apply(induct r rule: bsimp.induct) |
|
1290 |
apply(auto) |
|
1291 |
using rewrites_to_bsimp test2 apply fastforce |
|
1292 |
using rewrites_to_bsimp test2 by presburger |
|
1293 |
||
1294 |
lemma test4Q: |
|
1295 |
shows "asize (bsimp (bsimp r)) \<le> asize (bsimp r)" |
|
1296 |
apply(induct r rule: bsimp.induct) |
|
1297 |
apply(auto) |
|
1298 |
apply (metis order_refl test3Q) |
|
1299 |
by (metis le_refl test3Q) |
|
1300 |
||
1301 |
||
1302 |
||
1303 |
lemma testb0: |
|
1304 |
shows "fuse bs1 (bsimp_ASEQ bs r1 r2) = bsimp_ASEQ (bs1 @ bs) r1 r2" |
|
1305 |
apply(induct bs r1 r2 arbitrary: bs1 rule: bsimp_ASEQ.induct) |
|
1306 |
apply(auto) |
|
1307 |
done |
|
1308 |
||
1309 |
lemma testb1: |
|
1310 |
shows "fuse bs1 (bsimp_AALTs bs rs) = bsimp_AALTs (bs1 @ bs) rs" |
|
1311 |
apply(induct bs rs arbitrary: bs1 rule: bsimp_AALTs.induct) |
|
1312 |
apply(auto simp add: fuse_append) |
|
1313 |
done |
|
1314 |
||
1315 |
lemma testb2: |
|
1316 |
shows "bsimp (bsimp_ASEQ bs r1 r2) = bsimp_ASEQ bs (bsimp r1) (bsimp r2)" |
|
1317 |
apply(induct bs r1 r2 rule: bsimp_ASEQ.induct) |
|
1318 |
apply(auto simp add: testb0 testb1) |
|
1319 |
done |
|
1320 |
||
1321 |
lemma testb3: |
|
1322 |
shows "\<nexists>r'. (bsimp r \<leadsto> r') \<and> asize2 (bsimp r) > asize2 r'" |
|
1323 |
apply(induct r rule: bsimp.induct) |
|
1324 |
apply(auto) |
|
1325 |
defer |
|
1326 |
defer |
|
1327 |
using rrewrite.cases apply blast |
|
1328 |
using rrewrite.cases apply blast |
|
1329 |
using rrewrite.cases apply blast |
|
1330 |
using rrewrite.cases apply blast |
|
1331 |
oops |
|
1332 |
||
1333 |
lemma testb4: |
|
1334 |
assumes "sum_list (map asize rs1) \<le> sum_list (map asize rs2)" |
|
1335 |
shows "asize (bsimp_AALTs bs1 rs1) \<le> Suc (asize (bsimp_AALTs bs1 rs2))" |
|
1336 |
using assms |
|
1337 |
apply(induct bs1 rs2 arbitrary: rs1 rule: bsimp_AALTs.induct) |
|
1338 |
apply(auto) |
|
1339 |
apply(case_tac rs1) |
|
1340 |
apply(auto) |
|
1341 |
using asize2.elims apply auto[1] |
|
1342 |
apply (metis One_nat_def Zero_not_Suc asize.elims) |
|
1343 |
apply(case_tac rs1) |
|
1344 |
apply(auto) |
|
1345 |
apply(case_tac list) |
|
1346 |
apply(auto) |
|
1347 |
using asize_fuse apply force |
|
1348 |
apply (simp add: asize_fuse) |
|
1349 |
by (smt (verit, ccfv_threshold) One_nat_def add.right_neutral asize.simps(1) asize.simps(4) asize_fuse bsimp_AALTs.elims le_Suc_eq list.map(1) list.map(2) not_less_eq_eq sum_list_simps(1) sum_list_simps(2)) |
|
1350 |
||
1351 |
lemma flts_asize: |
|
1352 |
shows "sum_list (map asize (flts rs)) \<le> sum_list (map asize rs)" |
|
1353 |
apply(induct rs rule: flts.induct) |
|
1354 |
apply(auto simp add: comp_def asize_fuse) |
|
1355 |
done |
|
1356 |
||
1357 |
||
1358 |
lemma test5: |
|
1359 |
shows "asize2 r \<ge> asize2 (bsimp r)" |
|
1360 |
apply(induct r rule: bsimp.induct) |
|
1361 |
apply(auto) |
|
1362 |
apply (meson Suc_le_mono add_le_mono asize2_bsimp_ASEQ order_trans) |
|
1363 |
apply(rule order_trans) |
|
1364 |
apply(rule asize2_bsimp_AALTs) |
|
1365 |
apply(simp) |
|
1366 |
apply(rule order_trans) |
|
1367 |
apply(rule distinctBy_asize2) |
|
1368 |
apply(rule order_trans) |
|
1369 |
apply(rule flts_asize2) |
|
1370 |
using sumlist_asize2 by force |
|
1371 |
||
1372 |
||
405
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1373 |
fun awidth :: "arexp \<Rightarrow> nat" where |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1374 |
"awidth AZERO = 1" |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1375 |
| "awidth (AONE cs) = 1" |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1376 |
| "awidth (ACHAR cs c) = 1" |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1377 |
| "awidth (AALTs cs rs) = (sum_list (map awidth rs))" |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1378 |
| "awidth (ASEQ cs r1 r2) = (awidth r1 + awidth r2)" |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1379 |
| "awidth (ASTAR cs r) = (awidth r)" |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1380 |
|
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1381 |
|
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1382 |
|
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1383 |
lemma |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1384 |
shows "s \<notin> L r \<Longrightarrow> blexer_simp r s = None" |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1385 |
by (simp add: blexersimp_correctness lexer_correct_None) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1386 |
|
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1387 |
lemma g1: |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1388 |
"bders_simp AZERO s = AZERO" |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1389 |
apply(induct s) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1390 |
apply(simp) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1391 |
apply(simp) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1392 |
done |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1393 |
|
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1394 |
lemma g2: |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1395 |
"s \<noteq> Nil \<Longrightarrow> bders_simp (AONE bs) s = AZERO" |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1396 |
apply(induct s) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1397 |
apply(simp) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1398 |
apply(simp) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1399 |
apply(case_tac s) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1400 |
apply(simp) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1401 |
apply(simp) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1402 |
done |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1403 |
|
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1404 |
lemma finite_pder: |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1405 |
shows "finite (pder c r)" |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1406 |
apply(induct c r rule: pder.induct) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1407 |
apply(auto) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1408 |
done |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1409 |
|
407 | 1410 |
|
405
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1411 |
|
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1412 |
lemma awidth_fuse: |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1413 |
shows "awidth (fuse bs r) = awidth r" |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1414 |
apply(induct r arbitrary: bs) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1415 |
apply(auto) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1416 |
done |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1417 |
|
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1418 |
lemma pders_SEQs: |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1419 |
assumes "finite A" |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1420 |
shows "card (SEQs A (STAR r)) \<le> card A" |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1421 |
using assms |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1422 |
by (simp add: SEQs_eq_image card_image_le) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1423 |
|
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1424 |
lemma binullable_intern: |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1425 |
shows "bnullable (intern r) = nullable r" |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1426 |
apply(induct r) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1427 |
apply(auto simp add: bnullable_fuse) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1428 |
done |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1429 |
|
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1430 |
lemma |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1431 |
"card (pder c r) \<le> awidth (bder c (intern r))" |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1432 |
apply(induct c r rule: pder.induct) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1433 |
apply(simp) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1434 |
apply(simp) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1435 |
apply(simp) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1436 |
apply(simp) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1437 |
apply(rule order_trans) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1438 |
apply(rule card_Un_le) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1439 |
apply (simp add: awidth_fuse bder_fuse) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1440 |
defer |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1441 |
apply(simp) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1442 |
apply(rule order_trans) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1443 |
apply(rule pders_SEQs) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1444 |
using finite_pder apply presburger |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1445 |
apply (simp add: awidth_fuse) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1446 |
apply(auto) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1447 |
apply(rule order_trans) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1448 |
apply(rule card_Un_le) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1449 |
apply(simp add: awidth_fuse) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1450 |
defer |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1451 |
using binullable_intern apply blast |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1452 |
using binullable_intern apply blast |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1453 |
apply (smt (verit, best) SEQs_eq_image add.commute add_Suc_right card_image_le dual_order.trans finite_pder trans_le_add2) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1454 |
apply(subgoal_tac "card (SEQs (pder c r1) r2) \<le> card (pder c r1)") |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1455 |
apply(linarith) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1456 |
by (simp add: UNION_singleton_eq_range card_image_le finite_pder) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1457 |
|
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1458 |
lemma |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1459 |
"card (pder c r) \<le> asize (bder c (intern r))" |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1460 |
apply(induct c r rule: pder.induct) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1461 |
apply(simp) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1462 |
apply(simp) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1463 |
apply(simp) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1464 |
apply(simp) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1465 |
apply (metis add_mono_thms_linordered_semiring(1) asize_fuse bder_fuse card_Un_le le_Suc_eq order_trans) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1466 |
defer |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1467 |
apply(simp) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1468 |
apply(rule order_trans) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1469 |
apply(rule pders_SEQs) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1470 |
using finite_pder apply presburger |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1471 |
apply (simp add: asize_fuse) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1472 |
apply(simp) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1473 |
apply(auto) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1474 |
apply(rule order_trans) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1475 |
apply(rule card_Un_le) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1476 |
apply (smt (z3) SEQs_eq_image add.commute add_Suc_right add_mono_thms_linordered_semiring(1) asize_fuse card_image_le dual_order.trans finite_pder le_add1) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1477 |
apply(rule order_trans) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1478 |
apply(rule card_Un_le) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1479 |
using binullable_intern apply blast |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1480 |
using binullable_intern apply blast |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1481 |
by (smt (verit, best) SEQs_eq_image add.commute add_Suc_right card_image_le dual_order.trans finite_pder trans_le_add2) |
410 | 1482 |
|
1483 |
||
1484 |
||
405
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1485 |
lemma |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1486 |
"card (pder c r) \<le> asize (bsimp (bder c (intern r)))" |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1487 |
apply(induct c r rule: pder.induct) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1488 |
apply(simp) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1489 |
apply(simp) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1490 |
apply(simp) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1491 |
apply(simp) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1492 |
apply(rule order_trans) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1493 |
apply(rule card_Un_le) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1494 |
prefer 3 |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1495 |
apply(simp) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1496 |
apply(rule order_trans) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1497 |
apply(rule pders_SEQs) |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1498 |
using finite_pder apply blast |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1499 |
oops |
3cfea5bb5e23
updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents:
402
diff
changeset
|
1500 |
|
416
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1501 |
*) |
410 | 1502 |
|
1503 |
||
400 | 1504 |
(* below is the idempotency of bsimp *) |
378 | 1505 |
|
416
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1506 |
(* |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1507 |
|
400 | 1508 |
lemma bsimp_ASEQ_fuse: |
1509 |
shows "fuse bs1 (bsimp_ASEQ bs2 r1 r2) = bsimp_ASEQ (bs1 @ bs2) r1 r2" |
|
1510 |
apply(induct r1 r2 arbitrary: bs1 bs2 rule: bsimp_ASEQ.induct) |
|
1511 |
apply(auto) |
|
1512 |
done |
|
1513 |
||
1514 |
lemma bsimp_AALTs_fuse: |
|
1515 |
assumes "\<forall>r \<in> set rs. fuse bs1 (fuse bs2 r) = fuse (bs1 @ bs2) r" |
|
1516 |
shows "fuse bs1 (bsimp_AALTs bs2 rs) = bsimp_AALTs (bs1 @ bs2) rs" |
|
1517 |
using assms |
|
1518 |
apply(induct bs2 rs arbitrary: bs1 rule: bsimp_AALTs.induct) |
|
1519 |
apply(auto) |
|
1520 |
done |
|
1521 |
||
1522 |
lemma bsimp_fuse: |
|
1523 |
shows "fuse bs (bsimp r) = bsimp (fuse bs r)" |
|
1524 |
apply(induct r arbitrary: bs) |
|
1525 |
apply(simp_all add: bsimp_ASEQ_fuse bsimp_AALTs_fuse fuse_append) |
|
1526 |
done |
|
1527 |
||
1528 |
lemma bsimp_ASEQ_idem: |
|
1529 |
assumes "bsimp (bsimp r1) = bsimp r1" "bsimp (bsimp r2) = bsimp r2" |
|
1530 |
shows "bsimp (bsimp_ASEQ x1 (bsimp r1) (bsimp r2)) = bsimp_ASEQ x1 (bsimp r1) (bsimp r2)" |
|
1531 |
using assms |
|
1532 |
apply(case_tac "bsimp r1 = AZERO") |
|
1533 |
apply(simp) |
|
1534 |
apply(case_tac "bsimp r2 = AZERO") |
|
1535 |
apply(simp) |
|
1536 |
apply(case_tac "\<exists>bs. bsimp r1 = AONE bs") |
|
1537 |
apply(auto)[1] |
|
1538 |
apply (metis bsimp_fuse) |
|
1539 |
apply(simp add: bsimp_ASEQ1) |
|
1540 |
done |
|
1541 |
||
1542 |
lemma bsimp_AALTs_idem: |
|
1543 |
assumes "\<forall>r \<in> set rs. bsimp (bsimp r) = bsimp r" |
|
1544 |
shows "bsimp (bsimp_AALTs bs rs) = bsimp_AALTs bs (map bsimp rs)" |
|
1545 |
using assms |
|
1546 |
apply(induct bs rs rule: bsimp_AALTs.induct) |
|
1547 |
apply(simp) |
|
1548 |
apply(simp) |
|
1549 |
using bsimp_fuse apply presburger |
|
1550 |
oops |
|
1551 |
||
1552 |
lemma bsimp_idem_rev: |
|
1553 |
shows "\<nexists>r2. bsimp r1 \<leadsto> r2" |
|
1554 |
apply(induct r1 rule: bsimp.induct) |
|
1555 |
apply(auto) |
|
1556 |
defer |
|
1557 |
defer |
|
1558 |
using rrewrite.simps apply blast |
|
1559 |
using rrewrite.cases apply blast |
|
1560 |
using rrewrite.simps apply blast |
|
1561 |
using rrewrite.cases apply blast |
|
1562 |
apply(case_tac "bsimp r1 = AZERO") |
|
1563 |
apply(simp) |
|
1564 |
apply(case_tac "bsimp r2 = AZERO") |
|
1565 |
apply(simp) |
|
1566 |
apply(case_tac "\<exists>bs. bsimp r1 = AONE bs") |
|
1567 |
apply(auto)[1] |
|
1568 |
prefer 2 |
|
1569 |
apply (smt (verit, best) arexp.distinct(25) arexp.inject(3) bsimp_ASEQ1 rrewrite.simps) |
|
1570 |
defer |
|
1571 |
oops |
|
1572 |
||
1573 |
lemma bsimp_idem: |
|
1574 |
shows "bsimp (bsimp r) = bsimp r" |
|
398 | 1575 |
apply(induct r rule: bsimp.induct) |
1576 |
apply(auto) |
|
400 | 1577 |
using bsimp_ASEQ_idem apply presburger |
398 | 1578 |
oops |
1579 |
||
409 | 1580 |
lemma neg: |
1581 |
shows " \<not>(\<exists>r2. r1 \<leadsto> r2 \<and> (r2 \<leadsto>* bsimp r1) )" |
|
1582 |
apply(rule notI) |
|
1583 |
apply(erule exE) |
|
1584 |
apply(erule conjE) |
|
1585 |
oops |
|
1586 |
||
1587 |
||
1588 |
||
1589 |
||
1590 |
lemma reduction_always_in_bsimp: |
|
1591 |
shows " \<lbrakk> r1 \<leadsto> r2 ; \<not>(r2 \<leadsto>* bsimp r1)\<rbrakk> \<Longrightarrow> False" |
|
1592 |
apply(erule rrewrite.cases) |
|
1593 |
apply simp |
|
1594 |
apply auto |
|
1595 |
||
1596 |
oops |
|
416
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1597 |
*) |
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1598 |
|
409 | 1599 |
|
1600 |
(* |
|
1601 |
AALTs [] [AZERO, AALTs(bs1, [a, b]) ] |
|
1602 |
rewrite seq 1: \<leadsto> AALTs [] [ AALTs(bs1, [a, b]) ] \<leadsto> |
|
1603 |
fuse [] (AALTs bs1, [a, b]) |
|
1604 |
rewrite seq 2: \<leadsto> AALTs [] [AZERO, (fuse bs1 a), (fuse bs1 b)]) ] |
|
1605 |
||
1606 |
*) |
|
1607 |
||
1608 |
||
1609 |
(*r' size bsimp r > size r' |
|
1610 |
r' \<leadsto>* bsimp bsimp r |
|
1611 |
size bsimp r > size r' \<ge> size bsimp bsimp r*) |
|
1612 |
||
378 | 1613 |
|
365 | 1614 |
unused_thms |
1615 |
||
416
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1616 |
(* |
378 | 1617 |
inductive aggressive:: "arexp \<Rightarrow> arexp \<Rightarrow> bool" ("_ \<leadsto>? _" [99, 99] 99) |
1618 |
where |
|
1619 |
"ASEQ bs (AALTs bs1 rs) r \<leadsto>? AALTs (bs@bs1) (map (\<lambda>r'. ASEQ [] r' r) rs) " |
|
416
57182b36ec01
more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
411
diff
changeset
|
1620 |
*) |
378 | 1621 |
|
1622 |
||
365 | 1623 |
end |