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 |
69 |
74 |
70 lemma Der_union [simp]: |
75 lemma Der_union [simp]: |
71 shows "Der c (A \<union> B) = Der c A \<union> Der c B" |
76 shows "Der c (A \<union> B) = Der c A \<union> Der c B" |
72 unfolding Der_def |
77 unfolding Der_def |
73 by auto |
78 by auto |
232 | "L (UPNTIMES r n) = (\<Union>i\<in> {..n} . (L r) \<up> i)" |
238 | "L (UPNTIMES r n) = (\<Union>i\<in> {..n} . (L r) \<up> i)" |
233 | "L (NTIMES r n) = (L r) \<up> n" |
239 | "L (NTIMES r n) = (L r) \<up> n" |
234 | "L (FROMNTIMES r n) = (\<Union>i\<in> {n..} . (L r) \<up> i)" |
240 | "L (FROMNTIMES r n) = (\<Union>i\<in> {n..} . (L r) \<up> i)" |
235 | "L (NMTIMES r n m) = (\<Union>i\<in>{n..m} . (L r) \<up> i)" |
241 | "L (NMTIMES r n m) = (\<Union>i\<in>{n..m} . (L r) \<up> i)" |
236 | "L (PLUS r) = (\<Union>i\<in> {1..} . (L r) \<up> i)" |
242 | "L (PLUS r) = (\<Union>i\<in> {1..} . (L r) \<up> i)" |
|
243 | "L (AND r1 r2) = (L r1) \<inter> (L r2)" |
237 |
244 |
238 section {* Nullable, Derivatives *} |
245 section {* Nullable, Derivatives *} |
239 |
246 |
240 fun |
247 fun |
241 nullable :: "rexp \<Rightarrow> bool" |
248 nullable :: "rexp \<Rightarrow> bool" |
249 | "nullable (UPNTIMES r n) = True" |
256 | "nullable (UPNTIMES r n) = True" |
250 | "nullable (NTIMES r n) = (if n = 0 then True else nullable r)" |
257 | "nullable (NTIMES r n) = (if n = 0 then True else nullable r)" |
251 | "nullable (FROMNTIMES r n) = (if n = 0 then True else nullable r)" |
258 | "nullable (FROMNTIMES r n) = (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))" |
259 | "nullable (NMTIMES r n m) = (if m < n then False else (if n = 0 then True else nullable r))" |
253 | "nullable (PLUS r) = (nullable r)" |
260 | "nullable (PLUS r) = (nullable r)" |
|
261 | "nullable (AND r1 r2) = (nullable r1 \<and> nullable r2)" |
254 |
262 |
255 fun |
263 fun |
256 der :: "char \<Rightarrow> rexp \<Rightarrow> rexp" |
264 der :: "char \<Rightarrow> rexp \<Rightarrow> rexp" |
257 where |
265 where |
258 "der c (ZERO) = ZERO" |
266 "der c (ZERO) = ZERO" |
274 (if m < n then ZERO |
282 (if m < n then ZERO |
275 else (if n = 0 then (if m = 0 then ZERO else |
283 else (if n = 0 then (if m = 0 then ZERO else |
276 SEQ (der c r) (UPNTIMES r (m - 1))) else |
284 SEQ (der c r) (UPNTIMES r (m - 1))) else |
277 SEQ (der c r) (NMTIMES r (n - 1) (m - 1))))" |
285 SEQ (der c r) (NMTIMES r (n - 1) (m - 1))))" |
278 | "der c (PLUS r) = SEQ (der c r) (STAR r)" |
286 | "der c (PLUS r) = SEQ (der c r) (STAR r)" |
|
287 | "der c (AND r1 r2) = AND (der c r1) (der c r2)" |
279 |
288 |
280 fun |
289 fun |
281 ders :: "string \<Rightarrow> rexp \<Rightarrow> rexp" |
290 ders :: "string \<Rightarrow> rexp \<Rightarrow> rexp" |
282 where |
291 where |
283 "ders [] r = r" |
292 "ders [] r = r" |
414 | "flat (Left v) = flat v" |
423 | "flat (Left v) = flat v" |
415 | "flat (Right v) = flat v" |
424 | "flat (Right v) = flat v" |
416 | "flat (Seq v1 v2) = (flat v1) @ (flat v2)" |
425 | "flat (Seq v1 v2) = (flat v1) @ (flat v2)" |
417 | "flat (Stars []) = []" |
426 | "flat (Stars []) = []" |
418 | "flat (Stars (v#vs)) = (flat v) @ (flat (Stars vs))" |
427 | "flat (Stars (v#vs)) = (flat v) @ (flat (Stars vs))" |
|
428 | "flat (And v1 v2) = flat v1" |
419 |
429 |
420 lemma flat_Stars [simp]: |
430 lemma flat_Stars [simp]: |
421 "flat (Stars vs) = concat (map flat vs)" |
431 "flat (Stars vs) = concat (map flat vs)" |
422 by (induct vs) (auto) |
432 by (induct vs) (auto) |
423 |
433 |
436 | "\<lbrakk>\<forall>v \<in> set vs. \<turnstile> v : r; length vs \<le> n\<rbrakk> \<Longrightarrow> \<turnstile> Stars vs : UPNTIMES r n" |
446 | "\<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" |
447 | "\<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" |
448 | "\<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" |
449 | "\<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" |
450 | "\<lbrakk>\<forall>v \<in> set vs. \<turnstile> v : r; length vs \<ge> 1\<rbrakk> \<Longrightarrow> \<turnstile> Stars vs : PLUS r" |
|
451 | "\<lbrakk>\<turnstile> v1 : r1; \<turnstile> v2 : r2; flat v1 = flat v2\<rbrakk> \<Longrightarrow> \<turnstile> And v1 v2: AND r1 r2" |
441 |
452 |
442 |
453 |
443 inductive_cases Prf_elims: |
454 inductive_cases Prf_elims: |
444 "\<turnstile> v : ZERO" |
455 "\<turnstile> v : ZERO" |
445 "\<turnstile> v : SEQ r1 r2" |
456 "\<turnstile> v : SEQ r1 r2" |
603 | "mkeps(UPNTIMES r n) = Stars []" |
615 | "mkeps(UPNTIMES r n) = Stars []" |
604 | "mkeps(NTIMES r n) = Stars (replicate n (mkeps r))" |
616 | "mkeps(NTIMES r n) = Stars (replicate n (mkeps r))" |
605 | "mkeps(FROMNTIMES r n) = Stars (replicate n (mkeps r))" |
617 | "mkeps(FROMNTIMES r n) = Stars (replicate n (mkeps r))" |
606 | "mkeps(NMTIMES r n m) = Stars (replicate n (mkeps r))" |
618 | "mkeps(NMTIMES r n m) = Stars (replicate n (mkeps r))" |
607 | "mkeps(PLUS r) = Stars ([mkeps r])" |
619 | "mkeps(PLUS r) = Stars ([mkeps r])" |
|
620 | "mkeps(AND r1 r2) = And (mkeps r1) (mkeps r2)" |
608 |
621 |
609 |
622 |
610 fun injval :: "rexp \<Rightarrow> char \<Rightarrow> val \<Rightarrow> val" |
623 fun injval :: "rexp \<Rightarrow> char \<Rightarrow> val \<Rightarrow> val" |
611 where |
624 where |
612 "injval (CHAR d) c Void = Char d" |
625 "injval (CHAR d) c Void = Char d" |
619 | "injval (UPNTIMES r n) c (Seq v (Stars vs)) = Stars ((injval r c v) # vs)" |
632 | "injval (UPNTIMES 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)" |
633 | "injval (NTIMES 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)" |
634 | "injval (FROMNTIMES r n) 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)" |
635 | "injval (NMTIMES r n m) 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)" |
636 | "injval (PLUS r) c (Seq v (Stars vs)) = Stars ((injval r c v) # vs)" |
|
637 | "injval (AND r1 r2) c (And v1 v2) = And (injval r1 c v1) (injval r2 c v2)" |
624 |
638 |
625 section {* Mkeps, injval *} |
639 section {* Mkeps, injval *} |
|
640 |
|
641 lemma mkeps_flat: |
|
642 assumes "nullable(r)" |
|
643 shows "flat (mkeps r) = []" |
|
644 using assms |
|
645 apply (induct rule: nullable.induct) |
|
646 apply(auto) |
|
647 by meson |
626 |
648 |
627 lemma mkeps_nullable: |
649 lemma mkeps_nullable: |
628 assumes "nullable(r)" |
650 assumes "nullable(r)" |
629 shows "\<turnstile> mkeps r : r" |
651 shows "\<turnstile> mkeps r : r" |
630 using assms |
652 using assms |
631 apply(induct r rule: mkeps.induct) |
653 apply(induct r rule: mkeps.induct) |
632 apply(auto intro: Prf.intros) |
654 apply(auto intro: Prf.intros) |
633 by (metis Prf.intros(10) in_set_replicate length_replicate not_le order_refl) |
655 apply(metis Prf.intros(10) in_set_replicate length_replicate not_le order_refl) |
634 |
656 apply(rule Prf.intros) |
635 lemma mkeps_flat: |
657 apply(simp_all add: mkeps_flat) |
636 assumes "nullable(r)" |
658 done |
637 shows "flat (mkeps r) = []" |
659 |
638 using assms |
660 lemma Prf_injval_flat: |
639 apply (induct rule: nullable.induct) |
661 assumes "\<turnstile> v : der c r" |
640 apply(auto) |
662 shows "flat (injval r c v) = c # (flat v)" |
641 by meson |
663 using assms |
642 |
664 apply(induct arbitrary: v rule: der.induct) |
|
665 apply(auto elim!: Prf_elims split: if_splits) |
|
666 apply(metis mkeps_flat) |
|
667 apply(rotate_tac 2) |
|
668 apply(erule Prf.cases) |
|
669 apply(simp_all) |
|
670 apply(rotate_tac 2) |
|
671 apply(erule Prf.cases) |
|
672 apply(simp_all) |
|
673 apply(rotate_tac 2) |
|
674 apply(erule Prf.cases) |
|
675 apply(simp_all) |
|
676 apply(rotate_tac 2) |
|
677 apply(erule Prf.cases) |
|
678 apply(simp_all) |
|
679 apply(rotate_tac 2) |
|
680 apply(erule Prf.cases) |
|
681 apply(simp_all) |
|
682 apply(rotate_tac 3) |
|
683 apply(erule Prf.cases) |
|
684 apply(simp_all) |
|
685 apply(rotate_tac 4) |
|
686 apply(erule Prf.cases) |
|
687 apply(simp_all) |
|
688 apply(rotate_tac 2) |
|
689 apply(erule Prf.cases) |
|
690 apply(simp_all) |
|
691 apply(rotate_tac 2) |
|
692 apply(erule Prf.cases) |
|
693 apply(simp_all) |
|
694 done |
643 |
695 |
644 lemma Prf_injval: |
696 lemma Prf_injval: |
645 assumes "\<turnstile> v : der c r" |
697 assumes "\<turnstile> v : der c r" |
646 shows "\<turnstile> (injval r c v) : r" |
698 shows "\<turnstile> (injval r c v) : r" |
647 using assms |
699 using assms |
718 apply(rotate_tac 2) |
770 apply(rotate_tac 2) |
719 apply(erule Prf.cases) |
771 apply(erule Prf.cases) |
720 apply(simp_all) |
772 apply(simp_all) |
721 apply(auto) |
773 apply(auto) |
722 using Prf.intros apply auto[1] |
774 using Prf.intros apply auto[1] |
723 done |
775 (* AND *) |
724 |
776 apply(erule Prf.cases) |
725 |
777 apply(simp_all) |
726 lemma Prf_injval_flat: |
778 apply(auto) |
727 assumes "\<turnstile> v : der c r" |
779 apply(rule Prf.intros) |
728 shows "flat (injval r c v) = c # (flat v)" |
780 apply(simp) |
729 using assms |
781 apply(simp) |
730 apply(induct arbitrary: v rule: der.induct) |
782 apply(simp add: Prf_injval_flat) |
731 apply(auto elim!: Prf_elims split: if_splits) |
783 done |
732 apply(metis mkeps_flat) |
784 |
733 apply(rotate_tac 2) |
785 |
734 apply(erule Prf.cases) |
786 |
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 |
|
758 |
787 |
759 |
788 |
760 section {* Our Alternative Posix definition *} |
789 section {* Our Alternative Posix definition *} |
761 |
790 |
762 inductive |
791 inductive |
790 \<Longrightarrow> (s1 @ s2) \<in> NMTIMES r (Suc n) (Suc m) \<rightarrow> Stars (v # vs)" |
819 \<Longrightarrow> (s1 @ s2) \<in> NMTIMES r (Suc n) (Suc m) \<rightarrow> Stars (v # vs)" |
791 | Posix_NMTIMES2: "s \<in> UPNTIMES r m \<rightarrow> Stars vs \<Longrightarrow> s \<in> NMTIMES r 0 m \<rightarrow> Stars vs" |
820 | Posix_NMTIMES2: "s \<in> UPNTIMES r m \<rightarrow> Stars vs \<Longrightarrow> s \<in> NMTIMES r 0 m \<rightarrow> Stars vs" |
792 | Posix_PLUS1: "\<lbrakk>s1 \<in> r \<rightarrow> v; s2 \<in> STAR r \<rightarrow> Stars vs; flat v = [] \<Longrightarrow> flat (Stars vs) = []; |
821 | Posix_PLUS1: "\<lbrakk>s1 \<in> r \<rightarrow> v; s2 \<in> STAR r \<rightarrow> Stars vs; flat v = [] \<Longrightarrow> flat (Stars vs) = []; |
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> |
822 \<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> |
794 \<Longrightarrow> (s1 @ s2) \<in> PLUS r \<rightarrow> Stars (v # vs)" |
823 \<Longrightarrow> (s1 @ s2) \<in> PLUS r \<rightarrow> Stars (v # vs)" |
|
824 | Posix_AND: "\<lbrakk>s \<in> r1 \<rightarrow> v1; s \<in> r2 \<rightarrow> v2\<rbrakk> \<Longrightarrow> s \<in> (AND r1 r2) \<rightarrow> (And v1 v2)" |
795 |
825 |
796 inductive_cases Posix_elims: |
826 inductive_cases Posix_elims: |
797 "s \<in> ZERO \<rightarrow> v" |
827 "s \<in> ZERO \<rightarrow> v" |
798 "s \<in> ONE \<rightarrow> v" |
828 "s \<in> ONE \<rightarrow> v" |
799 "s \<in> CHAR c \<rightarrow> v" |
829 "s \<in> CHAR c \<rightarrow> v" |
924 apply(rotate_tac 3) |
954 apply(rotate_tac 3) |
925 apply(erule Prf.cases) |
955 apply(erule Prf.cases) |
926 apply(simp_all) |
956 apply(simp_all) |
927 apply(rule Prf.intros) |
957 apply(rule Prf.intros) |
928 apply(auto) |
958 apply(auto) |
929 done |
959 apply(rule Prf.intros) |
|
960 apply(auto) |
|
961 by (simp add: Posix1(2)) |
930 |
962 |
931 |
963 |
932 lemma Posix_NTIMES_mkeps: |
964 lemma Posix_NTIMES_mkeps: |
933 assumes "[] \<in> r \<rightarrow> mkeps r" |
965 assumes "[] \<in> r \<rightarrow> mkeps r" |
934 shows "[] \<in> NTIMES r n \<rightarrow> Stars (replicate n (mkeps r))" |
966 shows "[] \<in> NTIMES r n \<rightarrow> Stars (replicate n (mkeps r))" |
1179 by (metis Posix1(1) Posix_PLUS1.hyps(6) append_self_conv append_self_conv2) |
1211 by (metis Posix1(1) Posix_PLUS1.hyps(6) append_self_conv append_self_conv2) |
1180 moreover |
1212 moreover |
1181 have IHs: "\<And>v2. s1 \<in> r \<rightarrow> v2 \<Longrightarrow> v = v2" |
1213 have IHs: "\<And>v2. s1 \<in> r \<rightarrow> v2 \<Longrightarrow> v = v2" |
1182 "\<And>v2. s2 \<in> STAR r \<rightarrow> v2 \<Longrightarrow> Stars vs = v2" by fact+ |
1214 "\<And>v2. s2 \<in> STAR r \<rightarrow> v2 \<Longrightarrow> Stars vs = v2" by fact+ |
1183 ultimately show "Stars (v # vs) = v2" by auto |
1215 ultimately show "Stars (v # vs) = v2" by auto |
|
1216 next |
|
1217 case (Posix_AND s r1 v1 r2 v2 v') |
|
1218 have "s \<in> AND r1 r2 \<rightarrow> v'" |
|
1219 "s \<in> r1 \<rightarrow> v1" "s \<in> r2 \<rightarrow> v2" by fact+ |
|
1220 then obtain v1' v2' where "v' = And v1' v2'" "s \<in> r1 \<rightarrow> v1'" "s \<in> r2 \<rightarrow> v2'" |
|
1221 apply(cases) apply (auto simp add: append_eq_append_conv2) |
|
1222 done |
|
1223 moreover |
|
1224 have IHs: "\<And>v1'. s \<in> r1 \<rightarrow> v1' \<Longrightarrow> v1 = v1'" |
|
1225 "\<And>v2'. s \<in> r2 \<rightarrow> v2' \<Longrightarrow> v2 = v2'" by fact+ |
|
1226 ultimately show "And v1 v2 = v'" by simp |
1184 qed |
1227 qed |
1185 |
1228 |
1186 lemma NTIMES_Stars: |
1229 lemma NTIMES_Stars: |
1187 assumes "\<turnstile> v : NTIMES r n" |
1230 assumes "\<turnstile> v : NTIMES r n" |
1188 shows "\<exists>vs. v = Stars vs \<and> (\<forall>v \<in> set vs. \<turnstile> v : r) \<and> length vs = n" |
1231 shows "\<exists>vs. v = Stars vs \<and> (\<forall>v \<in> set vs. \<turnstile> v : r) \<and> length vs = n" |