author | Christian Urban <urbanc@in.tum.de> |
Sat, 18 Aug 2018 01:54:44 +0100 | |
changeset 289 | 807acaf7f599 |
parent 287 | 95b3880d428f |
child 293 | 1a4e5b94293b |
permissions | -rw-r--r-- |
266 | 1 |
|
2 |
theory Spec |
|
267 | 3 |
imports Main "~~/src/HOL/Library/Sublist" |
266 | 4 |
begin |
5 |
||
6 |
section {* Sequential Composition of Languages *} |
|
7 |
||
8 |
definition |
|
9 |
Sequ :: "string set \<Rightarrow> string set \<Rightarrow> string set" ("_ ;; _" [100,100] 100) |
|
10 |
where |
|
11 |
"A ;; B = {s1 @ s2 | s1 s2. s1 \<in> A \<and> s2 \<in> B}" |
|
12 |
||
13 |
text {* Two Simple Properties about Sequential Composition *} |
|
14 |
||
15 |
lemma Sequ_empty_string [simp]: |
|
16 |
shows "A ;; {[]} = A" |
|
17 |
and "{[]} ;; A = A" |
|
18 |
by (simp_all add: Sequ_def) |
|
19 |
||
20 |
lemma Sequ_empty [simp]: |
|
21 |
shows "A ;; {} = {}" |
|
22 |
and "{} ;; A = {}" |
|
23 |
by (simp_all add: Sequ_def) |
|
24 |
||
25 |
||
26 |
section {* Semantic Derivative (Left Quotient) of Languages *} |
|
27 |
||
28 |
definition |
|
29 |
Der :: "char \<Rightarrow> string set \<Rightarrow> string set" |
|
30 |
where |
|
31 |
"Der c A \<equiv> {s. c # s \<in> A}" |
|
32 |
||
33 |
definition |
|
34 |
Ders :: "string \<Rightarrow> string set \<Rightarrow> string set" |
|
35 |
where |
|
36 |
"Ders s A \<equiv> {s'. s @ s' \<in> A}" |
|
37 |
||
38 |
lemma Der_null [simp]: |
|
39 |
shows "Der c {} = {}" |
|
40 |
unfolding Der_def |
|
41 |
by auto |
|
42 |
||
43 |
lemma Der_empty [simp]: |
|
44 |
shows "Der c {[]} = {}" |
|
45 |
unfolding Der_def |
|
46 |
by auto |
|
47 |
||
48 |
lemma Der_char [simp]: |
|
49 |
shows "Der c {[d]} = (if c = d then {[]} else {})" |
|
50 |
unfolding Der_def |
|
51 |
by auto |
|
52 |
||
53 |
lemma Der_union [simp]: |
|
54 |
shows "Der c (A \<union> B) = Der c A \<union> Der c B" |
|
55 |
unfolding Der_def |
|
56 |
by auto |
|
57 |
||
58 |
lemma Der_Sequ [simp]: |
|
59 |
shows "Der c (A ;; B) = (Der c A) ;; B \<union> (if [] \<in> A then Der c B else {})" |
|
60 |
unfolding Der_def Sequ_def |
|
61 |
by (auto simp add: Cons_eq_append_conv) |
|
62 |
||
63 |
||
64 |
section {* Kleene Star for Languages *} |
|
65 |
||
66 |
inductive_set |
|
67 |
Star :: "string set \<Rightarrow> string set" ("_\<star>" [101] 102) |
|
68 |
for A :: "string set" |
|
69 |
where |
|
70 |
start[intro]: "[] \<in> A\<star>" |
|
71 |
| step[intro]: "\<lbrakk>s1 \<in> A; s2 \<in> A\<star>\<rbrakk> \<Longrightarrow> s1 @ s2 \<in> A\<star>" |
|
72 |
||
73 |
(* Arden's lemma *) |
|
74 |
||
75 |
lemma Star_cases: |
|
76 |
shows "A\<star> = {[]} \<union> A ;; A\<star>" |
|
77 |
unfolding Sequ_def |
|
78 |
by (auto) (metis Star.simps) |
|
79 |
||
80 |
lemma Star_decomp: |
|
81 |
assumes "c # x \<in> A\<star>" |
|
82 |
shows "\<exists>s1 s2. x = s1 @ s2 \<and> c # s1 \<in> A \<and> s2 \<in> A\<star>" |
|
83 |
using assms |
|
84 |
by (induct x\<equiv>"c # x" rule: Star.induct) |
|
85 |
(auto simp add: append_eq_Cons_conv) |
|
86 |
||
87 |
lemma Star_Der_Sequ: |
|
88 |
shows "Der c (A\<star>) \<subseteq> (Der c A) ;; A\<star>" |
|
89 |
unfolding Der_def Sequ_def |
|
90 |
by(auto simp add: Star_decomp) |
|
91 |
||
92 |
||
93 |
lemma Der_star [simp]: |
|
94 |
shows "Der c (A\<star>) = (Der c A) ;; A\<star>" |
|
95 |
proof - |
|
96 |
have "Der c (A\<star>) = Der c ({[]} \<union> A ;; A\<star>)" |
|
97 |
by (simp only: Star_cases[symmetric]) |
|
98 |
also have "... = Der c (A ;; A\<star>)" |
|
99 |
by (simp only: Der_union Der_empty) (simp) |
|
100 |
also have "... = (Der c A) ;; A\<star> \<union> (if [] \<in> A then Der c (A\<star>) else {})" |
|
101 |
by simp |
|
102 |
also have "... = (Der c A) ;; A\<star>" |
|
103 |
using Star_Der_Sequ by auto |
|
104 |
finally show "Der c (A\<star>) = (Der c A) ;; A\<star>" . |
|
105 |
qed |
|
106 |
||
107 |
||
108 |
section {* Regular Expressions *} |
|
109 |
||
110 |
datatype rexp = |
|
111 |
ZERO |
|
112 |
| ONE |
|
113 |
| CHAR char |
|
114 |
| SEQ rexp rexp |
|
115 |
| ALT rexp rexp |
|
116 |
| STAR rexp |
|
117 |
||
118 |
section {* Semantics of Regular Expressions *} |
|
119 |
||
120 |
fun |
|
121 |
L :: "rexp \<Rightarrow> string set" |
|
122 |
where |
|
123 |
"L (ZERO) = {}" |
|
124 |
| "L (ONE) = {[]}" |
|
125 |
| "L (CHAR c) = {[c]}" |
|
126 |
| "L (SEQ r1 r2) = (L r1) ;; (L r2)" |
|
127 |
| "L (ALT r1 r2) = (L r1) \<union> (L r2)" |
|
128 |
| "L (STAR r) = (L r)\<star>" |
|
129 |
||
130 |
||
131 |
section {* Nullable, Derivatives *} |
|
132 |
||
133 |
fun |
|
134 |
nullable :: "rexp \<Rightarrow> bool" |
|
135 |
where |
|
136 |
"nullable (ZERO) = False" |
|
137 |
| "nullable (ONE) = True" |
|
138 |
| "nullable (CHAR c) = False" |
|
139 |
| "nullable (ALT r1 r2) = (nullable r1 \<or> nullable r2)" |
|
140 |
| "nullable (SEQ r1 r2) = (nullable r1 \<and> nullable r2)" |
|
141 |
| "nullable (STAR r) = True" |
|
142 |
||
143 |
||
144 |
fun |
|
145 |
der :: "char \<Rightarrow> rexp \<Rightarrow> rexp" |
|
146 |
where |
|
147 |
"der c (ZERO) = ZERO" |
|
148 |
| "der c (ONE) = ZERO" |
|
149 |
| "der c (CHAR d) = (if c = d then ONE else ZERO)" |
|
150 |
| "der c (ALT r1 r2) = ALT (der c r1) (der c r2)" |
|
151 |
| "der c (SEQ r1 r2) = |
|
152 |
(if nullable r1 |
|
153 |
then ALT (SEQ (der c r1) r2) (der c r2) |
|
154 |
else SEQ (der c r1) r2)" |
|
155 |
| "der c (STAR r) = SEQ (der c r) (STAR r)" |
|
156 |
||
157 |
fun |
|
158 |
ders :: "string \<Rightarrow> rexp \<Rightarrow> rexp" |
|
159 |
where |
|
160 |
"ders [] r = r" |
|
161 |
| "ders (c # s) r = ders s (der c r)" |
|
162 |
||
163 |
||
164 |
lemma nullable_correctness: |
|
165 |
shows "nullable r \<longleftrightarrow> [] \<in> (L r)" |
|
166 |
by (induct r) (auto simp add: Sequ_def) |
|
167 |
||
168 |
lemma der_correctness: |
|
169 |
shows "L (der c r) = Der c (L r)" |
|
170 |
by (induct r) (simp_all add: nullable_correctness) |
|
171 |
||
172 |
lemma ders_correctness: |
|
173 |
shows "L (ders s r) = Ders s (L r)" |
|
267 | 174 |
by (induct s arbitrary: r) |
175 |
(simp_all add: Ders_def der_correctness Der_def) |
|
176 |
||
287 | 177 |
lemma ders_append: |
178 |
shows "ders (s1 @ s2) r = ders s2 (ders s1 r)" |
|
179 |
apply(induct s1 arbitrary: s2 r) |
|
180 |
apply(auto) |
|
181 |
done |
|
266 | 182 |
|
183 |
||
184 |
section {* Values *} |
|
185 |
||
186 |
datatype val = |
|
187 |
Void |
|
188 |
| Char char |
|
189 |
| Seq val val |
|
190 |
| Right val |
|
191 |
| Left val |
|
192 |
| Stars "val list" |
|
193 |
||
194 |
||
195 |
section {* The string behind a value *} |
|
196 |
||
197 |
fun |
|
198 |
flat :: "val \<Rightarrow> string" |
|
199 |
where |
|
200 |
"flat (Void) = []" |
|
201 |
| "flat (Char c) = [c]" |
|
202 |
| "flat (Left v) = flat v" |
|
203 |
| "flat (Right v) = flat v" |
|
204 |
| "flat (Seq v1 v2) = (flat v1) @ (flat v2)" |
|
205 |
| "flat (Stars []) = []" |
|
206 |
| "flat (Stars (v#vs)) = (flat v) @ (flat (Stars vs))" |
|
207 |
||
267 | 208 |
abbreviation |
209 |
"flats vs \<equiv> concat (map flat vs)" |
|
210 |
||
266 | 211 |
lemma flat_Stars [simp]: |
267 | 212 |
"flat (Stars vs) = flats vs" |
266 | 213 |
by (induct vs) (auto) |
214 |
||
215 |
lemma Star_concat: |
|
216 |
assumes "\<forall>s \<in> set ss. s \<in> A" |
|
217 |
shows "concat ss \<in> A\<star>" |
|
218 |
using assms by (induct ss) (auto) |
|
219 |
||
268 | 220 |
lemma Star_cstring: |
266 | 221 |
assumes "s \<in> A\<star>" |
268 | 222 |
shows "\<exists>ss. concat ss = s \<and> (\<forall>s \<in> set ss. s \<in> A \<and> s \<noteq> [])" |
266 | 223 |
using assms |
224 |
apply(induct rule: Star.induct) |
|
268 | 225 |
apply(auto)[1] |
266 | 226 |
apply(rule_tac x="[]" in exI) |
227 |
apply(simp) |
|
268 | 228 |
apply(erule exE) |
229 |
apply(clarify) |
|
230 |
apply(case_tac "s1 = []") |
|
231 |
apply(rule_tac x="ss" in exI) |
|
232 |
apply(simp) |
|
266 | 233 |
apply(rule_tac x="s1#ss" in exI) |
234 |
apply(simp) |
|
235 |
done |
|
236 |
||
237 |
||
268 | 238 |
section {* Lexical Values *} |
266 | 239 |
|
240 |
inductive |
|
268 | 241 |
Prf :: "val \<Rightarrow> rexp \<Rightarrow> bool" ("\<Turnstile> _ : _" [100, 100] 100) |
266 | 242 |
where |
243 |
"\<lbrakk>\<Turnstile> v1 : r1; \<Turnstile> v2 : r2\<rbrakk> \<Longrightarrow> \<Turnstile> Seq v1 v2 : SEQ r1 r2" |
|
244 |
| "\<Turnstile> v1 : r1 \<Longrightarrow> \<Turnstile> Left v1 : ALT r1 r2" |
|
245 |
| "\<Turnstile> v2 : r2 \<Longrightarrow> \<Turnstile> Right v2 : ALT r1 r2" |
|
246 |
| "\<Turnstile> Void : ONE" |
|
247 |
| "\<Turnstile> Char c : CHAR c" |
|
248 |
| "\<forall>v \<in> set vs. \<Turnstile> v : r \<and> flat v \<noteq> [] \<Longrightarrow> \<Turnstile> Stars vs : STAR r" |
|
249 |
||
268 | 250 |
inductive_cases Prf_elims: |
251 |
"\<Turnstile> v : ZERO" |
|
252 |
"\<Turnstile> v : SEQ r1 r2" |
|
253 |
"\<Turnstile> v : ALT r1 r2" |
|
254 |
"\<Turnstile> v : ONE" |
|
255 |
"\<Turnstile> v : CHAR c" |
|
256 |
"\<Turnstile> vs : STAR r" |
|
266 | 257 |
|
268 | 258 |
lemma Prf_Stars_appendE: |
266 | 259 |
assumes "\<Turnstile> Stars (vs1 @ vs2) : STAR r" |
260 |
shows "\<Turnstile> Stars vs1 : STAR r \<and> \<Turnstile> Stars vs2 : STAR r" |
|
261 |
using assms |
|
268 | 262 |
by (auto intro: Prf.intros elim!: Prf_elims) |
263 |
||
264 |
||
265 |
lemma Star_cval: |
|
266 |
assumes "\<forall>s\<in>set ss. \<exists>v. s = flat v \<and> \<Turnstile> v : r" |
|
267 |
shows "\<exists>vs. flats vs = concat ss \<and> (\<forall>v\<in>set vs. \<Turnstile> v : r \<and> flat v \<noteq> [])" |
|
268 |
using assms |
|
269 |
apply(induct ss) |
|
270 |
apply(auto) |
|
271 |
apply(rule_tac x="[]" in exI) |
|
272 |
apply(simp) |
|
273 |
apply(case_tac "flat v = []") |
|
274 |
apply(rule_tac x="vs" in exI) |
|
275 |
apply(simp) |
|
276 |
apply(rule_tac x="v#vs" in exI) |
|
277 |
apply(simp) |
|
266 | 278 |
done |
279 |
||
267 | 280 |
|
268 | 281 |
lemma L_flat_Prf1: |
282 |
assumes "\<Turnstile> v : r" |
|
283 |
shows "flat v \<in> L r" |
|
284 |
using assms |
|
285 |
by (induct) (auto simp add: Sequ_def Star_concat) |
|
266 | 286 |
|
268 | 287 |
lemma L_flat_Prf2: |
288 |
assumes "s \<in> L r" |
|
289 |
shows "\<exists>v. \<Turnstile> v : r \<and> flat v = s" |
|
290 |
using assms |
|
291 |
proof(induct r arbitrary: s) |
|
292 |
case (STAR r s) |
|
293 |
have IH: "\<And>s. s \<in> L r \<Longrightarrow> \<exists>v. \<Turnstile> v : r \<and> flat v = s" by fact |
|
294 |
have "s \<in> L (STAR r)" by fact |
|
295 |
then obtain ss where "concat ss = s" "\<forall>s \<in> set ss. s \<in> L r \<and> s \<noteq> []" |
|
296 |
using Star_cstring by auto |
|
297 |
then obtain vs where "flats vs = s" "\<forall>v\<in>set vs. \<Turnstile> v : r \<and> flat v \<noteq> []" |
|
298 |
using IH Star_cval by metis |
|
299 |
then show "\<exists>v. \<Turnstile> v : STAR r \<and> flat v = s" |
|
300 |
using Prf.intros(6) flat_Stars by blast |
|
301 |
next |
|
302 |
case (SEQ r1 r2 s) |
|
303 |
then show "\<exists>v. \<Turnstile> v : SEQ r1 r2 \<and> flat v = s" |
|
304 |
unfolding Sequ_def L.simps by (fastforce intro: Prf.intros) |
|
305 |
next |
|
306 |
case (ALT r1 r2 s) |
|
307 |
then show "\<exists>v. \<Turnstile> v : ALT r1 r2 \<and> flat v = s" |
|
308 |
unfolding L.simps by (fastforce intro: Prf.intros) |
|
309 |
qed (auto intro: Prf.intros) |
|
310 |
||
311 |
||
312 |
lemma L_flat_Prf: |
|
313 |
shows "L(r) = {flat v | v. \<Turnstile> v : r}" |
|
314 |
using L_flat_Prf1 L_flat_Prf2 by blast |
|
315 |
||
316 |
||
317 |
||
318 |
section {* Sets of Lexical Values *} |
|
319 |
||
320 |
text {* |
|
321 |
Shows that lexical values are finite for a given regex and string. |
|
322 |
*} |
|
266 | 323 |
|
324 |
definition |
|
268 | 325 |
LV :: "rexp \<Rightarrow> string \<Rightarrow> val set" |
326 |
where "LV r s \<equiv> {v. \<Turnstile> v : r \<and> flat v = s}" |
|
267 | 327 |
|
268 | 328 |
lemma LV_simps: |
329 |
shows "LV ZERO s = {}" |
|
330 |
and "LV ONE s = (if s = [] then {Void} else {})" |
|
331 |
and "LV (CHAR c) s = (if s = [c] then {Char c} else {})" |
|
332 |
and "LV (ALT r1 r2) s = Left ` LV r1 s \<union> Right ` LV r2 s" |
|
333 |
unfolding LV_def |
|
334 |
by (auto intro: Prf.intros elim: Prf.cases) |
|
335 |
||
267 | 336 |
|
337 |
abbreviation |
|
274 | 338 |
"Prefixes s \<equiv> {s'. prefix s' s}" |
267 | 339 |
|
340 |
abbreviation |
|
274 | 341 |
"Suffixes s \<equiv> {s'. suffix s' s}" |
267 | 342 |
|
343 |
abbreviation |
|
274 | 344 |
"SSuffixes s \<equiv> {s'. strict_suffix s' s}" |
266 | 345 |
|
267 | 346 |
lemma Suffixes_cons [simp]: |
347 |
shows "Suffixes (c # s) = Suffixes s \<union> {c # s}" |
|
274 | 348 |
by (auto simp add: suffix_def Cons_eq_append_conv) |
267 | 349 |
|
350 |
||
351 |
lemma finite_Suffixes: |
|
352 |
shows "finite (Suffixes s)" |
|
353 |
by (induct s) (simp_all) |
|
266 | 354 |
|
267 | 355 |
lemma finite_SSuffixes: |
356 |
shows "finite (SSuffixes s)" |
|
357 |
proof - |
|
358 |
have "SSuffixes s \<subseteq> Suffixes s" |
|
274 | 359 |
unfolding strict_suffix_def suffix_def by auto |
267 | 360 |
then show "finite (SSuffixes s)" |
361 |
using finite_Suffixes finite_subset by blast |
|
362 |
qed |
|
363 |
||
364 |
lemma finite_Prefixes: |
|
365 |
shows "finite (Prefixes s)" |
|
366 |
proof - |
|
367 |
have "finite (Suffixes (rev s))" |
|
368 |
by (rule finite_Suffixes) |
|
369 |
then have "finite (rev ` Suffixes (rev s))" by simp |
|
370 |
moreover |
|
371 |
have "rev ` (Suffixes (rev s)) = Prefixes s" |
|
274 | 372 |
unfolding suffix_def prefix_def image_def |
267 | 373 |
by (auto)(metis rev_append rev_rev_ident)+ |
374 |
ultimately show "finite (Prefixes s)" by simp |
|
375 |
qed |
|
376 |
||
268 | 377 |
lemma LV_STAR_finite: |
378 |
assumes "\<forall>s. finite (LV r s)" |
|
379 |
shows "finite (LV (STAR r) s)" |
|
267 | 380 |
proof(induct s rule: length_induct) |
381 |
fix s::"char list" |
|
268 | 382 |
assume "\<forall>s'. length s' < length s \<longrightarrow> finite (LV (STAR r) s')" |
383 |
then have IH: "\<forall>s' \<in> SSuffixes s. finite (LV (STAR r) s')" |
|
279 | 384 |
by (force simp add: strict_suffix_def suffix_def) |
274 | 385 |
define f where "f \<equiv> \<lambda>(v, vs). Stars (v # vs)" |
386 |
define S1 where "S1 \<equiv> \<Union>s' \<in> Prefixes s. LV r s'" |
|
387 |
define S2 where "S2 \<equiv> \<Union>s2 \<in> SSuffixes s. Stars -` (LV (STAR r) s2)" |
|
267 | 388 |
have "finite S1" using assms |
389 |
unfolding S1_def by (simp_all add: finite_Prefixes) |
|
390 |
moreover |
|
391 |
with IH have "finite S2" unfolding S2_def |
|
392 |
by (auto simp add: finite_SSuffixes inj_on_def finite_vimageI) |
|
393 |
ultimately |
|
394 |
have "finite ({Stars []} \<union> f ` (S1 \<times> S2))" by simp |
|
395 |
moreover |
|
268 | 396 |
have "LV (STAR r) s \<subseteq> {Stars []} \<union> f ` (S1 \<times> S2)" |
397 |
unfolding S1_def S2_def f_def |
|
289 | 398 |
unfolding LV_def image_def prefix_def strict_suffix_def |
274 | 399 |
apply(auto) |
400 |
apply(case_tac x) |
|
268 | 401 |
apply(auto elim: Prf_elims) |
402 |
apply(erule Prf_elims) |
|
403 |
apply(auto) |
|
404 |
apply(case_tac vs) |
|
274 | 405 |
apply(auto intro: Prf.intros) |
406 |
apply(rule exI) |
|
407 |
apply(rule conjI) |
|
408 |
apply(rule_tac x="flat a" in exI) |
|
409 |
apply(rule conjI) |
|
410 |
apply(rule_tac x="flats list" in exI) |
|
411 |
apply(simp) |
|
279 | 412 |
apply(blast) |
413 |
apply(simp add: suffix_def) |
|
274 | 414 |
using Prf.intros(6) by blast |
267 | 415 |
ultimately |
268 | 416 |
show "finite (LV (STAR r) s)" by (simp add: finite_subset) |
267 | 417 |
qed |
418 |
||
419 |
||
268 | 420 |
lemma LV_finite: |
421 |
shows "finite (LV r s)" |
|
267 | 422 |
proof(induct r arbitrary: s) |
423 |
case (ZERO s) |
|
268 | 424 |
show "finite (LV ZERO s)" by (simp add: LV_simps) |
267 | 425 |
next |
426 |
case (ONE s) |
|
268 | 427 |
show "finite (LV ONE s)" by (simp add: LV_simps) |
267 | 428 |
next |
429 |
case (CHAR c s) |
|
268 | 430 |
show "finite (LV (CHAR c) s)" by (simp add: LV_simps) |
267 | 431 |
next |
432 |
case (ALT r1 r2 s) |
|
268 | 433 |
then show "finite (LV (ALT r1 r2) s)" by (simp add: LV_simps) |
267 | 434 |
next |
435 |
case (SEQ r1 r2 s) |
|
274 | 436 |
define f where "f \<equiv> \<lambda>(v1, v2). Seq v1 v2" |
437 |
define S1 where "S1 \<equiv> \<Union>s' \<in> Prefixes s. LV r1 s'" |
|
438 |
define S2 where "S2 \<equiv> \<Union>s' \<in> Suffixes s. LV r2 s'" |
|
268 | 439 |
have IHs: "\<And>s. finite (LV r1 s)" "\<And>s. finite (LV r2 s)" by fact+ |
267 | 440 |
then have "finite S1" "finite S2" unfolding S1_def S2_def |
441 |
by (simp_all add: finite_Prefixes finite_Suffixes) |
|
442 |
moreover |
|
268 | 443 |
have "LV (SEQ r1 r2) s \<subseteq> f ` (S1 \<times> S2)" |
444 |
unfolding f_def S1_def S2_def |
|
274 | 445 |
unfolding LV_def image_def prefix_def suffix_def |
446 |
apply (auto elim!: Prf_elims) |
|
447 |
by (metis (mono_tags, lifting) mem_Collect_eq) |
|
267 | 448 |
ultimately |
268 | 449 |
show "finite (LV (SEQ r1 r2) s)" |
267 | 450 |
by (simp add: finite_subset) |
451 |
next |
|
452 |
case (STAR r s) |
|
268 | 453 |
then show "finite (LV (STAR r) s)" by (simp add: LV_STAR_finite) |
267 | 454 |
qed |
455 |
||
456 |
||
266 | 457 |
|
458 |
section {* Our POSIX Definition *} |
|
459 |
||
460 |
inductive |
|
461 |
Posix :: "string \<Rightarrow> rexp \<Rightarrow> val \<Rightarrow> bool" ("_ \<in> _ \<rightarrow> _" [100, 100, 100] 100) |
|
462 |
where |
|
463 |
Posix_ONE: "[] \<in> ONE \<rightarrow> Void" |
|
464 |
| Posix_CHAR: "[c] \<in> (CHAR c) \<rightarrow> (Char c)" |
|
465 |
| Posix_ALT1: "s \<in> r1 \<rightarrow> v \<Longrightarrow> s \<in> (ALT r1 r2) \<rightarrow> (Left v)" |
|
466 |
| Posix_ALT2: "\<lbrakk>s \<in> r2 \<rightarrow> v; s \<notin> L(r1)\<rbrakk> \<Longrightarrow> s \<in> (ALT r1 r2) \<rightarrow> (Right v)" |
|
467 |
| Posix_SEQ: "\<lbrakk>s1 \<in> r1 \<rightarrow> v1; s2 \<in> r2 \<rightarrow> v2; |
|
468 |
\<not>(\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> (s1 @ s\<^sub>3) \<in> L r1 \<and> s\<^sub>4 \<in> L r2)\<rbrakk> \<Longrightarrow> |
|
469 |
(s1 @ s2) \<in> (SEQ r1 r2) \<rightarrow> (Seq v1 v2)" |
|
470 |
| Posix_STAR1: "\<lbrakk>s1 \<in> r \<rightarrow> v; s2 \<in> STAR r \<rightarrow> Stars vs; flat v \<noteq> []; |
|
471 |
\<not>(\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> (s1 @ s\<^sub>3) \<in> L r \<and> s\<^sub>4 \<in> L (STAR r))\<rbrakk> |
|
472 |
\<Longrightarrow> (s1 @ s2) \<in> STAR r \<rightarrow> Stars (v # vs)" |
|
473 |
| Posix_STAR2: "[] \<in> STAR r \<rightarrow> Stars []" |
|
474 |
||
475 |
inductive_cases Posix_elims: |
|
476 |
"s \<in> ZERO \<rightarrow> v" |
|
477 |
"s \<in> ONE \<rightarrow> v" |
|
478 |
"s \<in> CHAR c \<rightarrow> v" |
|
479 |
"s \<in> ALT r1 r2 \<rightarrow> v" |
|
480 |
"s \<in> SEQ r1 r2 \<rightarrow> v" |
|
481 |
"s \<in> STAR r \<rightarrow> v" |
|
482 |
||
483 |
lemma Posix1: |
|
484 |
assumes "s \<in> r \<rightarrow> v" |
|
485 |
shows "s \<in> L r" "flat v = s" |
|
486 |
using assms |
|
487 |
by (induct s r v rule: Posix.induct) |
|
488 |
(auto simp add: Sequ_def) |
|
489 |
||
490 |
text {* |
|
491 |
Our Posix definition determines a unique value. |
|
492 |
*} |
|
493 |
||
494 |
lemma Posix_determ: |
|
495 |
assumes "s \<in> r \<rightarrow> v1" "s \<in> r \<rightarrow> v2" |
|
496 |
shows "v1 = v2" |
|
497 |
using assms |
|
498 |
proof (induct s r v1 arbitrary: v2 rule: Posix.induct) |
|
499 |
case (Posix_ONE v2) |
|
500 |
have "[] \<in> ONE \<rightarrow> v2" by fact |
|
501 |
then show "Void = v2" by cases auto |
|
502 |
next |
|
503 |
case (Posix_CHAR c v2) |
|
504 |
have "[c] \<in> CHAR c \<rightarrow> v2" by fact |
|
505 |
then show "Char c = v2" by cases auto |
|
506 |
next |
|
507 |
case (Posix_ALT1 s r1 v r2 v2) |
|
508 |
have "s \<in> ALT r1 r2 \<rightarrow> v2" by fact |
|
509 |
moreover |
|
510 |
have "s \<in> r1 \<rightarrow> v" by fact |
|
511 |
then have "s \<in> L r1" by (simp add: Posix1) |
|
512 |
ultimately obtain v' where eq: "v2 = Left v'" "s \<in> r1 \<rightarrow> v'" by cases auto |
|
513 |
moreover |
|
514 |
have IH: "\<And>v2. s \<in> r1 \<rightarrow> v2 \<Longrightarrow> v = v2" by fact |
|
515 |
ultimately have "v = v'" by simp |
|
516 |
then show "Left v = v2" using eq by simp |
|
517 |
next |
|
518 |
case (Posix_ALT2 s r2 v r1 v2) |
|
519 |
have "s \<in> ALT r1 r2 \<rightarrow> v2" by fact |
|
520 |
moreover |
|
521 |
have "s \<notin> L r1" by fact |
|
522 |
ultimately obtain v' where eq: "v2 = Right v'" "s \<in> r2 \<rightarrow> v'" |
|
523 |
by cases (auto simp add: Posix1) |
|
524 |
moreover |
|
525 |
have IH: "\<And>v2. s \<in> r2 \<rightarrow> v2 \<Longrightarrow> v = v2" by fact |
|
526 |
ultimately have "v = v'" by simp |
|
527 |
then show "Right v = v2" using eq by simp |
|
528 |
next |
|
529 |
case (Posix_SEQ s1 r1 v1 s2 r2 v2 v') |
|
530 |
have "(s1 @ s2) \<in> SEQ r1 r2 \<rightarrow> v'" |
|
531 |
"s1 \<in> r1 \<rightarrow> v1" "s2 \<in> r2 \<rightarrow> v2" |
|
532 |
"\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> s1 @ s\<^sub>3 \<in> L r1 \<and> s\<^sub>4 \<in> L r2)" by fact+ |
|
533 |
then obtain v1' v2' where "v' = Seq v1' v2'" "s1 \<in> r1 \<rightarrow> v1'" "s2 \<in> r2 \<rightarrow> v2'" |
|
534 |
apply(cases) apply (auto simp add: append_eq_append_conv2) |
|
535 |
using Posix1(1) by fastforce+ |
|
536 |
moreover |
|
537 |
have IHs: "\<And>v1'. s1 \<in> r1 \<rightarrow> v1' \<Longrightarrow> v1 = v1'" |
|
538 |
"\<And>v2'. s2 \<in> r2 \<rightarrow> v2' \<Longrightarrow> v2 = v2'" by fact+ |
|
539 |
ultimately show "Seq v1 v2 = v'" by simp |
|
540 |
next |
|
541 |
case (Posix_STAR1 s1 r v s2 vs v2) |
|
542 |
have "(s1 @ s2) \<in> STAR r \<rightarrow> v2" |
|
543 |
"s1 \<in> r \<rightarrow> v" "s2 \<in> STAR r \<rightarrow> Stars vs" "flat v \<noteq> []" |
|
544 |
"\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> s1 @ s\<^sub>3 \<in> L r \<and> s\<^sub>4 \<in> L (STAR r))" by fact+ |
|
545 |
then obtain v' vs' where "v2 = Stars (v' # vs')" "s1 \<in> r \<rightarrow> v'" "s2 \<in> (STAR r) \<rightarrow> (Stars vs')" |
|
546 |
apply(cases) apply (auto simp add: append_eq_append_conv2) |
|
547 |
using Posix1(1) apply fastforce |
|
548 |
apply (metis Posix1(1) Posix_STAR1.hyps(6) append_Nil append_Nil2) |
|
549 |
using Posix1(2) by blast |
|
550 |
moreover |
|
551 |
have IHs: "\<And>v2. s1 \<in> r \<rightarrow> v2 \<Longrightarrow> v = v2" |
|
552 |
"\<And>v2. s2 \<in> STAR r \<rightarrow> v2 \<Longrightarrow> Stars vs = v2" by fact+ |
|
553 |
ultimately show "Stars (v # vs) = v2" by auto |
|
554 |
next |
|
555 |
case (Posix_STAR2 r v2) |
|
556 |
have "[] \<in> STAR r \<rightarrow> v2" by fact |
|
557 |
then show "Stars [] = v2" by cases (auto simp add: Posix1) |
|
558 |
qed |
|
559 |
||
560 |
||
561 |
text {* |
|
289 | 562 |
Our POSIX values are lexical values. |
266 | 563 |
*} |
564 |
||
268 | 565 |
lemma Posix_LV: |
266 | 566 |
assumes "s \<in> r \<rightarrow> v" |
268 | 567 |
shows "v \<in> LV r s" |
289 | 568 |
using assms unfolding LV_def |
569 |
apply(induct rule: Posix.induct) |
|
570 |
apply(auto simp add: intro!: Prf.intros elim!: Prf_elims) |
|
571 |
done |
|
266 | 572 |
|
289 | 573 |
lemma Posix_Prf: |
574 |
assumes "s \<in> r \<rightarrow> v" |
|
575 |
shows "\<Turnstile> v : r" |
|
576 |
using assms Posix_LV LV_def |
|
577 |
by simp |
|
286
804fbb227568
added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents:
279
diff
changeset
|
578 |
|
266 | 579 |
end |