148
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
1 |
|
311
|
2 |
theory BitCoded
|
286
|
3 |
imports "Lexer"
|
148
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
4 |
begin
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
5 |
|
154
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
6 |
section {* Bit-Encodings *}
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
7 |
|
289
|
8 |
datatype bit = Z | S
|
|
9 |
|
154
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
10 |
fun
|
289
|
11 |
code :: "val \<Rightarrow> bit list"
|
154
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
12 |
where
|
286
|
13 |
"code Void = []"
|
|
14 |
| "code (Char c) = []"
|
289
|
15 |
| "code (Left v) = Z # (code v)"
|
|
16 |
| "code (Right v) = S # (code v)"
|
286
|
17 |
| "code (Seq v1 v2) = (code v1) @ (code v2)"
|
289
|
18 |
| "code (Stars []) = [S]"
|
|
19 |
| "code (Stars (v # vs)) = (Z # code v) @ code (Stars vs)"
|
286
|
20 |
|
154
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
21 |
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
22 |
fun
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
23 |
Stars_add :: "val \<Rightarrow> val \<Rightarrow> val"
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
24 |
where
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
25 |
"Stars_add v (Stars vs) = Stars (v # vs)"
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
26 |
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
27 |
function
|
289
|
28 |
decode' :: "bit list \<Rightarrow> rexp \<Rightarrow> (val * bit list)"
|
154
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
29 |
where
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
30 |
"decode' ds ZERO = (Void, [])"
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
31 |
| "decode' ds ONE = (Void, ds)"
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
32 |
| "decode' ds (CHAR d) = (Char d, ds)"
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
33 |
| "decode' [] (ALT r1 r2) = (Void, [])"
|
289
|
34 |
| "decode' (Z # ds) (ALT r1 r2) = (let (v, ds') = decode' ds r1 in (Left v, ds'))"
|
|
35 |
| "decode' (S # ds) (ALT r1 r2) = (let (v, ds') = decode' ds r2 in (Right v, ds'))"
|
154
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
36 |
| "decode' ds (SEQ r1 r2) = (let (v1, ds') = decode' ds r1 in
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
37 |
let (v2, ds'') = decode' ds' r2 in (Seq v1 v2, ds''))"
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
38 |
| "decode' [] (STAR r) = (Void, [])"
|
289
|
39 |
| "decode' (S # ds) (STAR r) = (Stars [], ds)"
|
|
40 |
| "decode' (Z # ds) (STAR r) = (let (v, ds') = decode' ds r in
|
154
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
41 |
let (vs, ds'') = decode' ds' (STAR r)
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
42 |
in (Stars_add v vs, ds''))"
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
43 |
by pat_completeness auto
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
44 |
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
45 |
lemma decode'_smaller:
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
46 |
assumes "decode'_dom (ds, r)"
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
47 |
shows "length (snd (decode' ds r)) \<le> length ds"
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
48 |
using assms
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
49 |
apply(induct ds r)
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
50 |
apply(auto simp add: decode'.psimps split: prod.split)
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
51 |
using dual_order.trans apply blast
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
52 |
by (meson dual_order.trans le_SucI)
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
53 |
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
54 |
termination "decode'"
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
55 |
apply(relation "inv_image (measure(%cs. size cs) <*lex*> measure(%s. size s)) (%(ds,r). (r,ds))")
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
56 |
apply(auto dest!: decode'_smaller)
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
57 |
by (metis less_Suc_eq_le snd_conv)
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
58 |
|
286
|
59 |
definition
|
289
|
60 |
decode :: "bit list \<Rightarrow> rexp \<Rightarrow> val option"
|
154
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
61 |
where
|
286
|
62 |
"decode ds r \<equiv> (let (v, ds') = decode' ds r
|
154
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
63 |
in (if ds' = [] then Some v else None))"
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
64 |
|
286
|
65 |
lemma decode'_code_Stars:
|
|
66 |
assumes "\<forall>v\<in>set vs. \<Turnstile> v : r \<and> (\<forall>x. decode' (code v @ x) r = (v, x)) \<and> flat v \<noteq> []"
|
|
67 |
shows "decode' (code (Stars vs) @ ds) (STAR r) = (Stars vs, ds)"
|
|
68 |
using assms
|
|
69 |
apply(induct vs)
|
|
70 |
apply(auto)
|
|
71 |
done
|
|
72 |
|
154
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
73 |
lemma decode'_code:
|
286
|
74 |
assumes "\<Turnstile> v : r"
|
|
75 |
shows "decode' ((code v) @ ds) r = (v, ds)"
|
154
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
76 |
using assms
|
286
|
77 |
apply(induct v r arbitrary: ds)
|
|
78 |
apply(auto)
|
|
79 |
using decode'_code_Stars by blast
|
154
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
80 |
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
81 |
lemma decode_code:
|
286
|
82 |
assumes "\<Turnstile> v : r"
|
|
83 |
shows "decode (code v) r = Some v"
|
|
84 |
using assms unfolding decode_def
|
|
85 |
by (smt append_Nil2 decode'_code old.prod.case)
|
|
86 |
|
154
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
87 |
|
311
|
88 |
section {* Annotated Regular Expressions *}
|
|
89 |
|
314
|
90 |
datatype arexp =
|
159
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
91 |
AZERO
|
289
|
92 |
| AONE "bit list"
|
|
93 |
| ACHAR "bit list" char
|
|
94 |
| ASEQ "bit list" arexp arexp
|
311
|
95 |
| AALTs "bit list" "arexp list"
|
289
|
96 |
| ASTAR "bit list" arexp
|
159
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
97 |
|
311
|
98 |
abbreviation
|
|
99 |
"AALT bs r1 r2 \<equiv> AALTs bs [r1, r2]"
|
|
100 |
|
317
|
101 |
fun asize :: "arexp \<Rightarrow> nat" where
|
|
102 |
"asize AZERO = 1"
|
|
103 |
| "asize (AONE cs) = 1"
|
|
104 |
| "asize (ACHAR cs c) = 1"
|
|
105 |
| "asize (AALTs cs rs) = Suc (sum_list (map asize rs))"
|
|
106 |
| "asize (ASEQ cs r1 r2) = Suc (asize r1 + asize r2)"
|
|
107 |
| "asize (ASTAR cs r) = Suc (asize r)"
|
|
108 |
|
|
109 |
|
311
|
110 |
|
289
|
111 |
fun fuse :: "bit list \<Rightarrow> arexp \<Rightarrow> arexp" where
|
159
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
112 |
"fuse bs AZERO = AZERO"
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
113 |
| "fuse bs (AONE cs) = AONE (bs @ cs)"
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
114 |
| "fuse bs (ACHAR cs c) = ACHAR (bs @ cs) c"
|
311
|
115 |
| "fuse bs (AALTs cs rs) = AALTs (bs @ cs) rs"
|
159
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
116 |
| "fuse bs (ASEQ cs r1 r2) = ASEQ (bs @ cs) r1 r2"
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
117 |
| "fuse bs (ASTAR cs r) = ASTAR (bs @ cs) r"
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
118 |
|
314
|
119 |
lemma fuse_append:
|
|
120 |
shows "fuse (bs1 @ bs2) r = fuse bs1 (fuse bs2 r)"
|
|
121 |
apply(induct r)
|
|
122 |
apply(auto)
|
|
123 |
done
|
|
124 |
|
|
125 |
|
289
|
126 |
fun intern :: "rexp \<Rightarrow> arexp" where
|
|
127 |
"intern ZERO = AZERO"
|
|
128 |
| "intern ONE = AONE []"
|
|
129 |
| "intern (CHAR c) = ACHAR [] c"
|
|
130 |
| "intern (ALT r1 r2) = AALT [] (fuse [Z] (intern r1))
|
295
|
131 |
(fuse [S] (intern r2))"
|
289
|
132 |
| "intern (SEQ r1 r2) = ASEQ [] (intern r1) (intern r2)"
|
|
133 |
| "intern (STAR r) = ASTAR [] (intern r)"
|
159
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
134 |
|
286
|
135 |
|
289
|
136 |
fun retrieve :: "arexp \<Rightarrow> val \<Rightarrow> bit list" where
|
159
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
137 |
"retrieve (AONE bs) Void = bs"
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
138 |
| "retrieve (ACHAR bs c) (Char d) = bs"
|
313
|
139 |
| "retrieve (AALTs bs [r]) v = bs @ retrieve r v"
|
311
|
140 |
| "retrieve (AALTs bs (r#rs)) (Left v) = bs @ retrieve r v"
|
|
141 |
| "retrieve (AALTs bs (r#rs)) (Right v) = bs @ retrieve (AALTs [] rs) v"
|
159
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
142 |
| "retrieve (ASEQ bs r1 r2) (Seq v1 v2) = bs @ retrieve r1 v1 @ retrieve r2 v2"
|
289
|
143 |
| "retrieve (ASTAR bs r) (Stars []) = bs @ [S]"
|
159
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
144 |
| "retrieve (ASTAR bs r) (Stars (v#vs)) =
|
289
|
145 |
bs @ [Z] @ retrieve r v @ retrieve (ASTAR [] r) (Stars vs)"
|
286
|
146 |
|
|
147 |
fun
|
289
|
148 |
erase :: "arexp \<Rightarrow> rexp"
|
|
149 |
where
|
|
150 |
"erase AZERO = ZERO"
|
|
151 |
| "erase (AONE _) = ONE"
|
|
152 |
| "erase (ACHAR _ c) = CHAR c"
|
311
|
153 |
| "erase (AALTs _ []) = ZERO"
|
|
154 |
| "erase (AALTs _ [r]) = (erase r)"
|
313
|
155 |
| "erase (AALTs bs (r#rs)) = ALT (erase r) (erase (AALTs bs rs))"
|
289
|
156 |
| "erase (ASEQ _ r1 r2) = SEQ (erase r1) (erase r2)"
|
|
157 |
| "erase (ASTAR _ r) = STAR (erase r)"
|
|
158 |
|
|
159 |
fun
|
|
160 |
bnullable :: "arexp \<Rightarrow> bool"
|
286
|
161 |
where
|
289
|
162 |
"bnullable (AZERO) = False"
|
|
163 |
| "bnullable (AONE bs) = True"
|
|
164 |
| "bnullable (ACHAR bs c) = False"
|
311
|
165 |
| "bnullable (AALTs bs rs) = (\<exists>r \<in> set rs. bnullable r)"
|
289
|
166 |
| "bnullable (ASEQ bs r1 r2) = (bnullable r1 \<and> bnullable r2)"
|
|
167 |
| "bnullable (ASTAR bs r) = True"
|
286
|
168 |
|
289
|
169 |
fun
|
|
170 |
bmkeps :: "arexp \<Rightarrow> bit list"
|
|
171 |
where
|
|
172 |
"bmkeps(AONE bs) = bs"
|
|
173 |
| "bmkeps(ASEQ bs r1 r2) = bs @ (bmkeps r1) @ (bmkeps r2)"
|
313
|
174 |
| "bmkeps(AALTs bs [r]) = bs @ (bmkeps r)"
|
311
|
175 |
| "bmkeps(AALTs bs (r#rs)) = (if bnullable(r) then bs @ (bmkeps r) else (bmkeps (AALTs bs rs)))"
|
289
|
176 |
| "bmkeps(ASTAR bs r) = bs @ [S]"
|
286
|
177 |
|
|
178 |
|
159
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
179 |
fun
|
289
|
180 |
bder :: "char \<Rightarrow> arexp \<Rightarrow> arexp"
|
159
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
181 |
where
|
289
|
182 |
"bder c (AZERO) = AZERO"
|
|
183 |
| "bder c (AONE bs) = AZERO"
|
|
184 |
| "bder c (ACHAR bs d) = (if c = d then AONE bs else AZERO)"
|
311
|
185 |
| "bder c (AALTs bs rs) = AALTs bs (map (bder c) rs)"
|
289
|
186 |
| "bder c (ASEQ bs r1 r2) =
|
|
187 |
(if bnullable r1
|
|
188 |
then AALT bs (ASEQ [] (bder c r1) r2) (fuse (bmkeps r1) (bder c r2))
|
|
189 |
else ASEQ bs (bder c r1) r2)"
|
|
190 |
| "bder c (ASTAR bs r) = ASEQ bs (fuse [Z] (bder c r)) (ASTAR [] r)"
|
159
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
191 |
|
286
|
192 |
|
|
193 |
fun
|
289
|
194 |
bders :: "arexp \<Rightarrow> string \<Rightarrow> arexp"
|
286
|
195 |
where
|
289
|
196 |
"bders r [] = r"
|
|
197 |
| "bders r (c#s) = bders (bder c r) s"
|
286
|
198 |
|
289
|
199 |
lemma bders_append:
|
|
200 |
"bders r (s1 @ s2) = bders (bders r s1) s2"
|
287
|
201 |
apply(induct s1 arbitrary: r s2)
|
|
202 |
apply(simp_all)
|
|
203 |
done
|
286
|
204 |
|
289
|
205 |
lemma bnullable_correctness:
|
|
206 |
shows "nullable (erase r) = bnullable r"
|
311
|
207 |
apply(induct r rule: erase.induct)
|
286
|
208 |
apply(simp_all)
|
|
209 |
done
|
|
210 |
|
289
|
211 |
lemma erase_fuse:
|
|
212 |
shows "erase (fuse bs r) = erase r"
|
311
|
213 |
apply(induct r rule: erase.induct)
|
286
|
214 |
apply(simp_all)
|
|
215 |
done
|
|
216 |
|
311
|
217 |
lemma erase_intern [simp]:
|
289
|
218 |
shows "erase (intern r) = r"
|
287
|
219 |
apply(induct r)
|
289
|
220 |
apply(simp_all add: erase_fuse)
|
287
|
221 |
done
|
286
|
222 |
|
311
|
223 |
lemma erase_bder [simp]:
|
289
|
224 |
shows "erase (bder a r) = der a (erase r)"
|
311
|
225 |
apply(induct r rule: erase.induct)
|
289
|
226 |
apply(simp_all add: erase_fuse bnullable_correctness)
|
286
|
227 |
done
|
|
228 |
|
311
|
229 |
lemma erase_bders [simp]:
|
289
|
230 |
shows "erase (bders r s) = ders s (erase r)"
|
286
|
231 |
apply(induct s arbitrary: r )
|
289
|
232 |
apply(simp_all)
|
286
|
233 |
done
|
|
234 |
|
|
235 |
lemma retrieve_encode_STARS:
|
289
|
236 |
assumes "\<forall>v\<in>set vs. \<Turnstile> v : r \<and> code v = retrieve (intern r) v"
|
|
237 |
shows "code (Stars vs) = retrieve (ASTAR [] (intern r)) (Stars vs)"
|
286
|
238 |
using assms
|
|
239 |
apply(induct vs)
|
289
|
240 |
apply(simp_all)
|
|
241 |
done
|
|
242 |
|
|
243 |
lemma retrieve_fuse2:
|
|
244 |
assumes "\<Turnstile> v : (erase r)"
|
|
245 |
shows "retrieve (fuse bs r) v = bs @ retrieve r v"
|
|
246 |
using assms
|
313
|
247 |
apply(induct r arbitrary: v bs)
|
|
248 |
apply(auto elim: Prf_elims)[4]
|
|
249 |
defer
|
|
250 |
using retrieve_encode_STARS
|
|
251 |
apply(auto elim!: Prf_elims)[1]
|
|
252 |
apply(case_tac vs)
|
|
253 |
apply(simp)
|
|
254 |
apply(simp)
|
|
255 |
(* AALTs case *)
|
|
256 |
apply(simp)
|
|
257 |
apply(case_tac x2a)
|
|
258 |
apply(simp)
|
|
259 |
apply(auto elim!: Prf_elims)[1]
|
|
260 |
apply(simp)
|
|
261 |
apply(case_tac list)
|
|
262 |
apply(simp)
|
|
263 |
apply(auto)
|
|
264 |
apply(auto elim!: Prf_elims)[1]
|
|
265 |
done
|
286
|
266 |
|
289
|
267 |
lemma retrieve_fuse:
|
|
268 |
assumes "\<Turnstile> v : r"
|
|
269 |
shows "retrieve (fuse bs (intern r)) v = bs @ retrieve (intern r) v"
|
|
270 |
using assms
|
|
271 |
by (simp_all add: retrieve_fuse2)
|
|
272 |
|
|
273 |
|
|
274 |
lemma retrieve_code:
|
|
275 |
assumes "\<Turnstile> v : r"
|
|
276 |
shows "code v = retrieve (intern r) v"
|
286
|
277 |
using assms
|
311
|
278 |
apply(induct v r )
|
289
|
279 |
apply(simp_all add: retrieve_fuse retrieve_encode_STARS)
|
313
|
280 |
done
|
|
281 |
|
|
282 |
lemma r:
|
|
283 |
assumes "bnullable (AALTs bs (a # rs))"
|
|
284 |
shows "bnullable a \<or> (\<not> bnullable a \<and> bnullable (AALTs bs rs))"
|
|
285 |
using assms
|
|
286 |
apply(induct rs)
|
|
287 |
apply(auto)
|
|
288 |
done
|
|
289 |
|
|
290 |
lemma r0:
|
|
291 |
assumes "bnullable a"
|
|
292 |
shows "bmkeps (AALTs bs (a # rs)) = bs @ (bmkeps a)"
|
|
293 |
using assms
|
|
294 |
by (metis bmkeps.simps(3) bmkeps.simps(4) list.exhaust)
|
|
295 |
|
|
296 |
lemma r1:
|
|
297 |
assumes "\<not> bnullable a" "bnullable (AALTs bs rs)"
|
|
298 |
shows "bmkeps (AALTs bs (a # rs)) = bmkeps (AALTs bs rs)"
|
|
299 |
using assms
|
|
300 |
apply(induct rs)
|
|
301 |
apply(auto)
|
|
302 |
done
|
|
303 |
|
|
304 |
lemma r2:
|
|
305 |
assumes "x \<in> set rs" "bnullable x"
|
|
306 |
shows "bnullable (AALTs bs rs)"
|
|
307 |
using assms
|
|
308 |
apply(induct rs)
|
|
309 |
apply(auto)
|
|
310 |
done
|
286
|
311 |
|
313
|
312 |
lemma r3:
|
|
313 |
assumes "\<not> bnullable r"
|
|
314 |
" \<exists> x \<in> set rs. bnullable x"
|
|
315 |
shows "retrieve (AALTs bs rs) (mkeps (erase (AALTs bs rs))) =
|
|
316 |
retrieve (AALTs bs (r # rs)) (mkeps (erase (AALTs bs (r # rs))))"
|
|
317 |
using assms
|
|
318 |
apply(induct rs arbitrary: r bs)
|
|
319 |
apply(auto)[1]
|
|
320 |
apply(auto)
|
|
321 |
using bnullable_correctness apply blast
|
|
322 |
apply(auto simp add: bnullable_correctness mkeps_nullable retrieve_fuse2)
|
|
323 |
apply(subst retrieve_fuse2[symmetric])
|
|
324 |
apply (smt bnullable.simps(4) bnullable_correctness erase.simps(5) erase.simps(6) insert_iff list.exhaust list.set(2) mkeps.simps(3) mkeps_nullable)
|
|
325 |
apply(simp)
|
|
326 |
apply(case_tac "bnullable a")
|
|
327 |
apply (smt append_Nil2 bnullable.simps(4) bnullable_correctness erase.simps(5) erase.simps(6) fuse.simps(4) insert_iff list.exhaust list.set(2) mkeps.simps(3) mkeps_nullable retrieve_fuse2)
|
|
328 |
apply(drule_tac x="a" in meta_spec)
|
|
329 |
apply(drule_tac x="bs" in meta_spec)
|
|
330 |
apply(drule meta_mp)
|
|
331 |
apply(simp)
|
|
332 |
apply(drule meta_mp)
|
|
333 |
apply(auto)
|
|
334 |
apply(subst retrieve_fuse2[symmetric])
|
|
335 |
apply(case_tac rs)
|
|
336 |
apply(simp)
|
|
337 |
apply(auto)[1]
|
|
338 |
apply (simp add: bnullable_correctness)
|
|
339 |
apply (metis append_Nil2 bnullable_correctness erase_fuse fuse.simps(4) list.set_intros(1) mkeps.simps(3) mkeps_nullable nullable.simps(4) r2)
|
|
340 |
apply (simp add: bnullable_correctness)
|
|
341 |
apply (metis append_Nil2 bnullable_correctness erase.simps(6) erase_fuse fuse.simps(4) list.set_intros(2) mkeps.simps(3) mkeps_nullable r2)
|
|
342 |
apply(simp)
|
|
343 |
done
|
|
344 |
|
|
345 |
|
|
346 |
lemma t:
|
|
347 |
assumes "\<forall>r \<in> set rs. nullable (erase r) \<longrightarrow> bmkeps r = retrieve r (mkeps (erase r))"
|
|
348 |
"nullable (erase (AALTs bs rs))"
|
|
349 |
shows " bmkeps (AALTs bs rs) = retrieve (AALTs bs rs) (mkeps (erase (AALTs bs rs)))"
|
|
350 |
using assms
|
|
351 |
apply(induct rs arbitrary: bs)
|
|
352 |
apply(simp)
|
|
353 |
apply(auto simp add: bnullable_correctness)
|
|
354 |
apply(case_tac rs)
|
|
355 |
apply(auto simp add: bnullable_correctness)[2]
|
|
356 |
apply(subst r1)
|
|
357 |
apply(simp)
|
|
358 |
apply(rule r2)
|
|
359 |
apply(assumption)
|
|
360 |
apply(simp)
|
|
361 |
apply(drule_tac x="bs" in meta_spec)
|
|
362 |
apply(drule meta_mp)
|
|
363 |
apply(auto)[1]
|
|
364 |
prefer 2
|
|
365 |
apply(case_tac "bnullable a")
|
|
366 |
apply(subst r0)
|
|
367 |
apply blast
|
|
368 |
apply(subgoal_tac "nullable (erase a)")
|
|
369 |
prefer 2
|
|
370 |
using bnullable_correctness apply blast
|
|
371 |
apply (metis (no_types, lifting) erase.simps(5) erase.simps(6) list.exhaust mkeps.simps(3) retrieve.simps(3) retrieve.simps(4))
|
|
372 |
apply(subst r1)
|
|
373 |
apply(simp)
|
|
374 |
using r2 apply blast
|
|
375 |
apply(drule_tac x="bs" in meta_spec)
|
|
376 |
apply(drule meta_mp)
|
|
377 |
apply(auto)[1]
|
|
378 |
apply(simp)
|
|
379 |
using r3 apply blast
|
|
380 |
apply(auto)
|
|
381 |
using r3 by blast
|
286
|
382 |
|
289
|
383 |
lemma bmkeps_retrieve:
|
|
384 |
assumes "nullable (erase r)"
|
|
385 |
shows "bmkeps r = retrieve r (mkeps (erase r))"
|
286
|
386 |
using assms
|
|
387 |
apply(induct r)
|
313
|
388 |
apply(simp)
|
|
389 |
apply(simp)
|
|
390 |
apply(simp)
|
|
391 |
apply(simp)
|
|
392 |
defer
|
|
393 |
apply(simp)
|
|
394 |
apply(rule t)
|
|
395 |
apply(auto)
|
|
396 |
done
|
|
397 |
|
289
|
398 |
lemma bder_retrieve:
|
|
399 |
assumes "\<Turnstile> v : der c (erase r)"
|
|
400 |
shows "retrieve (bder c r) v = retrieve r (injval (erase r) c v)"
|
286
|
401 |
using assms
|
313
|
402 |
apply(induct r arbitrary: v rule: erase.induct)
|
289
|
403 |
apply(auto elim!: Prf_elims simp add: retrieve_fuse2 bnullable_correctness bmkeps_retrieve)
|
313
|
404 |
apply(case_tac va)
|
|
405 |
apply(simp)
|
|
406 |
apply(auto)
|
|
407 |
by (smt Prf_elims(3) injval.simps(2) injval.simps(3) retrieve.simps(4) retrieve.simps(5) same_append_eq)
|
|
408 |
|
286
|
409 |
|
289
|
410 |
lemma MAIN_decode:
|
|
411 |
assumes "\<Turnstile> v : ders s r"
|
|
412 |
shows "Some (flex r id s v) = decode (retrieve (bders (intern r) s) v) r"
|
|
413 |
using assms
|
|
414 |
proof (induct s arbitrary: v rule: rev_induct)
|
|
415 |
case Nil
|
|
416 |
have "\<Turnstile> v : ders [] r" by fact
|
|
417 |
then have "\<Turnstile> v : r" by simp
|
|
418 |
then have "Some v = decode (retrieve (intern r) v) r"
|
|
419 |
using decode_code retrieve_code by auto
|
|
420 |
then show "Some (flex r id [] v) = decode (retrieve (bders (intern r) []) v) r"
|
|
421 |
by simp
|
|
422 |
next
|
|
423 |
case (snoc c s v)
|
|
424 |
have IH: "\<And>v. \<Turnstile> v : ders s r \<Longrightarrow>
|
|
425 |
Some (flex r id s v) = decode (retrieve (bders (intern r) s) v) r" by fact
|
|
426 |
have asm: "\<Turnstile> v : ders (s @ [c]) r" by fact
|
|
427 |
then have asm2: "\<Turnstile> injval (ders s r) c v : ders s r"
|
|
428 |
by(simp add: Prf_injval ders_append)
|
|
429 |
have "Some (flex r id (s @ [c]) v) = Some (flex r id s (injval (ders s r) c v))"
|
|
430 |
by (simp add: flex_append)
|
|
431 |
also have "... = decode (retrieve (bders (intern r) s) (injval (ders s r) c v)) r"
|
|
432 |
using asm2 IH by simp
|
|
433 |
also have "... = decode (retrieve (bder c (bders (intern r) s)) v) r"
|
|
434 |
using asm by(simp_all add: bder_retrieve ders_append)
|
|
435 |
finally show "Some (flex r id (s @ [c]) v) =
|
|
436 |
decode (retrieve (bders (intern r) (s @ [c])) v) r" by (simp add: bders_append)
|
|
437 |
qed
|
286
|
438 |
|
|
439 |
|
289
|
440 |
definition blexer where
|
|
441 |
"blexer r s \<equiv> if bnullable (bders (intern r) s) then
|
|
442 |
decode (bmkeps (bders (intern r) s)) r else None"
|
|
443 |
|
|
444 |
lemma blexer_correctness:
|
|
445 |
shows "blexer r s = lexer r s"
|
|
446 |
proof -
|
|
447 |
{ define bds where "bds \<equiv> bders (intern r) s"
|
|
448 |
define ds where "ds \<equiv> ders s r"
|
|
449 |
assume asm: "nullable ds"
|
|
450 |
have era: "erase bds = ds"
|
|
451 |
unfolding ds_def bds_def by simp
|
|
452 |
have mke: "\<Turnstile> mkeps ds : ds"
|
|
453 |
using asm by (simp add: mkeps_nullable)
|
|
454 |
have "decode (bmkeps bds) r = decode (retrieve bds (mkeps ds)) r"
|
|
455 |
using bmkeps_retrieve
|
|
456 |
using asm era by (simp add: bmkeps_retrieve)
|
|
457 |
also have "... = Some (flex r id s (mkeps ds))"
|
|
458 |
using mke by (simp_all add: MAIN_decode ds_def bds_def)
|
|
459 |
finally have "decode (bmkeps bds) r = Some (flex r id s (mkeps ds))"
|
|
460 |
unfolding bds_def ds_def .
|
|
461 |
}
|
|
462 |
then show "blexer r s = lexer r s"
|
|
463 |
unfolding blexer_def lexer_flex
|
293
|
464 |
apply(subst bnullable_correctness[symmetric])
|
|
465 |
apply(simp)
|
|
466 |
done
|
289
|
467 |
qed
|
286
|
468 |
|
295
|
469 |
|
314
|
470 |
fun distinctBy :: "'a list \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'b set \<Rightarrow> 'a list"
|
|
471 |
where
|
|
472 |
"distinctBy [] f acc = []"
|
|
473 |
| "distinctBy (x#xs) f acc =
|
|
474 |
(if (f x) \<in> acc then distinctBy xs f acc
|
|
475 |
else x # (distinctBy xs f ({f x} \<union> acc)))"
|
|
476 |
|
|
477 |
fun flts :: "arexp list \<Rightarrow> arexp list"
|
|
478 |
where
|
|
479 |
"flts [] = []"
|
|
480 |
| "flts (AZERO # rs) = flts rs"
|
|
481 |
| "flts ((AALTs bs rs1) # rs) = (map (fuse bs) rs1) @ flts rs"
|
|
482 |
| "flts (r1 # rs) = r1 # flts rs"
|
|
483 |
|
|
484 |
fun bsimp_ASEQ :: "bit list \<Rightarrow> arexp \<Rightarrow> arexp \<Rightarrow> arexp"
|
|
485 |
where
|
|
486 |
"bsimp_ASEQ _ AZERO _ = AZERO"
|
|
487 |
| "bsimp_ASEQ _ _ AZERO = AZERO"
|
|
488 |
| "bsimp_ASEQ bs1 (AONE bs2) r2 = fuse (bs1 @ bs2) r2"
|
|
489 |
| "bsimp_ASEQ bs1 r1 r2 = ASEQ bs1 r1 r2"
|
|
490 |
|
|
491 |
|
|
492 |
fun bsimp_AALTs :: "bit list \<Rightarrow> arexp list \<Rightarrow> arexp"
|
|
493 |
where
|
|
494 |
"bsimp_AALTs _ [] = AZERO"
|
|
495 |
| "bsimp_AALTs bs1 [r] = fuse bs1 r"
|
|
496 |
| "bsimp_AALTs bs1 rs = AALTs bs1 rs"
|
|
497 |
|
|
498 |
|
|
499 |
fun bsimp :: "arexp \<Rightarrow> arexp"
|
|
500 |
where
|
|
501 |
"bsimp (ASEQ bs1 r1 r2) = bsimp_ASEQ bs1 (bsimp r1) (bsimp r2)"
|
|
502 |
| "bsimp (AALTs bs1 rs) = bsimp_AALTs bs1 (flts (map bsimp rs))"
|
|
503 |
| "bsimp r = r"
|
|
504 |
|
|
505 |
fun
|
|
506 |
bders_simp :: "arexp \<Rightarrow> string \<Rightarrow> arexp"
|
|
507 |
where
|
|
508 |
"bders_simp r [] = r"
|
|
509 |
| "bders_simp r (c # s) = bders_simp (bsimp (bder c r)) s"
|
|
510 |
|
|
511 |
definition blexer_simp where
|
|
512 |
"blexer_simp r s \<equiv> if bnullable (bders_simp (intern r) s) then
|
|
513 |
decode (bmkeps (bders_simp (intern r) s)) r else None"
|
|
514 |
|
|
515 |
|
317
|
516 |
lemma asize0:
|
|
517 |
shows "0 < asize r"
|
|
518 |
apply(induct r)
|
|
519 |
apply(auto)
|
|
520 |
done
|
|
521 |
|
|
522 |
|
314
|
523 |
lemma bders_simp_append:
|
|
524 |
shows "bders_simp r (s1 @ s2) = bders_simp (bders_simp r s1) s2"
|
|
525 |
apply(induct s1 arbitrary: r s2)
|
|
526 |
apply(simp)
|
|
527 |
apply(simp)
|
|
528 |
done
|
|
529 |
|
317
|
530 |
lemma bsimp_ASEQ_size:
|
|
531 |
shows "asize (bsimp_ASEQ bs r1 r2) \<le> Suc (asize r1 + asize r2)"
|
|
532 |
apply(induct bs r1 r2 rule: bsimp_ASEQ.induct)
|
|
533 |
apply(auto)
|
|
534 |
done
|
314
|
535 |
|
317
|
536 |
lemma fuse_size:
|
|
537 |
shows "asize (fuse bs r) = asize r"
|
|
538 |
apply(induct r)
|
|
539 |
apply(auto)
|
|
540 |
done
|
|
541 |
|
|
542 |
lemma flts_size:
|
|
543 |
shows "sum_list (map asize (flts rs)) \<le> sum_list (map asize rs)"
|
|
544 |
apply(induct rs rule: flts.induct)
|
|
545 |
apply(simp_all)
|
|
546 |
by (metis (mono_tags, lifting) add_mono_thms_linordered_semiring(1) comp_apply fuse_size le_SucI order_refl sum_list_cong)
|
|
547 |
|
|
548 |
|
|
549 |
lemma bsimp_AALTs_size:
|
|
550 |
shows "asize (bsimp_AALTs bs rs) \<le> Suc (sum_list (map asize rs))"
|
|
551 |
apply(induct rs rule: bsimp_AALTs.induct)
|
|
552 |
apply(auto simp add: fuse_size)
|
|
553 |
done
|
|
554 |
|
|
555 |
lemma bsimp_size:
|
|
556 |
shows "asize (bsimp r) \<le> asize r"
|
|
557 |
apply(induct r)
|
|
558 |
apply(simp_all)
|
|
559 |
apply (meson Suc_le_mono add_mono_thms_linordered_semiring(1) bsimp_ASEQ_size le_trans)
|
|
560 |
apply(rule le_trans)
|
|
561 |
apply(rule bsimp_AALTs_size)
|
|
562 |
apply(simp)
|
|
563 |
apply(rule le_trans)
|
|
564 |
apply(rule flts_size)
|
|
565 |
by (simp add: sum_list_mono)
|
|
566 |
|
|
567 |
fun nonalt :: "arexp \<Rightarrow> bool"
|
|
568 |
where
|
|
569 |
"nonalt (AALTs bs2 rs) = False"
|
|
570 |
| "nonalt r = True"
|
|
571 |
|
|
572 |
|
|
573 |
|
|
574 |
|
|
575 |
lemma bsimp_AALTs_size2:
|
|
576 |
assumes "\<forall>r \<in> set rs. nonalt r"
|
|
577 |
shows "asize (bsimp_AALTs bs rs) \<ge> sum_list (map asize rs)"
|
|
578 |
using assms
|
|
579 |
apply(induct rs rule: bsimp_AALTs.induct)
|
|
580 |
apply(simp_all add: fuse_size)
|
|
581 |
done
|
|
582 |
|
|
583 |
lemma qq:
|
|
584 |
shows "map (asize \<circ> fuse bs) rs = map asize rs"
|
|
585 |
apply(induct rs)
|
|
586 |
apply(auto simp add: fuse_size)
|
|
587 |
done
|
|
588 |
|
|
589 |
lemma flts_size2:
|
|
590 |
assumes "\<exists>bs rs'. AALTs bs rs' \<in> set rs"
|
|
591 |
shows "sum_list (map asize (flts rs)) < sum_list (map asize rs)"
|
|
592 |
using assms
|
|
593 |
apply(induct rs)
|
|
594 |
apply(auto simp add: qq)
|
|
595 |
apply (simp add: flts_size less_Suc_eq_le)
|
|
596 |
apply(case_tac a)
|
|
597 |
apply(auto simp add: qq)
|
|
598 |
prefer 2
|
|
599 |
apply (simp add: flts_size le_imp_less_Suc)
|
|
600 |
using less_Suc_eq by auto
|
|
601 |
|
314
|
602 |
lemma L_bsimp_ASEQ:
|
|
603 |
"L (SEQ (erase r1) (erase r2)) = L (erase (bsimp_ASEQ bs r1 r2))"
|
|
604 |
apply(induct bs r1 r2 rule: bsimp_ASEQ.induct)
|
|
605 |
apply(simp_all)
|
|
606 |
by (metis erase_fuse fuse.simps(4))
|
|
607 |
|
|
608 |
lemma L_bsimp_AALTs:
|
|
609 |
"L (erase (AALTs bs rs)) = L (erase (bsimp_AALTs bs rs))"
|
|
610 |
apply(induct bs rs rule: bsimp_AALTs.induct)
|
|
611 |
apply(simp_all add: erase_fuse)
|
|
612 |
done
|
|
613 |
|
|
614 |
lemma L_erase_AALTs:
|
|
615 |
shows "L (erase (AALTs bs rs)) = \<Union> (L ` erase ` (set rs))"
|
|
616 |
apply(induct rs)
|
|
617 |
apply(simp)
|
|
618 |
apply(simp)
|
|
619 |
apply(case_tac rs)
|
|
620 |
apply(simp)
|
|
621 |
apply(simp)
|
|
622 |
done
|
|
623 |
|
|
624 |
lemma L_erase_flts:
|
|
625 |
shows "\<Union> (L ` erase ` (set (flts rs))) = \<Union> (L ` erase ` (set rs))"
|
|
626 |
apply(induct rs rule: flts.induct)
|
|
627 |
apply(simp_all)
|
|
628 |
apply(auto)
|
|
629 |
using L_erase_AALTs erase_fuse apply auto[1]
|
|
630 |
by (simp add: L_erase_AALTs erase_fuse)
|
|
631 |
|
|
632 |
|
|
633 |
lemma L_bsimp_erase:
|
|
634 |
shows "L (erase r) = L (erase (bsimp r))"
|
|
635 |
apply(induct r)
|
|
636 |
apply(simp)
|
|
637 |
apply(simp)
|
|
638 |
apply(simp)
|
|
639 |
apply(auto simp add: Sequ_def)[1]
|
|
640 |
apply(subst L_bsimp_ASEQ[symmetric])
|
|
641 |
apply(auto simp add: Sequ_def)[1]
|
|
642 |
apply(subst (asm) L_bsimp_ASEQ[symmetric])
|
|
643 |
apply(auto simp add: Sequ_def)[1]
|
|
644 |
apply(simp)
|
|
645 |
apply(subst L_bsimp_AALTs[symmetric])
|
|
646 |
defer
|
|
647 |
apply(simp)
|
|
648 |
apply(subst (2)L_erase_AALTs)
|
|
649 |
apply(subst L_erase_flts)
|
|
650 |
apply(auto)
|
|
651 |
apply (simp add: L_erase_AALTs)
|
|
652 |
using L_erase_AALTs by blast
|
|
653 |
|
317
|
654 |
lemma bsimp_ASEQ0:
|
|
655 |
shows "bsimp_ASEQ bs r1 AZERO = AZERO"
|
|
656 |
apply(induct r1)
|
|
657 |
apply(auto)
|
|
658 |
done
|
|
659 |
|
|
660 |
|
314
|
661 |
|
|
662 |
lemma bsimp_ASEQ1:
|
|
663 |
assumes "r1 \<noteq> AZERO" "r2 \<noteq> AZERO" "\<forall>bs. r1 \<noteq> AONE bs"
|
|
664 |
shows "bsimp_ASEQ bs r1 r2 = ASEQ bs r1 r2"
|
|
665 |
using assms
|
|
666 |
apply(induct bs r1 r2 rule: bsimp_ASEQ.induct)
|
|
667 |
apply(auto)
|
|
668 |
done
|
|
669 |
|
|
670 |
lemma bsimp_ASEQ2:
|
|
671 |
shows "bsimp_ASEQ bs (AONE bs1) r2 = fuse (bs @ bs1) r2"
|
|
672 |
apply(induct r2)
|
|
673 |
apply(auto)
|
|
674 |
done
|
|
675 |
|
|
676 |
|
|
677 |
lemma L_bders_simp:
|
|
678 |
shows "L (erase (bders_simp r s)) = L (erase (bders r s))"
|
|
679 |
apply(induct s arbitrary: r rule: rev_induct)
|
|
680 |
apply(simp)
|
|
681 |
apply(simp)
|
|
682 |
apply(simp add: ders_append)
|
|
683 |
apply(simp add: bders_simp_append)
|
|
684 |
apply(simp add: L_bsimp_erase[symmetric])
|
|
685 |
by (simp add: der_correctness)
|
|
686 |
|
|
687 |
lemma b1:
|
|
688 |
"bsimp_ASEQ bs1 (AONE bs) r = fuse (bs1 @ bs) r"
|
|
689 |
apply(induct r)
|
|
690 |
apply(auto)
|
|
691 |
done
|
|
692 |
|
|
693 |
lemma b2:
|
|
694 |
assumes "bnullable r"
|
|
695 |
shows "bmkeps (fuse bs r) = bs @ bmkeps r"
|
|
696 |
by (simp add: assms bmkeps_retrieve bnullable_correctness erase_fuse mkeps_nullable retrieve_fuse2)
|
|
697 |
|
|
698 |
lemma b3:
|
|
699 |
shows "bnullable r = bnullable (bsimp r)"
|
|
700 |
using L_bsimp_erase bnullable_correctness nullable_correctness by auto
|
|
701 |
|
|
702 |
|
|
703 |
lemma b4:
|
|
704 |
shows "bnullable (bders_simp r s) = bnullable (bders r s)"
|
|
705 |
by (metis L_bders_simp bnullable_correctness lexer.simps(1) lexer_correct_None option.distinct(1))
|
|
706 |
|
|
707 |
lemma q1:
|
|
708 |
assumes "\<forall>r \<in> set rs. bmkeps(bsimp r) = bmkeps r"
|
|
709 |
shows "map (\<lambda>r. bmkeps(bsimp r)) rs = map bmkeps rs"
|
|
710 |
using assms
|
|
711 |
apply(induct rs)
|
|
712 |
apply(simp)
|
|
713 |
apply(simp)
|
|
714 |
done
|
|
715 |
|
|
716 |
lemma q3:
|
|
717 |
assumes "\<exists>r \<in> set rs. bnullable r"
|
|
718 |
shows "bmkeps (AALTs bs rs) = bmkeps (bsimp_AALTs bs rs)"
|
|
719 |
using assms
|
|
720 |
apply(induct bs rs rule: bsimp_AALTs.induct)
|
|
721 |
apply(simp)
|
|
722 |
apply(simp)
|
|
723 |
apply (simp add: b2)
|
|
724 |
apply(simp)
|
|
725 |
done
|
|
726 |
|
|
727 |
lemma qq1:
|
|
728 |
assumes "\<exists>r \<in> set rs. bnullable r"
|
|
729 |
shows "bmkeps (AALTs bs (rs @ rs1)) = bmkeps (AALTs bs rs)"
|
|
730 |
using assms
|
|
731 |
apply(induct rs arbitrary: rs1 bs)
|
|
732 |
apply(simp)
|
|
733 |
apply(simp)
|
|
734 |
by (metis Nil_is_append_conv bmkeps.simps(4) neq_Nil_conv r0 split_list_last)
|
|
735 |
|
|
736 |
lemma qq2:
|
|
737 |
assumes "\<forall>r \<in> set rs. \<not> bnullable r" "\<exists>r \<in> set rs1. bnullable r"
|
|
738 |
shows "bmkeps (AALTs bs (rs @ rs1)) = bmkeps (AALTs bs rs1)"
|
|
739 |
using assms
|
|
740 |
apply(induct rs arbitrary: rs1 bs)
|
|
741 |
apply(simp)
|
|
742 |
apply(simp)
|
|
743 |
by (metis append_assoc in_set_conv_decomp r1 r2)
|
|
744 |
|
|
745 |
lemma qq3:
|
|
746 |
shows "bnullable (AALTs bs rs) = (\<exists>r \<in> set rs. bnullable r)"
|
|
747 |
apply(induct rs arbitrary: bs)
|
|
748 |
apply(simp)
|
|
749 |
apply(simp)
|
|
750 |
done
|
|
751 |
|
317
|
752 |
lemma fuse_empty:
|
|
753 |
shows "fuse [] r = r"
|
|
754 |
apply(induct r)
|
|
755 |
apply(auto)
|
|
756 |
done
|
|
757 |
|
|
758 |
lemma flts_fuse:
|
|
759 |
shows "map (fuse bs) (flts rs) = flts (map (fuse bs) rs)"
|
|
760 |
apply(induct rs arbitrary: bs rule: flts.induct)
|
|
761 |
apply(auto simp add: fuse_append)
|
|
762 |
done
|
|
763 |
|
|
764 |
lemma bsimp_ASEQ_fuse:
|
|
765 |
shows "fuse bs1 (bsimp_ASEQ bs2 r1 r2) = bsimp_ASEQ (bs1 @ bs2) r1 r2"
|
|
766 |
apply(induct r1 r2 arbitrary: bs1 bs2 rule: bsimp_ASEQ.induct)
|
|
767 |
apply(auto)
|
|
768 |
done
|
|
769 |
|
|
770 |
lemma bsimp_AALTs_fuse:
|
|
771 |
assumes "\<forall>r \<in> set rs. fuse bs1 (fuse bs2 r) = fuse (bs1 @ bs2) r"
|
|
772 |
shows "fuse bs1 (bsimp_AALTs bs2 rs) = bsimp_AALTs (bs1 @ bs2) rs"
|
|
773 |
using assms
|
|
774 |
apply(induct bs2 rs arbitrary: bs1 rule: bsimp_AALTs.induct)
|
|
775 |
apply(auto)
|
|
776 |
done
|
|
777 |
|
|
778 |
|
|
779 |
|
|
780 |
lemma bsimp_fuse:
|
|
781 |
shows "fuse bs (bsimp r) = bsimp (fuse bs r)"
|
|
782 |
apply(induct r arbitrary: bs)
|
|
783 |
apply(simp)
|
|
784 |
apply(simp)
|
|
785 |
apply(simp)
|
|
786 |
prefer 3
|
|
787 |
apply(simp)
|
|
788 |
apply(simp)
|
|
789 |
apply (simp add: bsimp_ASEQ_fuse)
|
|
790 |
apply(simp)
|
|
791 |
by (simp add: bsimp_AALTs_fuse fuse_append)
|
|
792 |
|
|
793 |
lemma bsimp_fuse_AALTs:
|
|
794 |
shows "fuse bs (bsimp (AALTs [] rs)) = bsimp (AALTs bs rs)"
|
|
795 |
apply(subst bsimp_fuse)
|
|
796 |
apply(simp)
|
|
797 |
done
|
|
798 |
|
|
799 |
lemma bsimp_fuse_AALTs2:
|
|
800 |
shows "fuse bs (bsimp_AALTs [] rs) = bsimp_AALTs bs rs"
|
|
801 |
using bsimp_AALTs_fuse fuse_append by auto
|
|
802 |
|
|
803 |
|
|
804 |
lemma bsimp_ASEQ_idem:
|
|
805 |
assumes "bsimp (bsimp r1) = bsimp r1" "bsimp (bsimp r2) = bsimp r2"
|
|
806 |
shows "bsimp (bsimp_ASEQ x1 (bsimp r1) (bsimp r2)) = bsimp_ASEQ x1 (bsimp r1) (bsimp r2)"
|
|
807 |
using assms
|
|
808 |
apply(case_tac "bsimp r1 = AZERO")
|
|
809 |
apply(simp)
|
|
810 |
apply(case_tac "bsimp r2 = AZERO")
|
|
811 |
apply(simp)
|
|
812 |
apply (metis bnullable.elims(2) bnullable.elims(3) bsimp.simps(3) bsimp_ASEQ.simps(2) bsimp_ASEQ.simps(3) bsimp_ASEQ.simps(4) bsimp_ASEQ.simps(5) bsimp_ASEQ.simps(6))
|
|
813 |
apply(case_tac "\<exists>bs. bsimp r1 = AONE bs")
|
|
814 |
apply(auto)[1]
|
|
815 |
apply(subst bsimp_ASEQ2)
|
|
816 |
apply(subst bsimp_ASEQ2)
|
|
817 |
apply (metis assms(2) bsimp_fuse)
|
|
818 |
apply(subst bsimp_ASEQ1)
|
|
819 |
apply(auto)
|
|
820 |
done
|
|
821 |
|
|
822 |
|
|
823 |
fun nonnested :: "arexp \<Rightarrow> bool"
|
|
824 |
where
|
|
825 |
"nonnested (AALTs bs2 []) = True"
|
|
826 |
| "nonnested (AALTs bs2 ((AALTs bs1 rs1) # rs2)) = False"
|
|
827 |
| "nonnested (AALTs bs2 (r # rs2)) = nonnested (AALTs bs2 rs2)"
|
|
828 |
| "nonnested r = True"
|
|
829 |
|
|
830 |
|
|
831 |
lemma k0:
|
|
832 |
shows "flts (r # rs1) = flts [r] @ flts rs1"
|
|
833 |
apply(induct r arbitrary: rs1)
|
|
834 |
apply(auto)
|
|
835 |
done
|
|
836 |
|
|
837 |
lemma k00:
|
|
838 |
shows "flts (rs1 @ rs2) = flts rs1 @ flts rs2"
|
|
839 |
apply(induct rs1 arbitrary: rs2)
|
|
840 |
apply(auto)
|
|
841 |
by (metis append.assoc k0)
|
|
842 |
|
|
843 |
lemma k0a:
|
|
844 |
shows "flts [AALTs bs rs] = map (fuse bs) rs"
|
|
845 |
apply(simp)
|
|
846 |
done
|
|
847 |
|
|
848 |
fun spill where
|
|
849 |
"spill (AALTs bs rs) = map (fuse bs) rs"
|
|
850 |
|
|
851 |
lemma k0a2:
|
|
852 |
assumes "\<not> nonalt r"
|
|
853 |
shows "flts [r] = spill r"
|
|
854 |
using assms
|
|
855 |
apply(case_tac r)
|
|
856 |
apply(simp_all)
|
|
857 |
done
|
|
858 |
|
|
859 |
lemma k0b:
|
|
860 |
assumes "nonalt r" "r \<noteq> AZERO"
|
|
861 |
shows "flts [r] = [r]"
|
|
862 |
using assms
|
|
863 |
apply(case_tac r)
|
|
864 |
apply(simp_all)
|
|
865 |
done
|
|
866 |
|
|
867 |
lemma nn1:
|
|
868 |
assumes "nonnested (AALTs bs rs)"
|
|
869 |
shows "\<nexists>bs1 rs1. flts rs = [AALTs bs1 rs1]"
|
|
870 |
using assms
|
|
871 |
apply(induct rs rule: flts.induct)
|
|
872 |
apply(auto)
|
|
873 |
done
|
|
874 |
|
|
875 |
lemma nn1q:
|
|
876 |
assumes "nonnested (AALTs bs rs)"
|
|
877 |
shows "\<nexists>bs1 rs1. AALTs bs1 rs1 \<in> set (flts rs)"
|
|
878 |
using assms
|
|
879 |
apply(induct rs rule: flts.induct)
|
|
880 |
apply(auto)
|
|
881 |
done
|
|
882 |
|
|
883 |
lemma nn1qq:
|
|
884 |
assumes "nonnested (AALTs bs rs)"
|
|
885 |
shows "\<nexists>bs1 rs1. AALTs bs1 rs1 \<in> set rs"
|
|
886 |
using assms
|
|
887 |
apply(induct rs rule: flts.induct)
|
|
888 |
apply(auto)
|
|
889 |
done
|
|
890 |
|
|
891 |
lemma nn10:
|
|
892 |
assumes "nonnested (AALTs cs rs)"
|
|
893 |
shows "nonnested (AALTs (bs @ cs) rs)"
|
|
894 |
using assms
|
|
895 |
apply(induct rs arbitrary: cs bs)
|
|
896 |
apply(simp_all)
|
|
897 |
apply(case_tac a)
|
|
898 |
apply(simp_all)
|
|
899 |
done
|
|
900 |
|
|
901 |
lemma nn11a:
|
|
902 |
assumes "nonalt r"
|
|
903 |
shows "nonalt (fuse bs r)"
|
|
904 |
using assms
|
|
905 |
apply(induct r)
|
|
906 |
apply(auto)
|
|
907 |
done
|
|
908 |
|
|
909 |
|
|
910 |
lemma nn1a:
|
|
911 |
assumes "nonnested r"
|
|
912 |
shows "nonnested (fuse bs r)"
|
|
913 |
using assms
|
|
914 |
apply(induct bs r arbitrary: rule: fuse.induct)
|
|
915 |
apply(simp_all add: nn10)
|
|
916 |
done
|
|
917 |
|
|
918 |
lemma n0:
|
|
919 |
shows "nonnested (AALTs bs rs) \<longleftrightarrow> (\<forall>r \<in> set rs. nonalt r)"
|
|
920 |
apply(induct rs arbitrary: bs)
|
|
921 |
apply(auto)
|
|
922 |
apply (metis list.set_intros(1) nn1qq nonalt.elims(3))
|
|
923 |
apply (metis list.set_intros(2) nn1qq nonalt.elims(3))
|
|
924 |
by (metis nonalt.elims(2) nonnested.simps(3) nonnested.simps(4) nonnested.simps(5) nonnested.simps(6) nonnested.simps(7))
|
|
925 |
|
|
926 |
|
|
927 |
|
|
928 |
|
|
929 |
lemma nn1c:
|
|
930 |
assumes "\<forall>r \<in> set rs. nonnested r"
|
|
931 |
shows "\<forall>r \<in> set (flts rs). nonalt r"
|
|
932 |
using assms
|
|
933 |
apply(induct rs rule: flts.induct)
|
|
934 |
apply(auto)
|
|
935 |
apply(rule nn11a)
|
|
936 |
by (metis nn1qq nonalt.elims(3))
|
|
937 |
|
|
938 |
lemma nn1bb:
|
|
939 |
assumes "\<forall>r \<in> set rs. nonalt r"
|
|
940 |
shows "nonnested (bsimp_AALTs bs rs)"
|
|
941 |
using assms
|
|
942 |
apply(induct bs rs rule: bsimp_AALTs.induct)
|
|
943 |
apply(auto)
|
|
944 |
apply (metis nn11a nonalt.simps(1) nonnested.elims(3))
|
|
945 |
using n0 by auto
|
|
946 |
|
|
947 |
lemma nn1b:
|
|
948 |
shows "nonnested (bsimp r)"
|
|
949 |
apply(induct r)
|
|
950 |
apply(simp_all)
|
|
951 |
apply(case_tac "bsimp r1 = AZERO")
|
|
952 |
apply(simp)
|
|
953 |
apply(case_tac "bsimp r2 = AZERO")
|
|
954 |
apply(simp)
|
|
955 |
apply(subst bsimp_ASEQ0)
|
|
956 |
apply(simp)
|
|
957 |
apply(case_tac "\<exists>bs. bsimp r1 = AONE bs")
|
|
958 |
apply(auto)[1]
|
|
959 |
apply(subst bsimp_ASEQ2)
|
|
960 |
apply (simp add: nn1a)
|
|
961 |
apply(subst bsimp_ASEQ1)
|
|
962 |
apply(auto)
|
|
963 |
apply(rule nn1bb)
|
|
964 |
apply(auto)
|
|
965 |
by (metis (mono_tags, hide_lams) imageE nn1c set_map)
|
|
966 |
|
|
967 |
lemma rt:
|
|
968 |
shows "sum_list (map asize (flts (map bsimp rs))) \<le> sum_list (map asize rs)"
|
|
969 |
apply(induct rs)
|
|
970 |
apply(simp)
|
|
971 |
apply(simp)
|
|
972 |
apply(subst k0)
|
|
973 |
apply(simp)
|
|
974 |
by (smt add_le_cancel_right add_mono bsimp_size flts.simps(1) flts_size k0 le_iff_add list.simps(9) map_append sum_list.Cons sum_list.append trans_le_add1)
|
|
975 |
|
|
976 |
lemma flts_idem:
|
|
977 |
assumes "\<forall>r \<in> set rs. bsimp (bsimp r) = bsimp r"
|
|
978 |
shows "flts (map bsimp (flts (map bsimp rs))) = flts (map bsimp rs)"
|
|
979 |
using assms
|
|
980 |
apply(induct rs)
|
|
981 |
apply(simp)
|
|
982 |
apply(simp)
|
|
983 |
apply(subst k0)
|
|
984 |
apply(subst (2) k0)
|
|
985 |
apply(case_tac "bsimp a = AZERO")
|
|
986 |
apply(simp)
|
|
987 |
apply(case_tac "nonalt (bsimp a)")
|
|
988 |
thm k0 k0a k0b
|
|
989 |
apply(subst k0b)
|
|
990 |
apply(simp)
|
|
991 |
apply(simp)
|
|
992 |
apply(simp)
|
|
993 |
apply(subst k0b)
|
|
994 |
apply(simp)
|
|
995 |
apply(simp)
|
|
996 |
apply(simp)
|
|
997 |
apply(subst k0)
|
|
998 |
apply(subst k0b)
|
|
999 |
apply(simp)
|
|
1000 |
apply(simp)
|
|
1001 |
apply(simp)
|
|
1002 |
apply(simp)
|
|
1003 |
apply(simp add: k00)
|
|
1004 |
apply(subst k0a2)
|
|
1005 |
apply(simp)
|
|
1006 |
apply(subst k0a2)
|
|
1007 |
apply(simp)
|
|
1008 |
apply(case_tac a)
|
|
1009 |
apply(simp_all)
|
|
1010 |
sorry
|
|
1011 |
|
|
1012 |
lemma bsimp_AALTs_idem:
|
|
1013 |
(*assumes "\<forall>r \<in> set rs. bsimp (bsimp r) = bsimp r \<and> nonalt (bsimp r)" *)
|
|
1014 |
(*assumes "\<forall>r \<in> set rs. bsimp (bsimp r) = bsimp r" *)
|
|
1015 |
shows "bsimp (bsimp_AALTs bs rs) = bsimp_AALTs bs (flts (map bsimp rs))"
|
|
1016 |
apply(induct rs arbitrary: bs taking: "\<lambda>rs. sum_list (map asize rs)" rule: measure_induct)
|
|
1017 |
apply(case_tac x)
|
|
1018 |
apply(simp)
|
|
1019 |
apply(simp)
|
|
1020 |
apply(case_tac "\<exists>bs' rs'. a = AALTs bs' rs'")
|
|
1021 |
apply(clarify)
|
|
1022 |
apply(case_tac list)
|
|
1023 |
apply(simp)
|
|
1024 |
apply(simp)
|
|
1025 |
|
|
1026 |
apply(drule_tac x="flts (rs' @ list)" in spec)
|
|
1027 |
apply(erule impE)
|
|
1028 |
prefer 2
|
|
1029 |
apply(case_tac a)
|
|
1030 |
apply(simp)
|
|
1031 |
apply(case_tac list)
|
|
1032 |
apply(simp)
|
|
1033 |
apply(simp)
|
|
1034 |
apply(case_tac list)
|
|
1035 |
apply(simp)
|
|
1036 |
apply(simp)
|
|
1037 |
apply(case_tac list)
|
|
1038 |
apply(simp)
|
|
1039 |
apply(simp)
|
|
1040 |
prefer 3
|
|
1041 |
apply(case_tac list)
|
|
1042 |
apply(simp)
|
|
1043 |
apply(simp)
|
|
1044 |
apply(case_tac list)
|
|
1045 |
apply(simp)
|
|
1046 |
|
|
1047 |
|
|
1048 |
apply(simp)
|
|
1049 |
|
|
1050 |
apply(case_tac "flts (map bsimp list)")
|
|
1051 |
apply(simp)
|
|
1052 |
apply(simp)
|
|
1053 |
|
|
1054 |
|
|
1055 |
|
|
1056 |
prefer 2
|
|
1057 |
apply(simp)
|
|
1058 |
|
|
1059 |
apply(subst k0)
|
|
1060 |
apply(subst (2) k0)
|
|
1061 |
|
|
1062 |
apply(case_tac a)
|
|
1063 |
apply(simp_all)
|
|
1064 |
|
|
1065 |
prefer 2
|
|
1066 |
apply(simp)
|
|
1067 |
apply(case_tac r)
|
|
1068 |
apply(auto)
|
|
1069 |
apply(case_tac "bsimp x42 = AZERO")
|
|
1070 |
apply(simp)
|
|
1071 |
apply(case_tac "bsimp x43 = AZERO")
|
|
1072 |
apply(simp)
|
|
1073 |
apply(subst bsimp_ASEQ0)
|
|
1074 |
apply(subst bsimp_ASEQ0)
|
|
1075 |
apply(simp)
|
|
1076 |
apply(case_tac "\<exists>bs. bsimp x42 = AONE bs")
|
|
1077 |
apply(auto)[1]
|
|
1078 |
apply(subst bsimp_ASEQ2)
|
|
1079 |
apply(subst bsimp_ASEQ2)
|
|
1080 |
prefer 2
|
|
1081 |
apply(subst bsimp_ASEQ1)
|
|
1082 |
apply(auto)
|
|
1083 |
apply(subst bsimp_ASEQ1)
|
|
1084 |
apply(auto)
|
|
1085 |
apply(subst (asm) bsimp_ASEQ2)
|
|
1086 |
apply(subst (asm) bsimp_ASEQ2)
|
|
1087 |
using flts_fuse bsimp_fuse bsimp_fuse_AALTs bsimp_fuse_AALTs2 bsimp_AALTs.simps flts.simps
|
|
1088 |
|
|
1089 |
apply(case_tac x43)
|
|
1090 |
apply(simp_all)
|
|
1091 |
prefer 3
|
|
1092 |
oops
|
|
1093 |
|
|
1094 |
lemma bsimp_idem:
|
|
1095 |
shows "bsimp (bsimp r) = bsimp r"
|
|
1096 |
apply(induct r taking: "asize" rule: measure_induct)
|
|
1097 |
apply(case_tac x)
|
|
1098 |
apply(simp)
|
|
1099 |
apply(simp)
|
|
1100 |
apply(simp)
|
|
1101 |
prefer 3
|
|
1102 |
apply(simp)
|
|
1103 |
apply(simp)
|
|
1104 |
apply (simp add: bsimp_ASEQ_idem)
|
|
1105 |
apply(clarify)
|
|
1106 |
apply(case_tac x52)
|
|
1107 |
apply(simp)
|
|
1108 |
apply(simp)
|
|
1109 |
apply(subst k0)
|
|
1110 |
apply(subst (2) k0)
|
|
1111 |
apply(case_tac "bsimp a = AZERO")
|
|
1112 |
apply(simp)
|
|
1113 |
apply(frule_tac x="AALTs x51 (flts (map bsimp list))" in spec)
|
|
1114 |
apply(drule mp)
|
|
1115 |
apply(simp)
|
|
1116 |
apply (meson add_le_cancel_right asize0 le_trans not_le rt trans_le_add2)
|
|
1117 |
apply(simp)
|
|
1118 |
apply(subst (asm) flts_idem)
|
|
1119 |
apply(auto)[1]
|
|
1120 |
apply(drule_tac x="r" in spec)
|
|
1121 |
apply (metis add.commute add_lessD1 not_add_less1 not_less_eq sum_list_map_remove1)
|
|
1122 |
apply(simp)
|
|
1123 |
apply(subst flts_idem)
|
|
1124 |
apply(auto)[1]
|
|
1125 |
apply(drule_tac x="r" in spec)
|
|
1126 |
apply (metis add.commute add_lessD1 not_add_less1 not_less_eq sum_list_map_remove1)
|
|
1127 |
apply(simp)
|
|
1128 |
apply(case_tac "nonalt (bsimp a)")
|
|
1129 |
apply(subst k0b)
|
|
1130 |
apply(simp)
|
|
1131 |
apply(simp)
|
|
1132 |
apply(subst k0b)
|
|
1133 |
apply(simp)
|
|
1134 |
apply(simp)
|
|
1135 |
apply(auto)[1]
|
|
1136 |
apply(frule_tac x="AALTs x51 (bsimp a # flts (map bsimp list))" in spec)
|
|
1137 |
apply(drule mp)
|
|
1138 |
apply(simp)
|
|
1139 |
prefer 2
|
|
1140 |
apply(simp)
|
|
1141 |
apply(subst (asm) k0)
|
|
1142 |
apply(subst (asm) flts_idem)
|
|
1143 |
apply(auto)[1]
|
|
1144 |
apply (simp add: sum_list_map_remove1)
|
|
1145 |
apply(subst (asm) k0b)
|
|
1146 |
apply(simp)
|
|
1147 |
apply(simp)
|
|
1148 |
apply(simp)
|
|
1149 |
apply(subst k0)
|
|
1150 |
apply(subst flts_idem)
|
|
1151 |
apply(auto)[1]
|
|
1152 |
apply (simp add: sum_list_map_remove1)
|
|
1153 |
apply(subst k0b)
|
|
1154 |
apply(simp)
|
|
1155 |
apply(simp)
|
|
1156 |
apply(simp)
|
|
1157 |
lemma XX_bder:
|
|
1158 |
shows "bsimp (bder c (bsimp r)) = (bsimp \<circ> bder c) r"
|
|
1159 |
apply(induct r)
|
|
1160 |
apply(simp)
|
|
1161 |
apply(simp)
|
|
1162 |
apply(simp)
|
|
1163 |
prefer 3
|
|
1164 |
apply(simp)
|
|
1165 |
prefer 2
|
|
1166 |
apply(simp)
|
|
1167 |
apply(case_tac x2a)
|
|
1168 |
apply(simp)
|
|
1169 |
apply(simp)
|
|
1170 |
apply(auto)[1]
|
|
1171 |
|
|
1172 |
|
314
|
1173 |
lemma q3a:
|
|
1174 |
assumes "\<exists>r \<in> set rs. bnullable r"
|
|
1175 |
shows "bmkeps (AALTs bs (map (fuse bs1) rs)) = bmkeps (AALTs (bs@bs1) rs)"
|
|
1176 |
using assms
|
|
1177 |
apply(induct rs arbitrary: bs bs1)
|
|
1178 |
apply(simp)
|
|
1179 |
apply(simp)
|
|
1180 |
apply(auto)
|
|
1181 |
apply (metis append_assoc b2 bnullable_correctness erase_fuse r0)
|
|
1182 |
apply(case_tac "bnullable a")
|
|
1183 |
apply (metis append.assoc b2 bnullable_correctness erase_fuse r0)
|
|
1184 |
apply(case_tac rs)
|
|
1185 |
apply(simp)
|
|
1186 |
apply(simp)
|
|
1187 |
apply(auto)[1]
|
|
1188 |
apply (metis bnullable_correctness erase_fuse)+
|
|
1189 |
done
|
|
1190 |
|
|
1191 |
lemma qq4:
|
|
1192 |
assumes "\<exists>x\<in>set list. bnullable x"
|
|
1193 |
shows "\<exists>x\<in>set (flts list). bnullable x"
|
|
1194 |
using assms
|
|
1195 |
apply(induct list rule: flts.induct)
|
|
1196 |
apply(auto)
|
|
1197 |
by (metis UnCI bnullable_correctness erase_fuse imageI)
|
|
1198 |
|
|
1199 |
|
|
1200 |
lemma qs3:
|
|
1201 |
assumes "\<exists>r \<in> set rs. bnullable r"
|
|
1202 |
shows "bmkeps (AALTs bs rs) = bmkeps (AALTs bs (flts rs))"
|
|
1203 |
using assms
|
|
1204 |
apply(induct rs arbitrary: bs taking: size rule: measure_induct)
|
|
1205 |
apply(case_tac x)
|
|
1206 |
apply(simp)
|
|
1207 |
apply(simp)
|
|
1208 |
apply(case_tac a)
|
|
1209 |
apply(simp)
|
|
1210 |
apply (simp add: r1)
|
|
1211 |
apply(simp)
|
|
1212 |
apply (simp add: r0)
|
|
1213 |
apply(simp)
|
|
1214 |
apply(case_tac "flts list")
|
|
1215 |
apply(simp)
|
|
1216 |
apply (metis L_erase_AALTs L_erase_flts L_flat_Prf1 L_flat_Prf2 Prf_elims(1) bnullable_correctness erase.simps(4) mkeps_nullable r2)
|
|
1217 |
apply(simp)
|
|
1218 |
apply (simp add: r1)
|
|
1219 |
prefer 3
|
|
1220 |
apply(simp)
|
|
1221 |
apply (simp add: r0)
|
|
1222 |
prefer 2
|
|
1223 |
apply(simp)
|
|
1224 |
apply(case_tac "\<exists>x\<in>set x52. bnullable x")
|
|
1225 |
apply(case_tac "list")
|
|
1226 |
apply(simp)
|
|
1227 |
apply (metis b2 fuse.simps(4) q3a r2)
|
|
1228 |
apply(erule disjE)
|
|
1229 |
apply(subst qq1)
|
|
1230 |
apply(auto)[1]
|
|
1231 |
apply (metis bnullable_correctness erase_fuse)
|
|
1232 |
apply(simp)
|
|
1233 |
apply (metis b2 fuse.simps(4) q3a r2)
|
|
1234 |
apply(simp)
|
|
1235 |
apply(auto)[1]
|
|
1236 |
apply(subst qq1)
|
|
1237 |
apply (metis bnullable_correctness erase_fuse image_eqI set_map)
|
|
1238 |
apply (metis b2 fuse.simps(4) q3a r2)
|
|
1239 |
apply(subst qq1)
|
|
1240 |
apply (metis bnullable_correctness erase_fuse image_eqI set_map)
|
|
1241 |
apply (metis b2 fuse.simps(4) q3a r2)
|
|
1242 |
apply(simp)
|
|
1243 |
apply(subst qq2)
|
|
1244 |
apply (metis bnullable_correctness erase_fuse imageE set_map)
|
|
1245 |
prefer 2
|
|
1246 |
apply(case_tac "list")
|
|
1247 |
apply(simp)
|
|
1248 |
apply(simp)
|
|
1249 |
apply (simp add: qq4)
|
|
1250 |
apply(simp)
|
|
1251 |
apply(auto)
|
|
1252 |
apply(case_tac list)
|
|
1253 |
apply(simp)
|
|
1254 |
apply(simp)
|
|
1255 |
apply (simp add: r0)
|
|
1256 |
apply(case_tac "bnullable (ASEQ x41 x42 x43)")
|
|
1257 |
apply(case_tac list)
|
|
1258 |
apply(simp)
|
|
1259 |
apply(simp)
|
|
1260 |
apply (simp add: r0)
|
|
1261 |
apply(simp)
|
|
1262 |
using qq4 r1 r2 by auto
|
|
1263 |
|
317
|
1264 |
|
314
|
1265 |
|
|
1266 |
lemma k1:
|
|
1267 |
assumes "\<And>x2aa. \<lbrakk>x2aa \<in> set x2a; bnullable x2aa\<rbrakk> \<Longrightarrow> bmkeps x2aa = bmkeps (bsimp x2aa)"
|
|
1268 |
"\<exists>x\<in>set x2a. bnullable x"
|
|
1269 |
shows "bmkeps (AALTs x1 (flts x2a)) = bmkeps (AALTs x1 (flts (map bsimp x2a)))"
|
|
1270 |
using assms
|
|
1271 |
apply(induct x2a)
|
|
1272 |
apply fastforce
|
|
1273 |
apply(simp)
|
|
1274 |
apply(subst k0)
|
|
1275 |
apply(subst (2) k0)
|
|
1276 |
apply(auto)[1]
|
|
1277 |
apply (metis b3 k0 list.set_intros(1) qs3 r0)
|
|
1278 |
by (smt b3 imageI insert_iff k0 list.set(2) qq3 qs3 r0 r1 set_map)
|
|
1279 |
|
|
1280 |
|
|
1281 |
|
|
1282 |
lemma bmkeps_simp:
|
|
1283 |
assumes "bnullable r"
|
|
1284 |
shows "bmkeps r = bmkeps (bsimp r)"
|
|
1285 |
using assms
|
|
1286 |
apply(induct r)
|
|
1287 |
apply(simp)
|
|
1288 |
apply(simp)
|
|
1289 |
apply(simp)
|
|
1290 |
apply(simp)
|
|
1291 |
prefer 3
|
|
1292 |
apply(simp)
|
|
1293 |
apply(case_tac "bsimp r1 = AZERO")
|
|
1294 |
apply(simp)
|
|
1295 |
apply(auto)[1]
|
|
1296 |
apply (metis L_bsimp_erase L_flat_Prf1 L_flat_Prf2 Prf_elims(1) bnullable_correctness erase.simps(1) mkeps_nullable)
|
|
1297 |
apply(case_tac "bsimp r2 = AZERO")
|
|
1298 |
apply(simp)
|
|
1299 |
apply(auto)[1]
|
|
1300 |
apply (metis L_bsimp_erase L_flat_Prf1 L_flat_Prf2 Prf_elims(1) bnullable_correctness erase.simps(1) mkeps_nullable)
|
|
1301 |
apply(case_tac "\<exists>bs. bsimp r1 = AONE bs")
|
|
1302 |
apply(auto)[1]
|
|
1303 |
apply(subst b1)
|
|
1304 |
apply(subst b2)
|
|
1305 |
apply(simp add: b3[symmetric])
|
|
1306 |
apply(simp)
|
|
1307 |
apply(subgoal_tac "bsimp_ASEQ x1 (bsimp r1) (bsimp r2) = ASEQ x1 (bsimp r1) (bsimp r2)")
|
|
1308 |
prefer 2
|
|
1309 |
apply (smt b3 bnullable.elims(2) bsimp_ASEQ.simps(17) bsimp_ASEQ.simps(19) bsimp_ASEQ.simps(20) bsimp_ASEQ.simps(21) bsimp_ASEQ.simps(22) bsimp_ASEQ.simps(24) bsimp_ASEQ.simps(25) bsimp_ASEQ.simps(26) bsimp_ASEQ.simps(27) bsimp_ASEQ.simps(29) bsimp_ASEQ.simps(30) bsimp_ASEQ.simps(31))
|
|
1310 |
apply(simp)
|
|
1311 |
apply(simp)
|
|
1312 |
apply(subst q3[symmetric])
|
|
1313 |
apply simp
|
|
1314 |
using b3 qq4 apply auto[1]
|
|
1315 |
apply(subst qs3)
|
|
1316 |
apply simp
|
|
1317 |
using k1 by blast
|
|
1318 |
|
|
1319 |
thm bmkeps_retrieve bmkeps_simp bder_retrieve
|
|
1320 |
|
|
1321 |
lemma bmkeps_bder_AALTs:
|
|
1322 |
assumes "\<exists>r \<in> set rs. bnullable (bder c r)"
|
|
1323 |
shows "bmkeps (bder c (bsimp_AALTs bs rs)) = bmkeps (bsimp_AALTs bs (map (bder c) rs))"
|
|
1324 |
using assms
|
|
1325 |
apply(induct rs)
|
|
1326 |
apply(simp)
|
|
1327 |
apply(simp)
|
|
1328 |
apply(auto)
|
|
1329 |
apply(case_tac rs)
|
|
1330 |
apply(simp)
|
|
1331 |
apply (metis (full_types) Prf_injval bder_retrieve bmkeps_retrieve bnullable_correctness erase_bder erase_fuse mkeps_nullable retrieve_fuse2)
|
|
1332 |
apply(simp)
|
|
1333 |
apply(case_tac rs)
|
|
1334 |
apply(simp_all)
|
|
1335 |
done
|
|
1336 |
|
|
1337 |
|
317
|
1338 |
fun extr :: "arexp \<Rightarrow> (bit list) set" where
|
|
1339 |
"extr (AONE bs) = {bs}"
|
|
1340 |
| "extr (ACHAR bs c) = {bs}"
|
|
1341 |
| "extr (AALTs bs (r#rs)) =
|
|
1342 |
{bs @ bs' | bs'. bs' \<in> extr r} \<union>
|
|
1343 |
{bs @ bs' | bs'. bs' \<in> extr (AALTs [] rs)}"
|
|
1344 |
| "extr (ASEQ bs r1 r2) =
|
|
1345 |
{bs @ bs1 @ bs2 | bs1 bs2. bs1 \<in> extr r1 \<and> bs2 \<in> extr r2}"
|
|
1346 |
| "extr (ASTAR bs r) = {bs @ [S]} \<union>
|
|
1347 |
{bs @ [Z] @ bs1 @ bs2 | bs1 bs2. bs1 \<in> extr r \<and> bs2 \<in> extr (ASTAR [] r)}"
|
314
|
1348 |
|
|
1349 |
|
|
1350 |
lemma MAIN_decode:
|
|
1351 |
assumes "\<Turnstile> v : ders s r"
|
|
1352 |
shows "Some (flex r id s v) = decode (retrieve (bders_simp (intern r) s) v) r"
|
|
1353 |
using assms
|
|
1354 |
proof (induct s arbitrary: v rule: rev_induct)
|
|
1355 |
case Nil
|
|
1356 |
have "\<Turnstile> v : ders [] r" by fact
|
|
1357 |
then have "\<Turnstile> v : r" by simp
|
|
1358 |
then have "Some v = decode (retrieve (intern r) v) r"
|
|
1359 |
using decode_code retrieve_code by auto
|
|
1360 |
then show "Some (flex r id [] v) = decode (retrieve (bders_simp (intern r) []) v) r"
|
|
1361 |
by simp
|
|
1362 |
next
|
|
1363 |
case (snoc c s v)
|
|
1364 |
have IH: "\<And>v. \<Turnstile> v : ders s r \<Longrightarrow>
|
|
1365 |
Some (flex r id s v) = decode (retrieve (bders_simp (intern r) s) v) r" by fact
|
|
1366 |
have asm: "\<Turnstile> v : ders (s @ [c]) r" by fact
|
|
1367 |
then have asm2: "\<Turnstile> injval (ders s r) c v : ders s r"
|
|
1368 |
by(simp add: Prf_injval ders_append)
|
|
1369 |
have "Some (flex r id (s @ [c]) v) = Some (flex r id s (injval (ders s r) c v))"
|
|
1370 |
by (simp add: flex_append)
|
|
1371 |
also have "... = decode (retrieve (bders_simp (intern r) s) (injval (ders s r) c v)) r"
|
|
1372 |
using asm2 IH by simp
|
|
1373 |
also have "... = decode (retrieve (bder c (bders_simp (intern r) s)) v) r"
|
|
1374 |
using asm bder_retrieve ders_append
|
|
1375 |
apply -
|
|
1376 |
apply(drule_tac x="v" in meta_spec)
|
|
1377 |
apply(drule_tac x="c" in meta_spec)
|
|
1378 |
apply(drule_tac x="bders_simp (intern r) s" in meta_spec)
|
|
1379 |
apply(drule_tac meta_mp)
|
|
1380 |
apply(simp add: ders_append)
|
|
1381 |
defer
|
|
1382 |
apply(simp)
|
|
1383 |
oops
|
|
1384 |
|
316
|
1385 |
fun vsimp :: "arexp \<Rightarrow> val \<Rightarrow> val"
|
|
1386 |
where
|
|
1387 |
"vsimp (ASEQ _ (AONE _) r) (Seq v1 v2) = vsimp r v1"
|
|
1388 |
| "vsimp _ v = v"
|
|
1389 |
|
|
1390 |
lemma fuse_vsimp:
|
|
1391 |
assumes "\<Turnstile> v : (erase r)"
|
|
1392 |
shows "vsimp (fuse bs r) v = vsimp r v"
|
|
1393 |
using assms
|
|
1394 |
apply(induct r arbitrary: v bs)
|
|
1395 |
apply(simp_all)
|
|
1396 |
apply(case_tac "\<exists>bs. r1 = AONE bs")
|
|
1397 |
apply(auto)
|
|
1398 |
apply (metis Prf_elims(2) vsimp.simps(1))
|
|
1399 |
apply(erule Prf_elims)
|
|
1400 |
apply(auto)
|
|
1401 |
apply(case_tac r1)
|
|
1402 |
apply(auto)
|
|
1403 |
done
|
|
1404 |
|
|
1405 |
|
|
1406 |
lemma retrieve_XXX0:
|
|
1407 |
assumes "\<And>r v. \<lbrakk>r \<in> set rs; \<Turnstile> v : erase r\<rbrakk> \<Longrightarrow>
|
|
1408 |
\<exists>v'. \<Turnstile> v' : erase (bsimp r) \<and> retrieve (bsimp r) v' = retrieve r v"
|
|
1409 |
"\<Turnstile> v : erase (AALTs bs rs)"
|
|
1410 |
shows "\<exists>v'. \<Turnstile> v' : erase (bsimp_AALTs bs (flts (map bsimp rs))) \<and>
|
|
1411 |
retrieve (bsimp_AALTs bs (flts (map bsimp rs))) v' = retrieve (AALTs bs rs) v"
|
|
1412 |
using assms
|
|
1413 |
apply(induct rs arbitrary: bs v taking: size rule: measure_induct)
|
|
1414 |
apply(case_tac x)
|
|
1415 |
apply(simp)
|
|
1416 |
using Prf_elims(1) apply blast
|
|
1417 |
apply(simp)
|
|
1418 |
apply(case_tac list)
|
|
1419 |
apply(simp_all)
|
|
1420 |
apply(case_tac a)
|
|
1421 |
apply(simp_all)
|
|
1422 |
using Prf_elims(1) apply blast
|
|
1423 |
apply (metis erase.simps(2) fuse.simps(2) retrieve_fuse2)
|
|
1424 |
using Prf_elims(5) apply force
|
|
1425 |
apply(erule Prf_elims)
|
|
1426 |
apply(auto)[1]
|
|
1427 |
|
|
1428 |
|
|
1429 |
|
|
1430 |
|
|
1431 |
apply(simp)
|
|
1432 |
apply(erule Prf_elims)
|
|
1433 |
using Prf_elims(1) apply b last
|
|
1434 |
apply(auto)
|
|
1435 |
apply (metis append_Ni l2 erase_fuse fuse.simps(4) retrieve_fuse2)
|
|
1436 |
apply(case_tac rs)
|
|
1437 |
apply(auto)
|
|
1438 |
|
|
1439 |
|
|
1440 |
oops
|
|
1441 |
|
|
1442 |
fun get where
|
|
1443 |
"get (Some v) = v"
|
314
|
1444 |
|
316
|
1445 |
|
|
1446 |
lemma retrieve_XXX:
|
|
1447 |
assumes "\<Turnstile> v : erase r"
|
|
1448 |
shows "\<Turnstile> get (decode (code v) (erase (bsimp r))) : erase (bsimp r)"
|
|
1449 |
using assms
|
|
1450 |
apply(induct r arbitrary: v)
|
|
1451 |
apply(simp)
|
|
1452 |
using Prf_elims(1) apply auto[1]
|
|
1453 |
apply(simp)
|
|
1454 |
apply (simp add: decode_code)
|
|
1455 |
apply(simp)
|
|
1456 |
apply (simp add: decode_code)
|
|
1457 |
apply(simp)
|
|
1458 |
apply(erule Prf_elims)
|
|
1459 |
apply(simp)
|
|
1460 |
apply(case_tac "r1 = AZERO")
|
|
1461 |
apply(simp)
|
|
1462 |
apply (meson Prf_elims(1) Prf_elims(2))
|
|
1463 |
apply(case_tac "r2 = AZERO")
|
|
1464 |
apply(simp)
|
|
1465 |
apply (meson Prf_elims(1) Prf_elims(2))
|
|
1466 |
apply(case_tac "\<exists>bs. bsimp r1 = AONE bs")
|
|
1467 |
apply(clarify)
|
|
1468 |
apply(simp)
|
|
1469 |
apply(subst bsimp_ASEQ2)
|
|
1470 |
apply(subst bsimp_ASEQ2)
|
317
|
1471 |
apply(simp add: erase_fuse)
|
|
1472 |
apply(case_tac r1)
|
|
1473 |
apply(simp_all)
|
|
1474 |
using Prf_elims(4) apply fastforce
|
|
1475 |
apply(erule Prf_elims)
|
|
1476 |
apply(simp)
|
|
1477 |
|
|
1478 |
apply(simp)
|
|
1479 |
|
|
1480 |
|
316
|
1481 |
defer
|
|
1482 |
apply(subst bsimp_ASEQ1)
|
|
1483 |
using L_bsimp_erase L_flat_Prf1 L_flat_Prf2 apply fastforce
|
|
1484 |
using L_bsimp_erase L_
|
314
|
1485 |
|
316
|
1486 |
lemma retrieve_XXX:
|
|
1487 |
assumes "\<Turnstile> v : erase r"
|
|
1488 |
shows "\<Turnstile> (vsimp (bsimp r) v : erase (bsimp r) \<and> retrieve (bsimp r) (vsimp (bsimp r) v) = retrieve r v"
|
|
1489 |
using assms
|
|
1490 |
apply(induct r arbitrary: v)
|
|
1491 |
apply(simp)
|
|
1492 |
using Prf_elims(1) apply blast
|
|
1493 |
apply(simp)
|
|
1494 |
using Prf_elims(4) apply fastforce
|
|
1495 |
apply(simp)
|
|
1496 |
apply blast
|
|
1497 |
apply simp
|
|
1498 |
apply(case_tac "r1 = AZERO")
|
|
1499 |
apply(simp)
|
|
1500 |
apply (meson Prf_elims(1) Prf_elims(2))
|
|
1501 |
apply(case_tac "r2 = AZERO")
|
|
1502 |
apply(simp)
|
|
1503 |
apply (meson Prf_elims(1) Prf_elims(2))
|
|
1504 |
apply(erule Prf_elims)
|
|
1505 |
apply(simp)
|
|
1506 |
apply(case_tac "\<exists>bs. bsimp r1 = AONE bs")
|
|
1507 |
apply(clarify)
|
|
1508 |
apply(simp)
|
|
1509 |
apply(subst bsimp_ASEQ2)
|
|
1510 |
defer
|
|
1511 |
apply(subst bsimp_ASEQ1)
|
|
1512 |
using L_bsimp_erase L_flat_Prf1 L_flat_Prf2 apply fastforce
|
|
1513 |
using L_bsimp_erase L_flat_Prf1 L_flat_Prf2 apply fastforce
|
|
1514 |
apply(simp)
|
|
1515 |
apply(simp)
|
|
1516 |
apply(drule_tac x="v1" in meta_spec)
|
|
1517 |
apply(drule_tac x="v2" in meta_spec)
|
|
1518 |
apply(simp)
|
|
1519 |
apply(clarify)
|
|
1520 |
apply(rule_tac x="Seq v' v'a" in exI)
|
|
1521 |
apply(simp)
|
|
1522 |
apply (metis Prf.intros(1) Prf_elims(1) bsimp_ASEQ1 erase.simps(1) retrieve.simps(6))
|
|
1523 |
prefer 3
|
|
1524 |
apply(drule_tac x="v1" in meta_spec)
|
|
1525 |
apply(drule_tac x="v2" in meta_spec)
|
|
1526 |
apply(simp)
|
|
1527 |
apply(clarify)
|
|
1528 |
apply(rule_tac x="v'a" in exI)
|
|
1529 |
apply(subst bsimp_ASEQ2)
|
|
1530 |
apply (metis Prf_elims(4) append_assoc erase_fuse retrieve.simps(1) retrieve_fuse2)
|
|
1531 |
prefer 2
|
|
1532 |
apply(auto)
|
|
1533 |
apply(case_tac "x2a")
|
|
1534 |
apply(simp)
|
|
1535 |
using Prf_elims(1) apply blast
|
|
1536 |
apply(simp)
|
|
1537 |
apply(case_tac "list")
|
|
1538 |
apply(simp)
|
|
1539 |
sorry
|
314
|
1540 |
|
|
1541 |
|
|
1542 |
lemma retrieve_XXX:
|
|
1543 |
assumes "\<Turnstile> v : erase r"
|
|
1544 |
shows "\<exists>v'. \<Turnstile> v' : erase (bsimp r) \<and> retrieve (bsimp r) v' = retrieve r v"
|
|
1545 |
using assms
|
|
1546 |
apply(induct r arbitrary: v)
|
|
1547 |
apply(simp)
|
|
1548 |
using Prf_elims(1) apply blast
|
|
1549 |
apply(simp)
|
|
1550 |
using Prf_elims(4) apply fastforce
|
|
1551 |
apply(simp)
|
|
1552 |
apply blast
|
|
1553 |
apply simp
|
|
1554 |
apply(case_tac "r1 = AZERO")
|
|
1555 |
apply(simp)
|
|
1556 |
apply (meson Prf_elims(1) Prf_elims(2))
|
|
1557 |
apply(case_tac "r2 = AZERO")
|
|
1558 |
apply(simp)
|
|
1559 |
apply (meson Prf_elims(1) Prf_elims(2))
|
|
1560 |
apply(erule Prf_elims)
|
|
1561 |
apply(simp)
|
|
1562 |
apply(case_tac "\<exists>bs. bsimp r1 = AONE bs")
|
|
1563 |
apply(clarify)
|
|
1564 |
apply(simp)
|
|
1565 |
apply(subst bsimp_ASEQ2)
|
|
1566 |
defer
|
|
1567 |
apply(subst bsimp_ASEQ1)
|
|
1568 |
using L_bsimp_erase L_flat_Prf1 L_flat_Prf2 apply fastforce
|
|
1569 |
using L_bsimp_erase L_flat_Prf1 L_flat_Prf2 apply fastforce
|
|
1570 |
apply(simp)
|
|
1571 |
apply(simp)
|
|
1572 |
apply(drule_tac x="v1" in meta_spec)
|
|
1573 |
apply(drule_tac x="v2" in meta_spec)
|
|
1574 |
apply(simp)
|
|
1575 |
apply(clarify)
|
|
1576 |
apply(rule_tac x="Seq v' v'a" in exI)
|
|
1577 |
apply(simp)
|
|
1578 |
apply (metis Prf.intros(1) Prf_elims(1) bsimp_ASEQ1 erase.simps(1) retrieve.simps(6))
|
|
1579 |
prefer 3
|
|
1580 |
apply(drule_tac x="v1" in meta_spec)
|
|
1581 |
apply(drule_tac x="v2" in meta_spec)
|
|
1582 |
apply(simp)
|
|
1583 |
apply(clarify)
|
|
1584 |
apply(rule_tac x="v'a" in exI)
|
|
1585 |
apply(subst bsimp_ASEQ2)
|
|
1586 |
apply (metis Prf_elims(4) append_assoc erase_fuse retrieve.simps(1) retrieve_fuse2)
|
|
1587 |
prefer 2
|
|
1588 |
apply(auto)
|
|
1589 |
apply(case_tac "x2a")
|
|
1590 |
apply(simp)
|
|
1591 |
using Prf_elims(1) apply blast
|
|
1592 |
apply(simp)
|
|
1593 |
apply(case_tac "list")
|
|
1594 |
apply(simp)
|
|
1595 |
sorry
|
|
1596 |
|
|
1597 |
|
|
1598 |
lemma TEST:
|
|
1599 |
assumes "\<Turnstile> v : ders s r"
|
316
|
1600 |
shows "\<exists>v'. retrieve (bders (intern r) s) v' = retrieve (bsimp (bders (intern r) s)) v"
|
314
|
1601 |
using assms
|
|
1602 |
apply(induct s arbitrary: r v rule: rev_induct)
|
|
1603 |
apply(simp)
|
316
|
1604 |
|
314
|
1605 |
defer
|
|
1606 |
apply(simp add: ders_append)
|
|
1607 |
apply(frule Prf_injval)
|
|
1608 |
apply(drule_tac x="r" in meta_spec)
|
|
1609 |
apply(drule_tac x="injval (ders xs r) x v" in meta_spec)
|
|
1610 |
apply(simp)
|
|
1611 |
apply(simp add: bders_append)
|
|
1612 |
apply(subst bder_retrieve)
|
|
1613 |
apply(simp)
|
|
1614 |
apply(simp)
|
|
1615 |
thm bder_retrieve
|
|
1616 |
thm bmkeps_retrieve
|
|
1617 |
|
|
1618 |
|
|
1619 |
lemma bmkeps_simp2:
|
|
1620 |
assumes "bnullable (bder c r)"
|
|
1621 |
shows "bmkeps (bder c (bsimp r)) = bmkeps (bder c r)"
|
|
1622 |
using assms
|
|
1623 |
apply(induct r)
|
|
1624 |
apply(simp)
|
|
1625 |
apply(simp)
|
|
1626 |
apply(simp)
|
|
1627 |
prefer 3
|
|
1628 |
apply(simp)
|
|
1629 |
apply(simp)
|
|
1630 |
apply(auto)[1]
|
|
1631 |
prefer 2
|
|
1632 |
apply(case_tac "r1 = AZERO")
|
|
1633 |
apply(simp)
|
|
1634 |
apply(case_tac "r2 = AZERO")
|
|
1635 |
apply(simp)
|
|
1636 |
apply(case_tac "\<exists>bs. (bsimp r1) = AONE bs")
|
|
1637 |
apply(clarify)
|
|
1638 |
apply(simp)
|
|
1639 |
apply(subst bsimp_ASEQ2)
|
|
1640 |
|
|
1641 |
apply(simp add: bmkeps_simp)
|
|
1642 |
apply(simp add: bders_append)
|
|
1643 |
apply(drule_tac x="bder a r" in meta_spec)
|
|
1644 |
apply(simp)
|
|
1645 |
apply(simp)
|
|
1646 |
apply(simp)
|
|
1647 |
prefer 3
|
|
1648 |
apply(simp)
|
|
1649 |
prefer 2
|
|
1650 |
apply(simp)
|
|
1651 |
apply(case_tac x2a)
|
|
1652 |
apply(simp)
|
|
1653 |
apply(simp add: )
|
|
1654 |
apply(subst k0)
|
|
1655 |
apply(auto)[1]
|
|
1656 |
apply(case_tac list)
|
|
1657 |
apply(simp)
|
|
1658 |
|
|
1659 |
|
|
1660 |
apply(case_tac "r1=AZERO")
|
|
1661 |
apply(simp)
|
|
1662 |
apply(case_tac "r2=AZERO")
|
|
1663 |
apply(simp)
|
|
1664 |
apply(auto)[1]
|
|
1665 |
apply(case_tac "\<exists>bs. r1=AONE bs")
|
|
1666 |
apply(simp)
|
|
1667 |
apply(auto)[1]
|
|
1668 |
apply(subst bsimp_ASEQ2)
|
|
1669 |
|
|
1670 |
|
|
1671 |
prefer 2
|
|
1672 |
apply(simp)
|
|
1673 |
apply(subst bmkeps_bder_AALTs)
|
|
1674 |
apply(case_tac x2a)
|
|
1675 |
apply(simp)
|
|
1676 |
apply(simp)
|
|
1677 |
apply(auto)[1]
|
|
1678 |
apply(subst bmkeps_bder_AALTs)
|
|
1679 |
|
|
1680 |
apply(case_tac a)
|
|
1681 |
apply(simp_all)
|
|
1682 |
apply(auto)[1]
|
|
1683 |
apply(case_tac list)
|
|
1684 |
apply(simp)
|
|
1685 |
apply(simp)
|
|
1686 |
|
|
1687 |
prefer 2
|
|
1688 |
apply(simp)
|
|
1689 |
|
|
1690 |
|
|
1691 |
lemma bbs0:
|
|
1692 |
shows "blexer_simp r [] = blexer r []"
|
|
1693 |
apply(simp add: blexer_def blexer_simp_def)
|
|
1694 |
done
|
|
1695 |
|
|
1696 |
lemma bbs1:
|
|
1697 |
shows "blexer_simp r [c] = blexer r [c]"
|
|
1698 |
apply(simp add: blexer_def blexer_simp_def)
|
|
1699 |
apply(auto)
|
|
1700 |
defer
|
|
1701 |
using b3 apply auto[1]
|
|
1702 |
using b3 apply auto[1]
|
|
1703 |
apply(subst bmkeps_simp[symmetric])
|
|
1704 |
apply(simp)
|
|
1705 |
apply(simp)
|
|
1706 |
done
|
|
1707 |
|
|
1708 |
lemma bbs1:
|
|
1709 |
shows "blexer_simp r [c1, c2] = blexer r [c1, c2]"
|
|
1710 |
apply(simp add: blexer_def blexer_simp_def)
|
|
1711 |
apply(auto)
|
|
1712 |
defer
|
|
1713 |
apply (metis L_bsimp_erase bnullable_correctness der_correctness erase_bder lexer.simps(1) lexer_correct_None option.distinct(1))
|
|
1714 |
apply (metis L_bsimp_erase bnullable_correctness der_correctness erase_bder lexer.simps(1) lexer_correct_None option.distinct(1))
|
|
1715 |
apply(subst bmkeps_simp[symmetric])
|
|
1716 |
using b3 apply auto[1]
|
|
1717 |
apply(subst bmkeps_retrieve)
|
|
1718 |
using b3 bnullable_correctness apply blast
|
|
1719 |
apply(subst bder_retrieve)
|
|
1720 |
using b3 bnullable_correctness mkeps_nullable apply fastforce
|
|
1721 |
apply(subst bmkeps_retrieve)
|
|
1722 |
using bnullable_correctness apply blast
|
|
1723 |
apply(subst bder_retrieve)
|
|
1724 |
using bnullable_correctness mkeps_nullable apply force
|
|
1725 |
|
|
1726 |
using bder_retrieve bmkeps_simp bmkeps_retrieve
|
|
1727 |
|
|
1728 |
|
|
1729 |
|
|
1730 |
lemma bsimp_retrieve_bder:
|
|
1731 |
assumes "\<Turnstile> v : der c (erase r)"
|
|
1732 |
shows "retrieve (bder c r) v = retrieve (bsimp (bder c r)) v"
|
|
1733 |
thm bder_retrieve bmkeps_simp
|
|
1734 |
apply(induct r arbitrary: c v)
|
|
1735 |
apply(simp)
|
|
1736 |
apply(simp)
|
|
1737 |
apply(simp)
|
|
1738 |
apply(auto)[1]
|
|
1739 |
apply(case_tac "bsimp (bder c r1) = AZERO")
|
|
1740 |
apply(simp)
|
|
1741 |
|
|
1742 |
prefer 3
|
|
1743 |
apply(simp)
|
|
1744 |
apply(auto elim!: Prf_elims)[1]
|
|
1745 |
apply(case_tac "(bsimp (fuse [Z] (bder c r))) = AZERO")
|
|
1746 |
apply(simp)
|
|
1747 |
apply (metis L_bsimp_erase L_flat_Prf1 L_flat_Prf2 Prf_elims(1) erase.simps(1) erase_bder erase_fuse)
|
|
1748 |
apply(case_tac "\<exists>bs. bsimp (fuse [Z] (bder c r)) = AONE bs")
|
|
1749 |
apply(clarify)
|
|
1750 |
apply(subgoal_tac "L (der c (erase r)) = {[]}")
|
|
1751 |
prefer 2
|
|
1752 |
apply (metis L.simps(2) L_bsimp_erase erase.simps(2) erase_bder erase_fuse)
|
|
1753 |
apply(simp)
|
|
1754 |
|
|
1755 |
|
|
1756 |
|
|
1757 |
apply(subst bsimp_ASEQ1)
|
|
1758 |
apply(simp)
|
|
1759 |
apply(simp)
|
|
1760 |
apply(auto)[1]
|
|
1761 |
|
|
1762 |
prefer 2
|
|
1763 |
|
|
1764 |
|
|
1765 |
lemma oo:
|
|
1766 |
shows "(case (blexer (der c r) s) of None \<Rightarrow> None | Some v \<Rightarrow> Some (injval r c v)) = blexer r (c # s)"
|
|
1767 |
apply(simp add: blexer_correctness)
|
|
1768 |
done
|
|
1769 |
|
|
1770 |
lemma oo2a:
|
|
1771 |
assumes "\<forall>r. bmkeps (bders_simp r s) = bmkeps (bders r s)" "c # s \<in> L r"
|
|
1772 |
"bnullable (bders_simp (bsimp (bder c (intern r))) s)"
|
|
1773 |
shows "(case (blexer_simp (der c r) s) of None \<Rightarrow> None | Some v \<Rightarrow> Some (injval r c v)) = blexer_simp r (c # s)"
|
|
1774 |
using assms
|
|
1775 |
apply(simp add: blexer_simp_def)
|
|
1776 |
apply(auto split: option.split)
|
|
1777 |
apply (metis blexer_correctness blexer_def lexer.simps(2) lexer_correct_None option.simps(4))
|
|
1778 |
prefer 2
|
|
1779 |
apply (metis L_bders_simp L_bsimp_erase Posix1(1) Posix_mkeps bnullable_correctness ders_correctness erase_bder erase_bders erase_intern lexer.simps(1) lexer_correct_None)
|
|
1780 |
apply(subst bmkeps_retrieve)
|
|
1781 |
using L_bders_simp bnullable_correctness nullable_correctness apply blast
|
|
1782 |
|
|
1783 |
thm bder_retrieve
|
|
1784 |
|
|
1785 |
|
|
1786 |
apply(subst bder_retrieve[symmetric])
|
|
1787 |
|
|
1788 |
|
|
1789 |
|
|
1790 |
apply(drule_tac x="bsimp (bder c (intern r))" in spec)
|
|
1791 |
apply(drule sym)
|
|
1792 |
apply(simp)
|
|
1793 |
apply(subst blexer_simp_def)
|
|
1794 |
apply(case_tac "bnullable (bders_simp (intern (der c r)) s)")
|
|
1795 |
apply(simp)
|
|
1796 |
apply(auto split: option.split)
|
|
1797 |
apply(subst oo)
|
|
1798 |
apply(simp)
|
|
1799 |
done
|
|
1800 |
|
|
1801 |
|
|
1802 |
|
|
1803 |
lemma oo3:
|
|
1804 |
assumes "\<forall>r. bders r s = bders_simp r s"
|
|
1805 |
shows "blexer_simp r (s @ [c]) = blexer r (s @ [c])"
|
|
1806 |
using assms
|
|
1807 |
apply(simp (no_asm) add: blexer_simp_def)
|
|
1808 |
apply(auto)
|
|
1809 |
prefer 2
|
|
1810 |
apply (metis L_bders_simp blexer_def bnullable_correctness lexer.simps(1) lexer_correct_None option.distinct(1))
|
|
1811 |
apply(simp add: bders_simp_append)
|
|
1812 |
apply(subst bmkeps_simp[symmetric])
|
|
1813 |
using b3 apply auto[1]
|
|
1814 |
apply(simp add: blexer_def)
|
|
1815 |
apply(auto)[1]
|
|
1816 |
prefer 2
|
|
1817 |
apply (metis (mono_tags, lifting) L_bders_simp Posix_mkeps append.right_neutral bders_simp.simps(1) bders_simp.simps(2) bders_simp_append bnullable_correctness lexer.simps(1) lexer_correct_None lexer_correctness(1) option.distinct(1))
|
|
1818 |
apply(simp add: bders_append)
|
|
1819 |
done
|
|
1820 |
|
|
1821 |
lemma oo4:
|
|
1822 |
assumes "\<forall>r. bmkeps (bders r s) = bmkeps (bders_simp r s)" "bnullable (bder c (bders r s))"
|
|
1823 |
shows "bmkeps (bders_simp r (s @ [c])) = bmkeps (bders r (s @ [c]))"
|
|
1824 |
using assms
|
|
1825 |
apply(simp add: bders_simp_append)
|
|
1826 |
apply(subst bmkeps_simp[symmetric])
|
|
1827 |
apply (metis L_bders_simp bnullable_correctness der_correctness erase_bder lexer.simps(1) lexer_correct_None option.distinct(1))
|
|
1828 |
apply(simp add: bders_append)
|
|
1829 |
done
|
|
1830 |
|
|
1831 |
lemma oo4:
|
|
1832 |
shows "blexer_simp r s = blexer r s"
|
|
1833 |
apply(induct s arbitrary: r rule: rev_induct)
|
|
1834 |
apply(simp only: blexer_simp_def blexer_def)
|
|
1835 |
apply(simp)
|
|
1836 |
apply(simp only: blexer_simp_def blexer_def)
|
|
1837 |
apply(subgoal_tac "bnullable (bders_simp (intern r) (xs @ [x])) = bnullable (bders (intern r) (xs @ [x]))")
|
|
1838 |
prefer 2
|
|
1839 |
apply (simp add: b4)
|
|
1840 |
apply(simp)
|
|
1841 |
apply(rule impI)
|
|
1842 |
apply(simp add: bders_simp_append)
|
|
1843 |
apply(subst bmkeps_simp[symmetric])
|
|
1844 |
using b3 apply auto[1]
|
|
1845 |
apply(subst bmkeps_retrieve)
|
|
1846 |
using b3 bnullable_correctness apply blast
|
|
1847 |
apply(subst bder_retrieve)
|
|
1848 |
using b3 bnullable_correctness mkeps_nullable apply fastforce
|
|
1849 |
apply(simp add: bders_append)
|
|
1850 |
apply(subst bmkeps_retrieve)
|
|
1851 |
using bnullable_correctness apply blast
|
|
1852 |
apply(subst bder_retrieve)
|
|
1853 |
using bnullable_correctness mkeps_nullable apply fastforce
|
|
1854 |
apply(subst erase_bder)
|
|
1855 |
apply(case_tac "xs \<in> L")
|
|
1856 |
apply(subst (asm) (2) bmkeps_retrieve)
|
|
1857 |
|
|
1858 |
|
|
1859 |
thm bmkeps_retrieve bmkeps_retrieve
|
|
1860 |
apply(subst bmkeps_retrieve[symmetric])
|
|
1861 |
|
|
1862 |
apply (simp add: bnullable_correctness)
|
|
1863 |
apply(simp add: bders_simp_append)
|
|
1864 |
|
|
1865 |
|
|
1866 |
apply(induct s arbitrary: r rule: rev_induct)
|
|
1867 |
apply(simp add: blexer_def blexer_simp_def)
|
|
1868 |
apply(rule oo3)
|
|
1869 |
apply(simp (no_asm) add: blexer_simp_def)
|
|
1870 |
apply(auto)
|
|
1871 |
prefer 2
|
|
1872 |
apply (metis L_bders_simp blexer_def bnullable_correctness lexer.simps(1) lexer_correct_None option.distinct(1))
|
|
1873 |
apply(simp add: bders_simp_append)
|
|
1874 |
apply(subst bmkeps_simp[symmetric])
|
|
1875 |
using b3 apply auto[1]
|
|
1876 |
apply(simp add: blexer_def)
|
|
1877 |
apply(auto)[1]
|
|
1878 |
prefer 2
|
|
1879 |
apply (m etis (mono_tags, lifting) L_bders_simp Posix_mkeps append.right_neutral bders_simp.simps(1) bders_simp.simps(2) bders_simp_append bnullable_correctness lexer.simps(1) lexer_correct_None lexer_correctness(1) option.distinct(1))
|
|
1880 |
apply(simp add: bders_append)
|
|
1881 |
oops
|
|
1882 |
|
|
1883 |
|
|
1884 |
lemma bnullable_simp:
|
|
1885 |
assumes "s \<in> L (erase r)"
|
|
1886 |
shows "bmkeps (bders r s) = bmkeps (bders_simp r s)"
|
|
1887 |
using assms
|
|
1888 |
apply(induct s arbitrary: r rule: rev_induct)
|
|
1889 |
apply(simp)
|
|
1890 |
apply(simp add: bders_append bders_simp_append)
|
|
1891 |
apply(subst bmkeps_simp[symmetric])
|
|
1892 |
apply (metis L_bders_simp b3 bders_simp.simps(1) bders_simp.simps(2) bders_simp_append blexer_correctness blexer_def bnullable_correctness erase_bders erase_intern lexer.simps(1) lexer_correct_None lexer_correct_Some lexer_correctness(1))
|
|
1893 |
apply(subst bmkeps_retrieve)
|
|
1894 |
apply (metis bders.simps(1) bders.simps(2) bders_append blexer_correctness blexer_def bnullable_correctness erase_bders erase_intern lexer_correct_Some option.distinct(1))
|
|
1895 |
apply(subst bmkeps_retrieve)
|
|
1896 |
apply (metis L_bders_simp L_bsimp_erase Posix_mkeps bders_simp.simps(1) bders_simp.simps(2) bders_simp_append blexer_correctness blexer_def bnullable_correctness erase_bders erase_intern lexer.simps(1) lexer_correct_None lexer_correctness(2))
|
|
1897 |
apply(subst bder_retrieve)
|
|
1898 |
apply (metis bders.simps(1) bders.simps(2) bders_append blexer_correctness blexer_def bnullable_correctness erase_bder erase_bders erase_intern lexer_correct_Some mkeps_nullable option.distinct(1))
|
|
1899 |
apply(subst bder_retrieve)
|
|
1900 |
apply (metis L_bders_simp L_bsimp_erase Posix_mkeps bders_simp.simps(1) bders_simp.simps(2) bders_simp_append blexer_correctness blexer_def bnullable_correctness erase_bder erase_bders erase_intern lexer.simps(1) lexer_correct_None lexer_correctness(2) mkeps_nullable)
|
|
1901 |
|
|
1902 |
apply(drule_tac x="bder a r" in meta_spec)
|
|
1903 |
apply(drule_tac meta_mp)
|
|
1904 |
apply (me tis erase_bder lexer.simps(2) lexer_correct_None option.simps(4))
|
|
1905 |
apply(simp)
|
|
1906 |
oops
|
|
1907 |
|
|
1908 |
|
|
1909 |
lemma
|
|
1910 |
shows "blexer r s = blexer_simp r s"
|
|
1911 |
apply(induct s arbitrary: r rule: rev_induct)
|
|
1912 |
apply(simp add: blexer_def blexer_simp_def)
|
|
1913 |
apply(case_tac "xs @ [x] \<in> L r")
|
|
1914 |
defer
|
|
1915 |
apply(subgoal_tac "blexer (ders xs r) [x] = None")
|
|
1916 |
prefer 2
|
|
1917 |
apply(subst blexer_correctness)
|
|
1918 |
apply(simp (no_asm) add: lexer_correct_None)
|
|
1919 |
apply(simp add: nullable_correctness)
|
|
1920 |
apply(simp add: der_correctness ders_correctness)
|
|
1921 |
apply(simp add: Der_def Ders_def)
|
|
1922 |
apply(subgoal_tac "blexer r (xs @ [x]) = None")
|
|
1923 |
prefer 2
|
|
1924 |
apply (simp add: blexer_correctness)
|
|
1925 |
using lexer_correct_None apply auto[1]
|
|
1926 |
apply(simp)
|
|
1927 |
apply(subgoal_tac "blexer_simp (ders xs r) [x] = None")
|
|
1928 |
prefer 2
|
|
1929 |
apply (metis L_bders_simp Posix_injval Posix_mkeps bders.simps(2) blexer_correctness blexer_simp_def bnullable_correctness ders.simps(1) erase_bder erase_bders erase_intern lexer_correct_None lexer_correctness(2))
|
|
1930 |
apply(subgoal_tac "[] \<notin> L (erase (bders_simp (intern r) (xs @ [x])))")
|
|
1931 |
prefer 2
|
|
1932 |
apply(metis L_bders_simp Posix_injval bders.simps(2) blexer_correctness ders.simps(1) ders_append erase_bder erase_bders erase_intern lexer_correct_None lexer_correctness(2))
|
|
1933 |
using blexer_simp_def bnullable_correctness lexer_correct_None apply auto[1]
|
|
1934 |
(* case xs @ [x] \<in> L r *)
|
|
1935 |
apply(subgoal_tac "\<exists>v. blexer (ders xs r) [x] = Some v \<and> [x] \<in> (ders xs r) \<rightarrow> v")
|
|
1936 |
prefer 2
|
|
1937 |
using blexer_correctness lexer_correct_Some apply auto[1]
|
|
1938 |
apply (simp add: Posix_injval Posix_mkeps)
|
|
1939 |
apply (metis ders.simps(1) ders.simps(2) ders_append lexer_correct_None lexer_flex)
|
|
1940 |
apply(clarify)
|
|
1941 |
apply(subgoal_tac "blexer_simp (ders xs r) [x] = Some v")
|
|
1942 |
prefer 2
|
|
1943 |
apply(simp add: blexer_simp_def)
|
|
1944 |
apply(auto)[1]
|
|
1945 |
apply (metis bders.simps(1) bders.simps(2) blexer_def bmkeps_simp option.simps(3))
|
|
1946 |
using b3 blexer_def apply fastforce
|
|
1947 |
apply(subgoal_tac "blexer_simp (ders xs r) [x] = blexer_simp r (xs @ [x])")
|
|
1948 |
prefer 2
|
|
1949 |
apply(simp add: blexer_simp_def)
|
|
1950 |
|
|
1951 |
apply(simp)
|
|
1952 |
|
|
1953 |
|
|
1954 |
|
|
1955 |
apply(simp)
|
|
1956 |
apply(subst blexer_simp_def)
|
|
1957 |
apply(simp)
|
|
1958 |
apply(auto)
|
|
1959 |
apply(drule_tac x="der a r" in meta_spec)
|
|
1960 |
apply(subst blexer_def)
|
|
1961 |
apply(subgoal_tac "bnullable (bders (intern r) (a # s))")
|
|
1962 |
prefer 2
|
|
1963 |
apply (metis Posix_injval blexer_correctness blexer_def lexer_correctness(2))
|
|
1964 |
apply(simp)
|
|
1965 |
|
|
1966 |
|
|
1967 |
|
|
1968 |
lemma
|
|
1969 |
shows "blexer r s = blexer_simp r s"
|
|
1970 |
apply(induct s arbitrary: r)
|
|
1971 |
apply(simp add: blexer_def blexer_simp_def)
|
|
1972 |
apply(case_tac "s \<in> L (der a r)")
|
|
1973 |
defer
|
|
1974 |
apply(subgoal_tac "blexer (der a r) s = None")
|
|
1975 |
prefer 2
|
|
1976 |
apply (simp add: blexer_correctness lexer_correct_None)
|
|
1977 |
apply(subgoal_tac "blexer r (a # s) = None")
|
|
1978 |
prefer 2
|
|
1979 |
apply (simp add: blexer_correctness)
|
|
1980 |
apply(simp)
|
|
1981 |
|
|
1982 |
apply(subst blexer_simp_def)
|
|
1983 |
apply(simp)
|
|
1984 |
apply(drule_tac x="der a r" in meta_spec)
|
|
1985 |
apply(subgoal_tac "s \<notin> L(erase (bder a (intern r)))")
|
|
1986 |
prefer 2
|
|
1987 |
apply simp
|
|
1988 |
|
|
1989 |
apply(simp only:)
|
|
1990 |
apply(subst blexer_simp_def)
|
|
1991 |
apply(subgoal_tac "\<not> bnullable (bders_simp (intern r) (a # s))")
|
|
1992 |
apply(simp)
|
|
1993 |
apply(subst bnullable_correctness[symmetric])
|
|
1994 |
apply(simp)
|
|
1995 |
|
|
1996 |
|
295
|
1997 |
|
148
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
1998 |
end |