diff -r 3c8cfdf95252 -r f067e59b58d9 thys/ReStar.thy --- a/thys/ReStar.thy Sat Jan 30 13:12:36 2016 +0000 +++ b/thys/ReStar.thy Mon Feb 01 13:46:28 2016 +0000 @@ -201,6 +201,18 @@ section {* Relation between values and regular expressions *} inductive + NPrf :: "val \ rexp \ bool" ("\ _ : _" [100, 100] 100) +where + "\\ v1 : r1; \ v2 : r2\ \ \ Seq v1 v2 : SEQ r1 r2" +| "\ v1 : r1 \ \ Left v1 : ALT r1 r2" +| "\ v2 : r2 \ \ Right v2 : ALT r1 r2" +| "\ Void : EMPTY" +| "\ Char c : CHAR c" +| "\ Star [] : STAR r" +| "\\ v : r; \ Star vs : STAR r; flat v \ []\ \ \ Star (v # vs) : STAR r" + + +inductive Prf :: "val \ rexp \ bool" ("\ _ : _" [100, 100] 100) where "\\ v1 : r1; \ v2 : r2\ \ \ Seq v1 v2 : SEQ r1 r2" @@ -209,7 +221,15 @@ | "\ Void : EMPTY" | "\ Char c : CHAR c" | "\ Star [] : STAR r" -| "\\ v : r; \ Star vs : STAR r\ \ \ Star (v#vs) : STAR r" +| "\\ v : r; \ Star vs : STAR r\ \ \ Star (v # vs) : STAR r" + +lemma NPrf_imp_Prf: + assumes "\ v : r" + shows "\ v : r" +using assms +apply(induct) +apply(auto intro: Prf.intros) +done lemma not_nullable_flat: assumes "\ v : r" "\nullable r" @@ -278,6 +298,48 @@ apply(simp) done +lemma Prf_Star_flat_L: + assumes "\ v : STAR r" shows "flat v \ (L r)\" +using assms +apply(induct v r\"STAR r" arbitrary: r rule: Prf.induct) +apply(auto) +apply(simp add: star3) +apply(auto) +apply(rule_tac x="Suc x" in exI) +apply(auto simp add: Sequ_def) +apply(rule_tac x="flat v" in exI) +apply(rule_tac x="flat (Star vs)" in exI) +apply(auto) +by (metis Prf_flat_L) + +lemma L_flat_Prf2: + "L(r) = {flat v | v. \ v : r}" +apply(induct r) +apply(auto) +using L.simps(1) Prf_flat_L +apply(blast) +using Prf.intros(4) +apply(force) +using L.simps(2) Prf_flat_L +apply(blast) +using Prf.intros(5) apply force +using L.simps(3) Prf_flat_L apply blast +using L_flat_Prf apply auto[1] +apply (smt L.simps(4) Sequ_def mem_Collect_eq) +using Prf_flat_L +apply(fastforce) +apply(metis Prf.intros(2) flat.simps(3)) +apply(metis Prf.intros(3) flat.simps(4)) +apply(erule Prf.cases) +apply(simp) +apply(simp) +apply(auto) +using L_flat_Prf apply auto[1] +apply (smt Collect_cong L.simps(6) mem_Collect_eq) +using Prf_Star_flat_L +apply(fastforce) +done + section {* Values Sets *} @@ -450,6 +512,7 @@ | "injval (SEQ r1 r2) c (Seq v1 v2) = Seq (injval r1 c v1) v2" | "injval (SEQ r1 r2) c (Left (Seq v1 v2)) = Seq (injval r1 c v1) v2" | "injval (SEQ r1 r2) c (Right v2) = Seq (mkeps r1) (injval r2 c v2)" +| "injval (STAR r) c (Seq v (Star vs)) = Star ((injval r c v) # vs)" fun lex :: "rexp \ string \ val option" @@ -477,6 +540,7 @@ (if flat v1 = [] then Right(projval r2 c v2) else if nullable r1 then Left (Seq (projval r1 c v1) v2) else Seq (projval r1 c v1) v2)" +| "projval (STAR r) c (Star (v # vs)) = Seq (projval r c v) (Star vs)" @@ -496,8 +560,6 @@ apply(auto) done -(* HERE *) - lemma v3: assumes "\ v : der c r" shows "\ (injval r c v) : r" @@ -505,70 +567,83 @@ apply(induct arbitrary: v rule: der.induct) apply(simp) apply(erule Prf.cases) -apply(simp_all)[5] +apply(simp_all)[7] apply(simp) apply(erule Prf.cases) -apply(simp_all)[5] +apply(simp_all)[7] apply(case_tac "c = c'") apply(simp) apply(erule Prf.cases) -apply(simp_all)[5] +apply(simp_all)[7] apply (metis Prf.intros(5)) apply(simp) apply(erule Prf.cases) -apply(simp_all)[5] +apply(simp_all)[7] apply(simp) apply(erule Prf.cases) -apply(simp_all)[5] +apply(simp_all)[7] apply (metis Prf.intros(2)) apply (metis Prf.intros(3)) apply(simp) apply(case_tac "nullable r1") apply(simp) apply(erule Prf.cases) -apply(simp_all)[5] +apply(simp_all)[7] apply(auto)[1] apply(erule Prf.cases) -apply(simp_all)[5] +apply(simp_all)[7] apply(auto)[1] apply (metis Prf.intros(1)) apply(auto)[1] apply (metis Prf.intros(1) mkeps_nullable) apply(simp) apply(erule Prf.cases) -apply(simp_all)[5] +apply(simp_all)[7] apply(auto)[1] apply(rule Prf.intros) apply(auto)[2] -done +apply(simp) +apply(erule Prf.cases) +apply(simp_all)[7] +apply(clarify) +apply(rotate_tac 2) +apply(erule Prf.cases) +apply(simp_all)[7] +apply(auto) +apply (metis Prf.intros(6) Prf.intros(7)) +by (metis Prf.intros(7)) lemma v3_proj: - assumes "\ v : r" and "\s. (flat v) = c # s" - shows "\ (projval r c v) : der c r" + assumes "\ v : r" and "\s. (flat v) = c # s" + shows "\ (projval r c v) : der c r" using assms -apply(induct rule: Prf.induct) +apply(induct rule: NPrf.induct) prefer 4 apply(simp) prefer 4 apply(simp) -apply (metis Prf.intros(4)) +apply (metis NPrf.intros(4)) prefer 2 apply(simp) -apply (metis Prf.intros(2)) +apply (metis NPrf.intros(2)) prefer 2 apply(simp) -apply (metis Prf.intros(3)) +apply (metis NPrf.intros(3)) apply(auto) -apply(rule Prf.intros) +apply(rule NPrf.intros) apply(simp) -apply (metis Prf_flat_L nullable_correctness) -apply(rule Prf.intros) -apply(rule Prf.intros) +apply (metis NPrf_imp_Prf not_nullable_flat) +apply(rule NPrf.intros) +apply(rule NPrf.intros) apply (metis Cons_eq_append_conv) apply(simp) -apply(rule Prf.intros) +apply(rule NPrf.intros) apply (metis Cons_eq_append_conv) apply(simp) +(* Star case *) +apply(rule NPrf.intros) +apply (metis Cons_eq_append_conv) +apply(auto) done lemma v4: @@ -578,44 +653,51 @@ apply(induct arbitrary: v rule: der.induct) apply(simp) apply(erule Prf.cases) -apply(simp_all)[5] +apply(simp_all)[7] apply(simp) apply(erule Prf.cases) -apply(simp_all)[5] +apply(simp_all)[7] apply(simp) apply(case_tac "c = c'") apply(simp) apply(auto)[1] apply(erule Prf.cases) -apply(simp_all)[5] +apply(simp_all)[7] apply(simp) apply(erule Prf.cases) -apply(simp_all)[5] +apply(simp_all)[7] apply(simp) apply(erule Prf.cases) -apply(simp_all)[5] +apply(simp_all)[7] apply(simp) apply(case_tac "nullable r1") apply(simp) apply(erule Prf.cases) -apply(simp_all (no_asm_use))[5] +apply(simp_all (no_asm_use))[7] apply(auto)[1] apply(erule Prf.cases) -apply(simp_all)[5] +apply(simp_all)[7] apply(clarify) apply(simp only: injval.simps flat.simps) apply(auto)[1] apply (metis mkeps_flat) apply(simp) apply(erule Prf.cases) -apply(simp_all)[5] +apply(simp_all)[7] +apply(simp) +apply(erule Prf.cases) +apply(simp_all)[7] +apply(auto) +apply(rotate_tac 2) +apply(erule Prf.cases) +apply(simp_all)[7] done lemma v4_proj: - assumes "\ v : r" and "\s. (flat v) = c # s" + assumes "\ v : r" and "\s. (flat v) = c # s" shows "c # flat (projval r c v) = flat v" using assms -apply(induct rule: Prf.induct) +apply(induct rule: NPrf.induct) prefer 4 apply(simp) prefer 4 @@ -625,15 +707,19 @@ prefer 2 apply(simp) apply(auto) -by (metis Cons_eq_append_conv) +apply (metis Cons_eq_append_conv) +apply(simp add: append_eq_Cons_conv) +apply(auto) +done lemma v4_proj2: - assumes "\ v : r" and "(flat v) = c # s" + assumes "\ v : r" and "(flat v) = c # s" shows "flat (projval r c v) = s" using assms by (metis list.inject v4_proj) + section {* Alternative Posix definition *} inductive @@ -646,7 +732,8 @@ | "\s1 \ r1 \ v1; s2 \ r2 \ v2; \(\s3 s4. s3 \ [] \ s3 @ s4 = s2 \ (s1 @ s3) \ L r1 \ s4 \ L r2)\ \ (s1 @ s2) \ (SEQ r1 r2) \ (Seq v1 v2)" - +| "\s1 \ r \ v; s2 \ STAR r \ Star vs; flat v \ []\ \ (s1 @ s2) \ STAR r \ Star (v # vs)" +| "[] \ STAR r \ Star []" lemma PMatch_mkeps: assumes "nullable r" @@ -666,8 +753,9 @@ apply(simp) apply (rule PMatch.intros) apply(simp) -by (metis nullable_correctness) - +apply (metis nullable_correctness) +apply(metis PMatch.intros(7)) +done lemma PMatch1: assumes "s \ r \ v" @@ -680,6 +768,22 @@ apply (metis Prf.intros(2)) apply (metis Prf.intros(3)) apply (metis Prf.intros(1)) +apply (metis Prf.intros(7)) +by (metis Prf.intros(6)) + +lemma PMatch1N: + assumes "s \ r \ v" + shows "\ v : r" +using assms +apply(induct s r v rule: PMatch.induct) +apply(auto) +apply (metis NPrf.intros(4)) +apply (metis NPrf.intros(5)) +apply (metis NPrf.intros(2)) +apply (metis NPrf.intros(3)) +apply (metis NPrf.intros(1)) +apply (metis NPrf.intros(7) PMatch1(2)) +apply(rule NPrf.intros) done lemma PMatch_Values: @@ -696,38 +800,40 @@ apply(induct c r arbitrary: s v rule: der.induct) apply(auto) apply(erule PMatch.cases) -apply(simp_all)[5] +apply(simp_all)[7] apply(erule PMatch.cases) -apply(simp_all)[5] +apply(simp_all)[7] apply(case_tac "c = c'") apply(simp) apply(erule PMatch.cases) -apply(simp_all)[5] +apply(simp_all)[7] apply (metis PMatch.intros(2)) apply(simp) apply(erule PMatch.cases) -apply(simp_all)[5] +apply(simp_all)[7] apply(erule PMatch.cases) -apply(simp_all)[5] +apply(simp_all)[7] apply (metis PMatch.intros(3)) apply(clarify) apply(rule PMatch.intros) apply metis apply(simp add: L_flat_Prf) apply(auto)[1] -thm v3_proj +apply(subgoal_tac "\ v : r1") apply(frule_tac c="c" in v3_proj) apply metis apply(drule_tac x="projval r1 c v" in spec) apply(drule mp) apply (metis v4_proj2) -apply(simp) +apply (metis NPrf_imp_Prf) +defer +(* SEQ case *) apply(case_tac "nullable r1") apply(simp) -defer +prefer 2 apply(simp) apply(erule PMatch.cases) -apply(simp_all)[5] +apply(simp_all)[7] apply(clarify) apply(subst append.simps(2)[symmetric]) apply(rule PMatch.intros) @@ -736,6 +842,7 @@ apply(auto)[1] apply(simp add: L_flat_Prf) apply(auto)[1] +apply(subgoal_tac "\ v : r1") apply(frule_tac c="c" in v3_proj) apply metis apply(drule_tac x="s3" in spec) @@ -743,14 +850,15 @@ apply(rule_tac x="projval r1 c v" in exI) apply(rule conjI) apply (metis v4_proj2) -apply(simp) +apply (metis NPrf_imp_Prf) apply metis +defer (* nullable case *) apply(erule PMatch.cases) -apply(simp_all)[5] +apply(simp_all)[7] apply(clarify) apply(erule PMatch.cases) -apply(simp_all)[5] +apply(simp_all)[7] apply(clarify) apply(subst append.simps(2)[symmetric]) apply(rule PMatch.intros) @@ -759,16 +867,17 @@ apply(auto)[1] apply(simp add: L_flat_Prf) apply(auto)[1] +apply(subgoal_tac "\ v : r1") apply(frule_tac c="c" in v3_proj) apply metis apply(drule_tac x="s3" in spec) apply(drule mp) -apply (metis v4_proj2) +apply (metis NPrf_imp_Prf v4_proj2) apply(simp) +defer (* interesting case *) apply(clarify) apply(simp) -thm L.simps apply(subst (asm) L.simps(4)[symmetric]) apply(simp only: L_flat_Prf) apply(simp) @@ -783,12 +892,33 @@ apply(drule_tac x="Seq (projval r1 c v) vb" in spec) apply(drule mp) apply(simp) -apply (metis append_Cons butlast_snoc last_snoc neq_Nil_conv rotate1.simps(2) v4_proj2) +apply(subgoal_tac "\ v : r1") +apply (metis append_Cons butlast_snoc list.sel(1) neq_Nil_conv rotate1.simps(2) v4_proj2) +defer apply(subgoal_tac "\ projval r1 c v : der c r1") apply (metis Prf.intros(1)) +apply(rule NPrf_imp_Prf) apply(rule v3_proj) -apply(simp) -by (metis Cons_eq_append_conv) +defer +apply (metis Cons_eq_append_conv) +(* Star case *) +apply(erule PMatch.cases) +apply(simp_all)[7] +apply(clarify) +apply(rotate_tac 2) +apply(frule_tac PMatch1) +apply(erule PMatch.cases) +apply(simp_all)[7] +apply(subst append.simps(2)[symmetric]) +apply(rule PMatch.intros) +apply metis +apply (metis Nil_is_append_conv PMatch.intros(6)) +apply (metis PMatch1(2) list.distinct(1)) +apply(auto)[1] +(* HERE *) +(* oops *) + + lemma lex_correct1: assumes "s \ L r"