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