64 |
64 |
65 lemma Der_Sequ [simp]: |
65 lemma Der_Sequ [simp]: |
66 shows "Der c (A ;; B) = (Der c A) ;; B \<union> (if [] \<in> A then Der c B else {})" |
66 shows "Der c (A ;; B) = (Der c A) ;; B \<union> (if [] \<in> A then Der c B else {})" |
67 unfolding Der_def Sequ_def |
67 unfolding Der_def Sequ_def |
68 by (auto simp add: Cons_eq_append_conv) |
68 by (auto simp add: Cons_eq_append_conv) |
69 |
|
70 lemma Der_inter [simp]: |
|
71 shows "Der c (A \<inter> B) = Der c A \<inter> Der c B" |
|
72 unfolding Der_def |
|
73 by auto |
|
74 |
69 |
75 lemma Der_union [simp]: |
70 lemma Der_union [simp]: |
76 shows "Der c (A \<union> B) = Der c A \<union> Der c B" |
71 shows "Der c (A \<union> B) = Der c A \<union> Der c B" |
77 unfolding Der_def |
72 unfolding Der_def |
78 by auto |
73 by auto |
241 | "L (UPNTIMES r n) = (\<Union>i\<in> {..n} . (L r) \<up> i)" |
232 | "L (UPNTIMES r n) = (\<Union>i\<in> {..n} . (L r) \<up> i)" |
242 | "L (NTIMES r n) = (L r) \<up> n" |
233 | "L (NTIMES r n) = (L r) \<up> n" |
243 | "L (FROMNTIMES r n) = (\<Union>i\<in> {n..} . (L r) \<up> i)" |
234 | "L (FROMNTIMES r n) = (\<Union>i\<in> {n..} . (L r) \<up> i)" |
244 | "L (NMTIMES r n m) = (\<Union>i\<in>{n..m} . (L r) \<up> i)" |
235 | "L (NMTIMES r n m) = (\<Union>i\<in>{n..m} . (L r) \<up> i)" |
245 | "L (PLUS r) = (\<Union>i\<in> {1..} . (L r) \<up> i)" |
236 | "L (PLUS r) = (\<Union>i\<in> {1..} . (L r) \<up> i)" |
246 | "L (AND r1 r2) = (L r1) \<inter> (L r2)" |
|
247 | "L (NOT r) = UNIV - (L r)" |
|
248 | "L (ALLL) = UNIV" |
|
249 | "L (ALLBUT) = UNIV - {[]}" |
|
250 |
237 |
251 section {* Nullable, Derivatives *} |
238 section {* Nullable, Derivatives *} |
252 |
239 |
253 fun |
240 fun |
254 nullable :: "rexp \<Rightarrow> bool" |
241 nullable :: "rexp \<Rightarrow> bool" |
262 | "nullable (UPNTIMES r n) = True" |
249 | "nullable (UPNTIMES r n) = True" |
263 | "nullable (NTIMES r n) = (if n = 0 then True else nullable r)" |
250 | "nullable (NTIMES r n) = (if n = 0 then True else nullable r)" |
264 | "nullable (FROMNTIMES r n) = (if n = 0 then True else nullable r)" |
251 | "nullable (FROMNTIMES r n) = (if n = 0 then True else nullable r)" |
265 | "nullable (NMTIMES r n m) = (if m < n then False else (if n = 0 then True else nullable r))" |
252 | "nullable (NMTIMES r n m) = (if m < n then False else (if n = 0 then True else nullable r))" |
266 | "nullable (PLUS r) = (nullable r)" |
253 | "nullable (PLUS r) = (nullable r)" |
267 | "nullable (AND r1 r2) = (nullable r1 \<and> nullable r2)" |
|
268 | "nullable (NOT r) = (\<not>nullable r)" |
|
269 | "nullable (ALLL) = True" |
|
270 | "nullable (ALLBUT) = False" |
|
271 |
|
272 |
254 |
273 fun |
255 fun |
274 der :: "char \<Rightarrow> rexp \<Rightarrow> rexp" |
256 der :: "char \<Rightarrow> rexp \<Rightarrow> rexp" |
275 where |
257 where |
276 "der c (ZERO) = ZERO" |
258 "der c (ZERO) = ZERO" |
292 (if m < n then ZERO |
274 (if m < n then ZERO |
293 else (if n = 0 then (if m = 0 then ZERO else |
275 else (if n = 0 then (if m = 0 then ZERO else |
294 SEQ (der c r) (UPNTIMES r (m - 1))) else |
276 SEQ (der c r) (UPNTIMES r (m - 1))) else |
295 SEQ (der c r) (NMTIMES r (n - 1) (m - 1))))" |
277 SEQ (der c r) (NMTIMES r (n - 1) (m - 1))))" |
296 | "der c (PLUS r) = SEQ (der c r) (STAR r)" |
278 | "der c (PLUS r) = SEQ (der c r) (STAR r)" |
297 | "der c (AND r1 r2) = AND (der c r1) (der c r2)" |
|
298 | "der c (NOT r) = NOT (der c r)" |
|
299 | "der c (ALLL) = ALLL" |
|
300 | "der c (ALLBUT) = ALLL" |
|
301 |
|
302 |
279 |
303 fun |
280 fun |
304 ders :: "string \<Rightarrow> rexp \<Rightarrow> rexp" |
281 ders :: "string \<Rightarrow> rexp \<Rightarrow> rexp" |
305 where |
282 where |
306 "ders [] r = r" |
283 "ders [] r = r" |
351 apply(case_tac "n \<le> m") |
328 apply(case_tac "n \<le> m") |
352 prefer 2 |
329 prefer 2 |
353 apply(simp only: der.simps if_True) |
330 apply(simp only: der.simps if_True) |
354 apply(simp only: L.simps) |
331 apply(simp only: L.simps) |
355 apply(simp) |
332 apply(simp) |
356 apply(auto)[3] |
333 apply(auto) |
357 apply(subst (asm) Sequ_UNION[symmetric]) |
334 apply(subst (asm) Sequ_UNION[symmetric]) |
358 apply(subst (asm) test[symmetric]) |
335 apply(subst (asm) test[symmetric]) |
359 apply(auto simp add: Der_UNION)[1] |
336 apply(auto simp add: Der_UNION)[1] |
360 apply(auto simp add: Der_UNION)[1] |
337 apply(auto simp add: Der_UNION)[1] |
361 apply(subst Sequ_UNION[symmetric]) |
338 apply(subst Sequ_UNION[symmetric]) |
376 apply(simp add: Der_UNION) |
353 apply(simp add: Der_UNION) |
377 apply(erule_tac bexE) |
354 apply(erule_tac bexE) |
378 apply(case_tac xa) |
355 apply(case_tac xa) |
379 apply(simp) |
356 apply(simp) |
380 apply(simp) |
357 apply(simp) |
381 apply(auto)[1] |
358 apply(auto) |
382 apply(auto simp add: Sequ_def Der_def)[1] |
359 apply(auto simp add: Sequ_def Der_def)[1] |
383 using Star_def apply auto[1] |
360 using Star_def apply auto[1] |
384 apply(case_tac "[] \<in> L r") |
361 apply(case_tac "[] \<in> L r") |
385 apply(auto)[1] |
362 apply(auto) |
386 using Der_UNION Der_star Star_def apply fastforce |
363 using Der_UNION Der_star Star_def by fastforce |
387 apply(simp) |
|
388 apply(simp) |
|
389 apply(simp add: Der_def) |
|
390 apply(blast) |
|
391 (* ALLL*) |
|
392 apply(simp add: Der_def) |
|
393 apply(simp add: Der_def) |
|
394 done |
|
395 |
364 |
396 lemma ders_correctness: |
365 lemma ders_correctness: |
397 shows "L (ders s r) = Ders s (L r)" |
366 shows "L (ders s r) = Ders s (L r)" |
398 apply(induct s arbitrary: r) |
367 apply(induct s arbitrary: r) |
399 apply(simp_all add: Ders_def der_correctness Der_def) |
368 apply(simp_all add: Ders_def der_correctness Der_def) |
448 | "flat (Left v) = flat v" |
414 | "flat (Left v) = flat v" |
449 | "flat (Right v) = flat v" |
415 | "flat (Right v) = flat v" |
450 | "flat (Seq v1 v2) = (flat v1) @ (flat v2)" |
416 | "flat (Seq v1 v2) = (flat v1) @ (flat v2)" |
451 | "flat (Stars []) = []" |
417 | "flat (Stars []) = []" |
452 | "flat (Stars (v#vs)) = (flat v) @ (flat (Stars vs))" |
418 | "flat (Stars (v#vs)) = (flat v) @ (flat (Stars vs))" |
453 | "flat (And v1 v2) = flat v1" |
|
454 | "flat (Not v) = flat v" |
|
455 | "flat Allbut = []" |
|
456 |
|
457 |
419 |
458 lemma flat_Stars [simp]: |
420 lemma flat_Stars [simp]: |
459 "flat (Stars vs) = concat (map flat vs)" |
421 "flat (Stars vs) = concat (map flat vs)" |
460 by (induct vs) (auto) |
422 by (induct vs) (auto) |
461 |
423 |
|
424 |
|
425 section {* Relation between values and regular expressions *} |
|
426 |
|
427 inductive |
|
428 Prf :: "val \<Rightarrow> rexp \<Rightarrow> bool" ("\<turnstile> _ : _" [100, 100] 100) |
|
429 where |
|
430 "\<lbrakk>\<turnstile> v1 : r1; \<turnstile> v2 : r2\<rbrakk> \<Longrightarrow> \<turnstile> Seq v1 v2 : SEQ r1 r2" |
|
431 | "\<turnstile> v1 : r1 \<Longrightarrow> \<turnstile> Left v1 : ALT r1 r2" |
|
432 | "\<turnstile> v2 : r2 \<Longrightarrow> \<turnstile> Right v2 : ALT r1 r2" |
|
433 | "\<turnstile> Void : ONE" |
|
434 | "\<turnstile> Char c : CHAR c" |
|
435 | "\<lbrakk>\<forall>v \<in> set vs. \<turnstile> v : r\<rbrakk> \<Longrightarrow> \<turnstile> Stars vs : STAR r" |
|
436 | "\<lbrakk>\<forall>v \<in> set vs. \<turnstile> v : r; length vs \<le> n\<rbrakk> \<Longrightarrow> \<turnstile> Stars vs : UPNTIMES r n" |
|
437 | "\<lbrakk>\<forall>v \<in> set vs. \<turnstile> v : r; length vs = n\<rbrakk> \<Longrightarrow> \<turnstile> Stars vs : NTIMES r n" |
|
438 | "\<lbrakk>\<forall>v \<in> set vs. \<turnstile> v : r; length vs \<ge> n\<rbrakk> \<Longrightarrow> \<turnstile> Stars vs : FROMNTIMES r n" |
|
439 | "\<lbrakk>\<forall>v \<in> set vs. \<turnstile> v : r; length vs \<ge> n; length vs \<le> m\<rbrakk> \<Longrightarrow> \<turnstile> Stars vs : NMTIMES r n m" |
|
440 | "\<lbrakk>\<forall>v \<in> set vs. \<turnstile> v : r; length vs \<ge> 1\<rbrakk> \<Longrightarrow> \<turnstile> Stars vs : PLUS r" |
|
441 |
|
442 |
|
443 inductive_cases Prf_elims: |
|
444 "\<turnstile> v : ZERO" |
|
445 "\<turnstile> v : SEQ r1 r2" |
|
446 "\<turnstile> v : ALT r1 r2" |
|
447 "\<turnstile> v : ONE" |
|
448 "\<turnstile> v : CHAR c" |
|
449 (* "\<turnstile> vs : STAR r"*) |
|
450 |
|
451 lemma Prf_STAR: |
|
452 assumes "\<forall>v\<in>set vs. \<turnstile> v : r \<and> flat v \<in> L r" |
|
453 shows "concat (map flat vs) \<in> L r\<star>" |
|
454 using assms |
|
455 apply(induct vs) |
|
456 apply(auto) |
|
457 done |
|
458 |
|
459 lemma Prf_Pow: |
|
460 assumes "\<forall>v\<in>set vs. \<turnstile> v : r \<and> flat v \<in> L r" |
|
461 shows "concat (map flat vs) \<in> L r \<up> length vs" |
|
462 using assms |
|
463 apply(induct vs) |
|
464 apply(auto simp add: Sequ_def) |
|
465 done |
|
466 |
|
467 lemma Prf_flat_L: |
|
468 assumes "\<turnstile> v : r" shows "flat v \<in> L r" |
|
469 using assms |
|
470 apply(induct v r rule: Prf.induct) |
|
471 apply(auto simp add: Sequ_def) |
|
472 apply(rule Prf_STAR) |
|
473 apply(simp) |
|
474 apply(rule_tac x="length vs" in bexI) |
|
475 apply(rule Prf_Pow) |
|
476 apply(simp) |
|
477 apply(simp) |
|
478 apply(rule Prf_Pow) |
|
479 apply(simp) |
|
480 apply(rule_tac x="length vs" in bexI) |
|
481 apply(rule Prf_Pow) |
|
482 apply(simp) |
|
483 apply(simp) |
|
484 apply(rule_tac x="length vs" in bexI) |
|
485 apply(rule Prf_Pow) |
|
486 apply(simp) |
|
487 apply(simp) |
|
488 using Prf_Pow by blast |
|
489 |
462 lemma Star_Pow: |
490 lemma Star_Pow: |
463 assumes "s \<in> A \<up> n" |
491 assumes "s \<in> A \<up> n" |
464 shows "\<exists>ss. concat ss = s \<and> (\<forall>s \<in> set ss. s \<in> A) \<and> (length ss = n)" |
492 shows "\<exists>ss. concat ss = s \<and> (\<forall>s \<in> set ss. s \<in> A) \<and> (length ss = n)" |
465 using assms |
493 using assms |
466 apply(induct n arbitrary: s) |
494 apply(induct n arbitrary: s) |
475 assumes "s \<in> A\<star>" |
503 assumes "s \<in> A\<star>" |
476 shows "\<exists>ss. concat ss = s \<and> (\<forall>s \<in> set ss. s \<in> A)" |
504 shows "\<exists>ss. concat ss = s \<and> (\<forall>s \<in> set ss. s \<in> A)" |
477 using assms |
505 using assms |
478 apply(auto simp add: Star_def) |
506 apply(auto simp add: Star_def) |
479 using Star_Pow by blast |
507 using Star_Pow by blast |
|
508 |
|
509 |
|
510 lemma Star_val: |
|
511 assumes "\<forall>s\<in>set ss. \<exists>v. s = flat v \<and> \<turnstile> v : r" |
|
512 shows "\<exists>vs. concat (map flat vs) = concat ss \<and> (\<forall>v\<in>set vs. \<turnstile> v : r)" |
|
513 using assms |
|
514 apply(induct ss) |
|
515 apply(auto) |
|
516 apply (metis empty_iff list.set(1)) |
|
517 by (metis concat.simps(2) list.simps(9) set_ConsD) |
|
518 |
|
519 lemma Star_val_length: |
|
520 assumes "\<forall>s\<in>set ss. \<exists>v. s = flat v \<and> \<turnstile> v : r" |
|
521 shows "\<exists>vs. concat (map flat vs) = concat ss \<and> (\<forall>v\<in>set vs. \<turnstile> v : r) \<and> (length vs) = (length ss)" |
|
522 using assms |
|
523 apply(induct ss) |
|
524 apply(auto) |
|
525 by (metis List.bind_def bind_simps(2) length_Suc_conv set_ConsD) |
|
526 |
|
527 |
|
528 |
|
529 |
|
530 |
|
531 lemma L_flat_Prf2: |
|
532 assumes "s \<in> L r" shows "\<exists>v. \<turnstile> v : r \<and> flat v = s" |
|
533 using assms |
|
534 apply(induct r arbitrary: s) |
|
535 apply(auto simp add: Sequ_def intro: Prf.intros) |
|
536 using Prf.intros(1) flat.simps(5) apply blast |
|
537 using Prf.intros(2) flat.simps(3) apply blast |
|
538 using Prf.intros(3) flat.simps(4) apply blast |
|
539 apply(subgoal_tac "\<exists>vs::val list. concat (map flat vs) = s \<and> (\<forall>v \<in> set vs. \<turnstile> v : r)") |
|
540 apply(auto)[1] |
|
541 apply(rule_tac x="Stars vs" in exI) |
|
542 apply(simp) |
|
543 apply(rule Prf.intros) |
|
544 apply(simp) |
|
545 using Star_string Star_val apply force |
|
546 apply(subgoal_tac "\<exists>vs::val list. concat (map flat vs) = s \<and> (\<forall>v \<in> set vs. \<turnstile> v : r) \<and> (length vs = x)") |
|
547 apply(auto)[1] |
|
548 apply(rule_tac x="Stars vs" in exI) |
|
549 apply(simp) |
|
550 apply(rule Prf.intros) |
|
551 apply(simp) |
|
552 apply(simp) |
|
553 using Star_Pow Star_val_length apply blast |
|
554 apply(subgoal_tac "\<exists>vs::val list. concat (map flat vs) = s \<and> (\<forall>v \<in> set vs. \<turnstile> v : r) \<and> (length vs = x2)") |
|
555 apply(auto)[1] |
|
556 apply(rule_tac x="Stars vs" in exI) |
|
557 apply(simp) |
|
558 apply(rule Prf.intros) |
|
559 apply(simp) |
|
560 apply(simp) |
|
561 using Star_Pow Star_val_length apply blast |
|
562 apply(subgoal_tac "\<exists>vs::val list. concat (map flat vs) = s \<and> (\<forall>v \<in> set vs. \<turnstile> v : r) \<and> (length vs = x)") |
|
563 apply(auto)[1] |
|
564 apply(rule_tac x="Stars vs" in exI) |
|
565 apply(simp) |
|
566 apply(rule Prf.intros) |
|
567 apply(simp) |
|
568 apply(simp) |
|
569 using Star_Pow Star_val_length apply blast |
|
570 apply(subgoal_tac "\<exists>vs::val list. concat (map flat vs) = s \<and> (\<forall>v \<in> set vs. \<turnstile> v : r) \<and> (length vs = x)") |
|
571 apply(auto)[1] |
|
572 apply(rule_tac x="Stars vs" in exI) |
|
573 apply(simp) |
|
574 apply(rule Prf.intros) |
|
575 apply(simp) |
|
576 apply(simp) |
|
577 apply(simp) |
|
578 using Star_Pow Star_val_length apply blast |
|
579 apply(subgoal_tac "\<exists>vs::val list. concat (map flat vs) = s \<and> (\<forall>v \<in> set vs. \<turnstile> v : r) \<and> (length vs = x)") |
|
580 apply(auto)[1] |
|
581 apply(rule_tac x="Stars vs" in exI) |
|
582 apply(simp) |
|
583 apply(rule Prf.intros) |
|
584 apply(simp) |
|
585 apply(simp) |
|
586 using Star_Pow Star_val_length apply blast |
|
587 done |
|
588 |
|
589 lemma L_flat_Prf: |
|
590 "L(r) = {flat v | v. \<turnstile> v : r}" |
|
591 using Prf_flat_L L_flat_Prf2 by blast |
480 |
592 |
481 |
593 |
482 section {* Sulzmann and Lu functions *} |
594 section {* Sulzmann and Lu functions *} |
483 |
595 |
484 fun |
596 fun |
491 | "mkeps(UPNTIMES r n) = Stars []" |
603 | "mkeps(UPNTIMES r n) = Stars []" |
492 | "mkeps(NTIMES r n) = Stars (replicate n (mkeps r))" |
604 | "mkeps(NTIMES r n) = Stars (replicate n (mkeps r))" |
493 | "mkeps(FROMNTIMES r n) = Stars (replicate n (mkeps r))" |
605 | "mkeps(FROMNTIMES r n) = Stars (replicate n (mkeps r))" |
494 | "mkeps(NMTIMES r n m) = Stars (replicate n (mkeps r))" |
606 | "mkeps(NMTIMES r n m) = Stars (replicate n (mkeps r))" |
495 | "mkeps(PLUS r) = Stars ([mkeps r])" |
607 | "mkeps(PLUS r) = Stars ([mkeps r])" |
496 | "mkeps(AND r1 r2) = And (mkeps r1) (mkeps r2)" |
|
497 | "mkeps(NOT r) = Not (Allbut)" |
|
498 | "mkeps(ALLL) = Void" |
|
499 |
608 |
500 |
609 |
501 fun injval :: "rexp \<Rightarrow> char \<Rightarrow> val \<Rightarrow> val" |
610 fun injval :: "rexp \<Rightarrow> char \<Rightarrow> val \<Rightarrow> val" |
502 where |
611 where |
503 "injval (CHAR d) c Void = Char d" |
612 "injval (CHAR d) c Void = Char d" |
510 | "injval (UPNTIMES r n) c (Seq v (Stars vs)) = Stars ((injval r c v) # vs)" |
619 | "injval (UPNTIMES r n) c (Seq v (Stars vs)) = Stars ((injval r c v) # vs)" |
511 | "injval (NTIMES r n) c (Seq v (Stars vs)) = Stars ((injval r c v) # vs)" |
620 | "injval (NTIMES r n) c (Seq v (Stars vs)) = Stars ((injval r c v) # vs)" |
512 | "injval (FROMNTIMES r n) c (Seq v (Stars vs)) = Stars ((injval r c v) # vs)" |
621 | "injval (FROMNTIMES r n) c (Seq v (Stars vs)) = Stars ((injval r c v) # vs)" |
513 | "injval (NMTIMES r n m) c (Seq v (Stars vs)) = Stars ((injval r c v) # vs)" |
622 | "injval (NMTIMES r n m) c (Seq v (Stars vs)) = Stars ((injval r c v) # vs)" |
514 | "injval (PLUS r) c (Seq v (Stars vs)) = Stars ((injval r c v) # vs)" |
623 | "injval (PLUS r) c (Seq v (Stars vs)) = Stars ((injval r c v) # vs)" |
515 | "injval (AND r1 r2) c (And v1 v2) = And (injval r1 c v1) (injval r2 c v2)" |
|
516 |
|
517 |
624 |
518 section {* Mkeps, injval *} |
625 section {* Mkeps, injval *} |
|
626 |
|
627 lemma mkeps_nullable: |
|
628 assumes "nullable(r)" |
|
629 shows "\<turnstile> mkeps r : r" |
|
630 using assms |
|
631 apply(induct r rule: mkeps.induct) |
|
632 apply(auto intro: Prf.intros) |
|
633 by (metis Prf.intros(10) in_set_replicate length_replicate not_le order_refl) |
519 |
634 |
520 lemma mkeps_flat: |
635 lemma mkeps_flat: |
521 assumes "nullable(r)" |
636 assumes "nullable(r)" |
522 shows "flat (mkeps r) = []" |
637 shows "flat (mkeps r) = []" |
523 using assms |
638 using assms |
524 apply (induct r) |
639 apply (induct rule: nullable.induct) |
525 apply(auto)[15] |
640 apply(auto) |
526 apply(case_tac "x3a < x2") |
641 by meson |
527 apply(auto)[2] |
642 |
528 done |
|
529 |
|
530 lemma Prf_injval_flat: |
|
531 assumes "flat v \<in> L (der c r)" |
|
532 shows "flat (injval r c v) = c # (flat v)" |
|
533 using assms |
|
534 apply(induct arbitrary: v rule: der.induct) |
|
535 apply(simp_all) |
|
536 apply(case_tac "c = d") |
|
537 prefer 2 |
|
538 apply(simp) |
|
539 apply(simp) |
|
540 apply(auto elim!: Prf_elims split: if_splits) |
|
541 apply(metis mkeps_flat) |
|
542 apply(rotate_tac 2) |
|
543 apply(erule Prf.cases) |
|
544 apply(simp_all) |
|
545 apply(rotate_tac 2) |
|
546 apply(erule Prf.cases) |
|
547 apply(simp_all) |
|
548 apply(rotate_tac 2) |
|
549 apply(erule Prf.cases) |
|
550 apply(simp_all) |
|
551 apply(rotate_tac 2) |
|
552 apply(erule Prf.cases) |
|
553 apply(simp_all) |
|
554 apply(rotate_tac 2) |
|
555 apply(erule Prf.cases) |
|
556 apply(simp_all) |
|
557 apply(rotate_tac 3) |
|
558 apply(erule Prf.cases) |
|
559 apply(simp_all) |
|
560 apply(rotate_tac 4) |
|
561 apply(erule Prf.cases) |
|
562 apply(simp_all) |
|
563 apply(rotate_tac 2) |
|
564 apply(erule Prf.cases) |
|
565 apply(simp_all) |
|
566 apply(rotate_tac 2) |
|
567 apply(erule Prf.cases) |
|
568 apply(simp_all) |
|
569 done |
|
570 |
643 |
571 lemma Prf_injval: |
644 lemma Prf_injval: |
572 assumes "\<turnstile> v : der c r" |
645 assumes "\<turnstile> v : der c r" |
573 shows "\<turnstile> (injval r c v) : r" |
646 shows "\<turnstile> (injval r c v) : r" |
574 using assms |
647 using assms |
645 apply(rotate_tac 2) |
718 apply(rotate_tac 2) |
646 apply(erule Prf.cases) |
719 apply(erule Prf.cases) |
647 apply(simp_all) |
720 apply(simp_all) |
648 apply(auto) |
721 apply(auto) |
649 using Prf.intros apply auto[1] |
722 using Prf.intros apply auto[1] |
650 (* AND *) |
723 done |
651 apply(erule Prf.cases) |
724 |
652 apply(simp_all) |
725 |
653 apply(auto) |
726 lemma Prf_injval_flat: |
654 apply(rule Prf.intros) |
727 assumes "\<turnstile> v : der c r" |
655 apply(simp) |
728 shows "flat (injval r c v) = c # (flat v)" |
656 apply(simp) |
729 using assms |
657 apply(simp add: Prf_injval_flat) |
730 apply(induct arbitrary: v rule: der.induct) |
658 done |
731 apply(auto elim!: Prf_elims split: if_splits) |
659 |
732 apply(metis mkeps_flat) |
660 |
733 apply(rotate_tac 2) |
661 |
734 apply(erule Prf.cases) |
|
735 apply(simp_all) |
|
736 apply(rotate_tac 2) |
|
737 apply(erule Prf.cases) |
|
738 apply(simp_all) |
|
739 apply(rotate_tac 2) |
|
740 apply(erule Prf.cases) |
|
741 apply(simp_all) |
|
742 apply(rotate_tac 2) |
|
743 apply(erule Prf.cases) |
|
744 apply(simp_all) |
|
745 apply(rotate_tac 2) |
|
746 apply(erule Prf.cases) |
|
747 apply(simp_all) |
|
748 apply(rotate_tac 3) |
|
749 apply(erule Prf.cases) |
|
750 apply(simp_all) |
|
751 apply(rotate_tac 4) |
|
752 apply(erule Prf.cases) |
|
753 apply(simp_all) |
|
754 apply(rotate_tac 2) |
|
755 apply(erule Prf.cases) |
|
756 apply(simp_all) |
|
757 done |
662 |
758 |
663 |
759 |
664 section {* Our Alternative Posix definition *} |
760 section {* Our Alternative Posix definition *} |
665 |
761 |
666 inductive |
762 inductive |
694 \<Longrightarrow> (s1 @ s2) \<in> NMTIMES r (Suc n) (Suc m) \<rightarrow> Stars (v # vs)" |
790 \<Longrightarrow> (s1 @ s2) \<in> NMTIMES r (Suc n) (Suc m) \<rightarrow> Stars (v # vs)" |
695 | Posix_NMTIMES2: "s \<in> UPNTIMES r m \<rightarrow> Stars vs \<Longrightarrow> s \<in> NMTIMES r 0 m \<rightarrow> Stars vs" |
791 | Posix_NMTIMES2: "s \<in> UPNTIMES r m \<rightarrow> Stars vs \<Longrightarrow> s \<in> NMTIMES r 0 m \<rightarrow> Stars vs" |
696 | Posix_PLUS1: "\<lbrakk>s1 \<in> r \<rightarrow> v; s2 \<in> STAR r \<rightarrow> Stars vs; flat v = [] \<Longrightarrow> flat (Stars vs) = []; |
792 | Posix_PLUS1: "\<lbrakk>s1 \<in> r \<rightarrow> v; s2 \<in> STAR r \<rightarrow> Stars vs; flat v = [] \<Longrightarrow> flat (Stars vs) = []; |
697 \<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> |
793 \<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> |
698 \<Longrightarrow> (s1 @ s2) \<in> PLUS r \<rightarrow> Stars (v # vs)" |
794 \<Longrightarrow> (s1 @ s2) \<in> PLUS r \<rightarrow> Stars (v # vs)" |
699 | Posix_AND: "\<lbrakk>s \<in> r1 \<rightarrow> v1; s \<in> r2 \<rightarrow> v2\<rbrakk> \<Longrightarrow> s \<in> (AND r1 r2) \<rightarrow> (And v1 v2)" |
|
700 |
795 |
701 inductive_cases Posix_elims: |
796 inductive_cases Posix_elims: |
702 "s \<in> ZERO \<rightarrow> v" |
797 "s \<in> ZERO \<rightarrow> v" |
703 "s \<in> ONE \<rightarrow> v" |
798 "s \<in> ONE \<rightarrow> v" |
704 "s \<in> CHAR c \<rightarrow> v" |
799 "s \<in> CHAR c \<rightarrow> v" |
1086 by (metis Posix1(1) Posix_PLUS1.hyps(6) append_self_conv append_self_conv2) |
1179 by (metis Posix1(1) Posix_PLUS1.hyps(6) append_self_conv append_self_conv2) |
1087 moreover |
1180 moreover |
1088 have IHs: "\<And>v2. s1 \<in> r \<rightarrow> v2 \<Longrightarrow> v = v2" |
1181 have IHs: "\<And>v2. s1 \<in> r \<rightarrow> v2 \<Longrightarrow> v = v2" |
1089 "\<And>v2. s2 \<in> STAR r \<rightarrow> v2 \<Longrightarrow> Stars vs = v2" by fact+ |
1182 "\<And>v2. s2 \<in> STAR r \<rightarrow> v2 \<Longrightarrow> Stars vs = v2" by fact+ |
1090 ultimately show "Stars (v # vs) = v2" by auto |
1183 ultimately show "Stars (v # vs) = v2" by auto |
1091 next |
|
1092 case (Posix_AND s r1 v1 r2 v2 v') |
|
1093 have "s \<in> AND r1 r2 \<rightarrow> v'" |
|
1094 "s \<in> r1 \<rightarrow> v1" "s \<in> r2 \<rightarrow> v2" by fact+ |
|
1095 then obtain v1' v2' where "v' = And v1' v2'" "s \<in> r1 \<rightarrow> v1'" "s \<in> r2 \<rightarrow> v2'" |
|
1096 apply(cases) apply (auto simp add: append_eq_append_conv2) |
|
1097 done |
|
1098 moreover |
|
1099 have IHs: "\<And>v1'. s \<in> r1 \<rightarrow> v1' \<Longrightarrow> v1 = v1'" |
|
1100 "\<And>v2'. s \<in> r2 \<rightarrow> v2' \<Longrightarrow> v2 = v2'" by fact+ |
|
1101 ultimately show "And v1 v2 = v'" by simp |
|
1102 qed |
1184 qed |
1103 |
1185 |
1104 lemma NTIMES_Stars: |
1186 lemma NTIMES_Stars: |
1105 assumes "\<turnstile> v : NTIMES r n" |
1187 assumes "\<turnstile> v : NTIMES r n" |
1106 shows "\<exists>vs. v = Stars vs \<and> (\<forall>v \<in> set vs. \<turnstile> v : r) \<and> length vs = n" |
1188 shows "\<exists>vs. v = Stars vs \<and> (\<forall>v \<in> set vs. \<turnstile> v : r) \<and> length vs = n" |