348 assumes "\<Turnstile> v : r" |
351 assumes "\<Turnstile> v : r" |
349 shows "\<turnstile> v : r" |
352 shows "\<turnstile> v : r" |
350 using assms |
353 using assms |
351 by (induct)(auto intro: Prf.intros) |
354 by (induct)(auto intro: Prf.intros) |
352 |
355 |
353 lemma CPrf_stars: |
|
354 assumes "\<Turnstile> Stars vs : STAR r" |
|
355 shows "\<forall>v \<in> set vs. flat v \<noteq> [] \<and> \<Turnstile> v : r" |
|
356 using assms |
|
357 apply(erule_tac CPrf.cases) |
|
358 apply(simp_all) |
|
359 done |
|
360 |
|
361 lemma CPrf_Stars_appendE: |
356 lemma CPrf_Stars_appendE: |
362 assumes "\<Turnstile> Stars (vs1 @ vs2) : STAR r" |
357 assumes "\<Turnstile> Stars (vs1 @ vs2) : STAR r" |
363 shows "\<Turnstile> Stars vs1 : STAR r \<and> \<Turnstile> Stars vs2 : STAR r" |
358 shows "\<Turnstile> Stars vs1 : STAR r \<and> \<Turnstile> Stars vs2 : STAR r" |
364 using assms |
359 using assms |
365 apply(erule_tac CPrf.cases) |
360 apply(erule_tac CPrf.cases) |
366 apply(auto intro: CPrf.intros elim: Prf.cases) |
361 apply(auto intro: CPrf.intros) |
367 done |
362 done |
368 |
363 |
369 definition PT :: "rexp \<Rightarrow> string \<Rightarrow> val set" |
364 |
370 where "PT r s \<equiv> {v. flat v = s \<and> \<turnstile> v : r}" |
365 section {* Sets of Lexical and Canonical Values *} |
|
366 |
|
367 definition |
|
368 LV :: "rexp \<Rightarrow> string \<Rightarrow> val set" |
|
369 where "LV r s \<equiv> {v. \<turnstile> v : r \<and> flat v = s}" |
371 |
370 |
372 definition |
371 definition |
373 "CPT r s = {v. flat v = s \<and> \<Turnstile> v : r}" |
372 CV :: "rexp \<Rightarrow> string \<Rightarrow> val set" |
374 |
373 where "CV r s \<equiv> {v. \<Turnstile> v : r \<and> flat v = s}" |
375 definition |
374 |
376 "CPTpre r s = {v. \<exists>s'. flat v @ s' = s \<and> \<Turnstile> v : r}" |
375 lemma LV_CV_subset: |
377 |
376 shows "CV r s \<subseteq> LV r s" |
378 lemma CPT_CPTpre_subset: |
377 unfolding CV_def LV_def by(auto simp add: Prf_CPrf) |
379 shows "CPT r s \<subseteq> CPTpre r s" |
378 |
380 by(auto simp add: CPT_def CPTpre_def) |
379 abbreviation |
381 |
380 "Prefixes s \<equiv> {s'. prefixeq s' s}" |
382 lemma CPT_simps: |
381 |
383 shows "CPT ZERO s = {}" |
382 abbreviation |
384 and "CPT ONE s = (if s = [] then {Void} else {})" |
383 "Suffixes s \<equiv> {s'. suffixeq s' s}" |
385 and "CPT (CHAR c) s = (if s = [c] then {Char c} else {})" |
384 |
386 and "CPT (ALT r1 r2) s = Left ` CPT r1 s \<union> Right ` CPT r2 s" |
385 abbreviation |
387 and "CPT (SEQ r1 r2) s = |
386 "SSuffixes s \<equiv> {s'. suffix s' s}" |
388 {Seq v1 v2 | v1 v2. flat v1 @ flat v2 = s \<and> v1 \<in> CPT r1 (flat v1) \<and> v2 \<in> CPT r2 (flat v2)}" |
387 |
389 and "CPT (STAR r) s = |
388 lemma Suffixes_cons [simp]: |
390 Stars ` {vs. concat (map flat vs) = s \<and> (\<forall>v \<in> set vs. v \<in> CPT r (flat v) \<and> flat v \<noteq> [])}" |
389 shows "Suffixes (c # s) = Suffixes s \<union> {c # s}" |
391 apply - |
390 by (auto simp add: suffixeq_def Cons_eq_append_conv) |
392 apply(auto simp add: CPT_def intro: CPrf.intros)[1] |
391 |
|
392 lemma CV_simps: |
|
393 shows "CV ZERO s = {}" |
|
394 and "CV ONE s = (if s = [] then {Void} else {})" |
|
395 and "CV (CHAR c) s = (if s = [c] then {Char c} else {})" |
|
396 and "CV (ALT r1 r2) s = Left ` CV r1 s \<union> Right ` CV r2 s" |
|
397 unfolding CV_def |
|
398 by (auto intro: CPrf.intros elim: CPrf.cases) |
|
399 |
|
400 lemma finite_Suffixes: |
|
401 shows "finite (Suffixes s)" |
|
402 by (induct s) (simp_all) |
|
403 |
|
404 lemma finite_SSuffixes: |
|
405 shows "finite (SSuffixes s)" |
|
406 proof - |
|
407 have "SSuffixes s \<subseteq> Suffixes s" |
|
408 unfolding suffix_def suffixeq_def by auto |
|
409 then show "finite (SSuffixes s)" |
|
410 using finite_Suffixes finite_subset by blast |
|
411 qed |
|
412 |
|
413 lemma finite_Prefixes: |
|
414 shows "finite (Prefixes s)" |
|
415 proof - |
|
416 have "finite (Suffixes (rev s))" |
|
417 by (rule finite_Suffixes) |
|
418 then have "finite (rev ` Suffixes (rev s))" by simp |
|
419 moreover |
|
420 have "rev ` (Suffixes (rev s)) = Prefixes s" |
|
421 unfolding suffixeq_def prefixeq_def image_def |
|
422 by (auto)(metis rev_append rev_rev_ident)+ |
|
423 ultimately show "finite (Prefixes s)" by simp |
|
424 qed |
|
425 |
|
426 lemma CV_SEQ_subset: |
|
427 "CV (SEQ r1 r2) s \<subseteq> (\<lambda>(v1,v2). Seq v1 v2) ` ((\<Union>s' \<in> Prefixes s. CV r1 s') \<times> (\<Union>s' \<in> Suffixes s. CV r2 s'))" |
|
428 unfolding image_def CV_def prefixeq_def suffixeq_def |
|
429 by (auto elim: CPrf.cases) |
|
430 |
|
431 lemma CV_STAR_subset: |
|
432 "CV (STAR r) s \<subseteq> {Stars []} \<union> |
|
433 (\<lambda>(v,vs). Stars (v#vs)) ` ((\<Union>s' \<in> Prefixes s. CV r s') \<times> (\<Union>s2 \<in> SSuffixes s. Stars -` (CV (STAR r) s2)))" |
|
434 unfolding image_def CV_def prefixeq_def suffix_def |
|
435 apply(auto) |
393 apply(erule CPrf.cases) |
436 apply(erule CPrf.cases) |
394 apply(simp_all)[6] |
437 apply(auto) |
395 apply(auto simp add: CPT_def intro: CPrf.intros)[1] |
438 apply(case_tac vs) |
396 apply(erule CPrf.cases) |
439 apply(auto intro: CPrf.intros) |
397 apply(simp_all)[6] |
440 done |
398 apply(erule CPrf.cases) |
441 |
399 apply(simp_all)[6] |
442 |
400 apply(auto simp add: CPT_def intro: CPrf.intros)[1] |
443 lemma CV_STAR_finite: |
401 apply(erule CPrf.cases) |
444 assumes "\<forall>s. finite (CV r s)" |
402 apply(simp_all)[6] |
445 shows "finite (CV (STAR r) s)" |
403 apply(erule CPrf.cases) |
446 proof(induct s rule: length_induct) |
404 apply(simp_all)[6] |
447 fix s::"char list" |
405 apply(auto simp add: CPT_def intro: CPrf.intros)[1] |
448 assume "\<forall>s'. length s' < length s \<longrightarrow> finite (CV (STAR r) s')" |
406 apply(erule CPrf.cases) |
449 then have IH: "\<forall>s' \<in> SSuffixes s. finite (CV (STAR r) s')" |
407 apply(simp_all)[6] |
450 by (auto simp add: suffix_def) |
408 apply(auto simp add: CPT_def intro: CPrf.intros)[1] |
451 def f \<equiv> "\<lambda>(v, vs). Stars (v # vs)" |
409 apply(erule CPrf.cases) |
452 def S1 \<equiv> "\<Union>s' \<in> Prefixes s. CV r s'" |
410 apply(simp_all)[6] |
453 def S2 \<equiv> "\<Union>s2 \<in> SSuffixes s. Stars -` (CV (STAR r) s2)" |
411 (* STAR case *) |
454 have "finite S1" using assms |
412 apply(auto simp add: CPT_def intro: CPrf.intros)[1] |
455 unfolding S1_def by (simp_all add: finite_Prefixes) |
413 apply(erule CPrf.cases) |
456 moreover |
414 apply(simp_all)[6] |
457 with IH have "finite S2" unfolding S2_def |
415 done |
458 by (auto simp add: finite_SSuffixes inj_on_def finite_vimageI) |
|
459 ultimately |
|
460 have "finite ({Stars []} \<union> f ` (S1 \<times> S2))" by simp |
|
461 moreover |
|
462 have "CV (STAR r) s \<subseteq> {Stars []} \<union> f ` (S1 \<times> S2)" unfolding S1_def S2_def f_def |
|
463 by (rule CV_STAR_subset) |
|
464 ultimately |
|
465 show "finite (CV (STAR r) s)" by (simp add: finite_subset) |
|
466 qed |
|
467 |
|
468 |
|
469 lemma CV_finite: |
|
470 shows "finite (CV r s)" |
|
471 proof(induct r arbitrary: s) |
|
472 case (ZERO s) |
|
473 show "finite (CV ZERO s)" by (simp add: CV_simps) |
|
474 next |
|
475 case (ONE s) |
|
476 show "finite (CV ONE s)" by (simp add: CV_simps) |
|
477 next |
|
478 case (CHAR c s) |
|
479 show "finite (CV (CHAR c) s)" by (simp add: CV_simps) |
|
480 next |
|
481 case (ALT r1 r2 s) |
|
482 then show "finite (CV (ALT r1 r2) s)" by (simp add: CV_simps) |
|
483 next |
|
484 case (SEQ r1 r2 s) |
|
485 def f \<equiv> "\<lambda>(v1, v2). Seq v1 v2" |
|
486 def S1 \<equiv> "\<Union>s' \<in> Prefixes s. CV r1 s'" |
|
487 def S2 \<equiv> "\<Union>s' \<in> Suffixes s. CV r2 s'" |
|
488 have IHs: "\<And>s. finite (CV r1 s)" "\<And>s. finite (CV r2 s)" by fact+ |
|
489 then have "finite S1" "finite S2" unfolding S1_def S2_def |
|
490 by (simp_all add: finite_Prefixes finite_Suffixes) |
|
491 moreover |
|
492 have "CV (SEQ r1 r2) s \<subseteq> f ` (S1 \<times> S2)" |
|
493 unfolding f_def S1_def S2_def by (auto simp add: CV_SEQ_subset) |
|
494 ultimately |
|
495 show "finite (CV (SEQ r1 r2) s)" |
|
496 by (simp add: finite_subset) |
|
497 next |
|
498 case (STAR r s) |
|
499 then show "finite (CV (STAR r) s)" by (simp add: CV_STAR_finite) |
|
500 qed |
416 |
501 |
417 |
502 |
418 |
503 |
419 section {* Our POSIX Definition *} |
504 section {* Our POSIX Definition *} |
420 |
505 |
529 |
614 |
530 text {* |
615 text {* |
531 Our POSIX value is a canonical value. |
616 Our POSIX value is a canonical value. |
532 *} |
617 *} |
533 |
618 |
534 lemma Posix_CPT: |
619 lemma Posix_CV: |
535 assumes "s \<in> r \<rightarrow> v" |
620 assumes "s \<in> r \<rightarrow> v" |
536 shows "v \<in> CPT r s" |
621 shows "v \<in> CV r s" |
537 using assms |
622 using assms |
538 apply(induct rule: Posix.induct) |
623 apply(induct rule: Posix.induct) |
539 apply(auto simp add: CPT_def intro: CPrf.intros elim: CPrf.cases) |
624 apply(auto simp add: CV_def intro: CPrf.intros elim: CPrf.cases) |
540 apply(rotate_tac 5) |
625 apply(rotate_tac 5) |
541 apply(erule CPrf.cases) |
626 apply(erule CPrf.cases) |
542 apply(simp_all) |
627 apply(simp_all) |
543 apply(rule CPrf.intros) |
628 apply(rule CPrf.intros) |
544 apply(simp_all) |
629 apply(simp_all) |
545 done |
630 done |
546 |
631 |
547 |
|
548 |
|
549 (* |
|
550 lemma CPTpre_STAR_finite: |
|
551 assumes "\<And>s. finite (CPT r s)" |
|
552 shows "finite (CPT (STAR r) s)" |
|
553 apply(induct s rule: length_induct) |
|
554 apply(case_tac xs) |
|
555 apply(simp) |
|
556 apply(simp add: CPT_simps) |
|
557 apply(auto) |
|
558 apply(rule finite_imageI) |
|
559 using assms |
|
560 thm finite_Un |
|
561 prefer 2 |
|
562 apply(simp add: CPT_simps) |
|
563 apply(rule finite_imageI) |
|
564 apply(rule finite_subset) |
|
565 apply(rule CPTpre_subsets) |
|
566 apply(simp) |
|
567 apply(rule_tac B="(\<lambda>(v, vs). Stars (v#vs)) ` {(v, vs). v \<in> CPTpre r (a#list) \<and> flat v \<noteq> [] \<and> Stars vs \<in> CPTpre (STAR r) (drop (length (flat v)) (a#list))}" in finite_subset) |
|
568 apply(auto)[1] |
|
569 apply(rule finite_imageI) |
|
570 apply(simp add: Collect_case_prod_Sigma) |
|
571 apply(rule finite_SigmaI) |
|
572 apply(rule assms) |
|
573 apply(case_tac "flat v = []") |
|
574 apply(simp) |
|
575 apply(drule_tac x="drop (length (flat v)) (a # list)" in spec) |
|
576 apply(simp) |
|
577 apply(auto)[1] |
|
578 apply(rule test) |
|
579 apply(simp) |
|
580 done |
|
581 |
|
582 lemma CPTpre_subsets: |
|
583 "CPTpre ZERO s = {}" |
|
584 "CPTpre ONE s \<subseteq> {Void}" |
|
585 "CPTpre (CHAR c) s \<subseteq> {Char c}" |
|
586 "CPTpre (ALT r1 r2) s \<subseteq> Left ` CPTpre r1 s \<union> Right ` CPTpre r2 s" |
|
587 "CPTpre (SEQ r1 r2) s \<subseteq> {Seq v1 v2 | v1 v2. v1 \<in> CPTpre r1 s \<and> v2 \<in> CPTpre r2 (drop (length (flat v1)) s)}" |
|
588 "CPTpre (STAR r) s \<subseteq> {Stars []} \<union> |
|
589 {Stars (v#vs) | v vs. v \<in> CPTpre r s \<and> flat v \<noteq> [] \<and> Stars vs \<in> CPTpre (STAR r) (drop (length (flat v)) s)}" |
|
590 "CPTpre (STAR r) [] = {Stars []}" |
|
591 apply(auto simp add: CPTpre_def) |
|
592 apply(erule CPrf.cases) |
|
593 apply(simp_all) |
|
594 apply(erule CPrf.cases) |
|
595 apply(simp_all) |
|
596 apply(erule CPrf.cases) |
|
597 apply(simp_all) |
|
598 apply(erule CPrf.cases) |
|
599 apply(simp_all) |
|
600 apply(erule CPrf.cases) |
|
601 apply(simp_all) |
|
602 |
|
603 apply(erule CPrf.cases) |
|
604 apply(simp_all) |
|
605 apply(erule CPrf.cases) |
|
606 apply(simp_all) |
|
607 apply(rule CPrf.intros) |
|
608 done |
|
609 |
|
610 |
|
611 lemma CPTpre_simps: |
|
612 shows "CPTpre ONE s = {Void}" |
|
613 and "CPTpre (CHAR c) (d#s) = (if c = d then {Char c} else {})" |
|
614 and "CPTpre (ALT r1 r2) s = Left ` CPTpre r1 s \<union> Right ` CPTpre r2 s" |
|
615 and "CPTpre (SEQ r1 r2) s = |
|
616 {Seq v1 v2 | v1 v2. v1 \<in> CPTpre r1 s \<and> v2 \<in> CPTpre r2 (drop (length (flat v1)) s)}" |
|
617 apply - |
|
618 apply(rule subset_antisym) |
|
619 apply(rule CPTpre_subsets) |
|
620 apply(auto simp add: CPTpre_def intro: "CPrf.intros")[1] |
|
621 apply(case_tac "c = d") |
|
622 apply(simp) |
|
623 apply(rule subset_antisym) |
|
624 apply(rule CPTpre_subsets) |
|
625 apply(auto simp add: CPTpre_def intro: CPrf.intros)[1] |
|
626 apply(simp) |
|
627 apply(auto simp add: CPTpre_def intro: CPrf.intros)[1] |
|
628 apply(erule CPrf.cases) |
|
629 apply(simp_all) |
|
630 apply(rule subset_antisym) |
|
631 apply(rule CPTpre_subsets) |
|
632 apply(auto simp add: CPTpre_def intro: CPrf.intros)[1] |
|
633 apply(rule subset_antisym) |
|
634 apply(rule CPTpre_subsets) |
|
635 apply(auto simp add: CPTpre_def intro: CPrf.intros)[1] |
|
636 done |
|
637 |
|
638 lemma CPT_simps: |
|
639 shows "CPT ONE s = (if s = [] then {Void} else {})" |
|
640 and "CPT (CHAR c) [d] = (if c = d then {Char c} else {})" |
|
641 and "CPT (ALT r1 r2) s = Left ` CPT r1 s \<union> Right ` CPT r2 s" |
|
642 and "CPT (SEQ r1 r2) s = |
|
643 {Seq v1 v2 | v1 v2 s1 s2. s1 @ s2 = s \<and> v1 \<in> CPT r1 s1 \<and> v2 \<in> CPT r2 s2}" |
|
644 apply - |
|
645 apply(rule subset_antisym) |
|
646 apply(auto simp add: CPT_def)[1] |
|
647 apply(erule CPrf.cases) |
|
648 apply(simp_all)[7] |
|
649 apply(erule CPrf.cases) |
|
650 apply(simp_all)[7] |
|
651 apply(auto simp add: CPT_def intro: CPrf.intros)[1] |
|
652 apply(auto simp add: CPT_def intro: CPrf.intros)[1] |
|
653 apply(erule CPrf.cases) |
|
654 apply(simp_all)[7] |
|
655 apply(erule CPrf.cases) |
|
656 apply(simp_all)[7] |
|
657 apply(auto simp add: CPT_def image_def intro: CPrf.intros)[1] |
|
658 apply(erule CPrf.cases) |
|
659 apply(simp_all)[7] |
|
660 apply(clarify) |
|
661 apply blast |
|
662 apply(auto simp add: CPT_def image_def intro: CPrf.intros)[1] |
|
663 apply(erule CPrf.cases) |
|
664 apply(simp_all)[7] |
|
665 done |
|
666 |
|
667 lemma test: |
|
668 assumes "finite A" |
|
669 shows "finite {vs. Stars vs \<in> A}" |
|
670 using assms |
|
671 apply(induct A) |
|
672 apply(simp) |
|
673 apply(auto) |
|
674 apply(case_tac x) |
|
675 apply(simp_all) |
|
676 done |
|
677 |
|
678 lemma CPTpre_STAR_finite: |
|
679 assumes "\<And>s. finite (CPTpre r s)" |
|
680 shows "finite (CPTpre (STAR r) s)" |
|
681 apply(induct s rule: length_induct) |
|
682 apply(case_tac xs) |
|
683 apply(simp) |
|
684 apply(simp add: CPTpre_subsets) |
|
685 apply(rule finite_subset) |
|
686 apply(rule CPTpre_subsets) |
|
687 apply(simp) |
|
688 apply(rule_tac B="(\<lambda>(v, vs). Stars (v#vs)) ` {(v, vs). v \<in> CPTpre r (a#list) \<and> flat v \<noteq> [] \<and> Stars vs \<in> CPTpre (STAR r) (drop (length (flat v)) (a#list))}" in finite_subset) |
|
689 apply(auto)[1] |
|
690 apply(rule finite_imageI) |
|
691 apply(simp add: Collect_case_prod_Sigma) |
|
692 apply(rule finite_SigmaI) |
|
693 apply(rule assms) |
|
694 apply(case_tac "flat v = []") |
|
695 apply(simp) |
|
696 apply(drule_tac x="drop (length (flat v)) (a # list)" in spec) |
|
697 apply(simp) |
|
698 apply(auto)[1] |
|
699 apply(rule test) |
|
700 apply(simp) |
|
701 done |
|
702 |
|
703 lemma CPTpre_finite: |
|
704 shows "finite (CPTpre r s)" |
|
705 apply(induct r arbitrary: s) |
|
706 apply(simp add: CPTpre_subsets) |
|
707 apply(rule finite_subset) |
|
708 apply(rule CPTpre_subsets) |
|
709 apply(simp) |
|
710 apply(rule finite_subset) |
|
711 apply(rule CPTpre_subsets) |
|
712 apply(simp) |
|
713 apply(rule finite_subset) |
|
714 apply(rule CPTpre_subsets) |
|
715 apply(rule_tac B="(\<lambda>(v1, v2). Seq v1 v2) ` {(v1, v2). v1 \<in> CPTpre r1 s \<and> v2 \<in> CPTpre r2 (drop (length (flat v1)) s)}" in finite_subset) |
|
716 apply(auto)[1] |
|
717 apply(rule finite_imageI) |
|
718 apply(simp add: Collect_case_prod_Sigma) |
|
719 apply(rule finite_subset) |
|
720 apply(rule CPTpre_subsets) |
|
721 apply(simp) |
|
722 by (simp add: CPTpre_STAR_finite) |
|
723 |
|
724 |
|
725 lemma CPT_finite: |
|
726 shows "finite (CPT r s)" |
|
727 apply(rule finite_subset) |
|
728 apply(rule CPT_CPTpre_subset) |
|
729 apply(rule CPTpre_finite) |
|
730 done |
|
731 *) |
|
732 |
|
733 lemma test2: |
632 lemma test2: |
734 assumes "\<forall>v \<in> set vs. flat v \<in> r \<rightarrow> v \<and> flat v \<noteq> []" |
633 assumes "\<forall>v \<in> set vs. flat v \<in> r \<rightarrow> v \<and> flat v \<noteq> []" |
735 shows "(Stars vs) \<in> CPT (STAR r) (flat (Stars vs))" |
634 shows "(Stars vs) \<in> CV (STAR r) (flat (Stars vs))" |
736 using assms |
635 using assms |
737 apply(induct vs) |
636 apply(induct vs) |
738 apply(auto simp add: CPT_def) |
637 apply(auto simp add: CV_def) |
739 apply(rule CPrf.intros) |
638 apply(rule CPrf.intros) |
740 apply(simp) |
639 apply(simp) |
741 apply(rule CPrf.intros) |
640 apply(rule CPrf.intros) |
742 apply(simp_all) |
641 apply(simp_all) |
743 by (metis (no_types, lifting) CPT_def Posix_CPT mem_Collect_eq) |
642 by (metis (no_types, lifting) CV_def Posix_CV mem_Collect_eq) |
744 |
643 |
745 |
644 |
746 end |
645 end |