diff -r 8b919b3d753e -r 7f4f8c34da95 thys/ReStar.thy --- a/thys/ReStar.thy Mon Feb 08 15:51:23 2016 +0000 +++ b/thys/ReStar.thy Wed Feb 10 17:38:29 2016 +0000 @@ -32,6 +32,11 @@ where "Der c A \ {s. [c] @ s \ A}" +definition + Ders :: "string \ string set \ string set" +where + "Ders s A \ {s' | s'. s @ s' \ A}" + lemma Der_null [simp]: shows "Der c {} = {}" unfolding Der_def @@ -809,13 +814,20 @@ apply(simp_all add: nullable_correctness) done +lemma ders_correctness: + shows "L (ders s r) = Ders s (L r)" +apply(induct s arbitrary: r) +apply(simp add: Ders_def) +apply(simp) +apply(subst der_correctness) +apply(simp add: Ders_def Der_def) +done + section {* Injection function *} fun injval :: "rexp \ char \ val \ val" where - "injval (EMPTY) c Void = Char c" -| "injval (CHAR d) c Void = Char d" -| "injval (CHAR d) c (Char c') = Seq (Char d) (Char c')" + "injval (CHAR d) c Void = Char d" | "injval (ALT r1 r2) c (Left v1) = Left(injval r1 c v1)" | "injval (ALT r1 r2) c (Right v2) = Right(injval r2 c v2)" | "injval (SEQ r1 r2) c (Seq v1 v2) = Seq (injval r1 c v1) v2" @@ -869,6 +881,7 @@ apply(auto) done + lemma v3: assumes "\ v : der c r" shows "\ (injval r c v) : r" @@ -1028,6 +1041,113 @@ by (metis list.inject v4_proj) +section {* Roy's Definition *} + +inductive + Roy :: "val \ rexp \ bool" ("\ _ : _" [100, 100] 100) +where + "\ Void : EMPTY" +| "\ Char c : CHAR c" +| "\ v : r1 \ \ Left v : ALT r1 r2" +| "\\ v : r2; flat v \ L r1\ \ \ Right v : ALT r1 r2" +| "\\ v1 : r1; \ v2 : r2; \(\s\<^sub>3 s\<^sub>4. s\<^sub>3 \ [] \ s\<^sub>3 @ s\<^sub>4 = flat v2 \ (flat v1 @ s\<^sub>3) \ L r1 \ s\<^sub>4 \ L r2)\ \ + \ Seq v1 v2 : SEQ r1 r2" +| "\\ v : r; \ Stars vs : STAR r; flat v \ []; + \(\s\<^sub>3 s\<^sub>4. s\<^sub>3 \ [] \ s\<^sub>3 @ s\<^sub>4 = flat (Stars vs) \ (flat v @ s\<^sub>3) \ L r \ s\<^sub>4 \ L (STAR r))\ \ + \ Stars (v#vs) : STAR r" +| "\ Stars [] : STAR r" + +lemma drop_append: + assumes "s1 \ s2" + shows "s1 @ drop (length s1) s2 = s2" +using assms +apply(simp add: prefix_def) +apply(auto) +done + +lemma royA: + assumes "\(\s\<^sub>3 s\<^sub>4. s\<^sub>3 \ [] \ s\<^sub>3 @ s\<^sub>4 = flat v2 \ (flat v1 @ s\<^sub>3) \ L r1 \ s\<^sub>4 \ L r2)" + shows "\s. (s \ L(ders (flat v1) r1) \ + s \ (flat v2) \ drop (length s) (flat v2) \ L r2 \ s = [])" +using assms +apply - +apply(rule allI) +apply(rule impI) +apply(simp add: ders_correctness) +apply(simp add: Ders_def) +thm rest_def +apply(drule_tac x="s" in spec) +apply(simp) +apply(erule disjE) +apply(simp) +apply(drule_tac x="drop (length s) (flat v2)" in spec) +apply(simp add: drop_append) +done + +lemma royB: + assumes "\s. (s \ L(ders (flat v1) r1) \ + s \ (flat v2) \ drop (length s) (flat v2) \ L r2 \ s = [])" + shows "\(\s\<^sub>3 s\<^sub>4. s\<^sub>3 \ [] \ s\<^sub>3 @ s\<^sub>4 = flat v2 \ (flat v1 @ s\<^sub>3) \ L r1 \ s\<^sub>4 \ L r2)" +using assms +apply - +apply(auto simp add: prefix_def ders_correctness Ders_def) +by (metis append_eq_conv_conj) + +lemma royC: + assumes "\s t. (s \ L(ders (flat v1) r1) \ + s \ (flat v2 @ t) \ drop (length s) (flat v2 @ t) \ L r2 \ s = [])" + shows "\(\s\<^sub>3 s\<^sub>4. s\<^sub>3 \ [] \ s\<^sub>3 @ s\<^sub>4 = flat v2 \ (flat v1 @ s\<^sub>3) \ L r1 \ s\<^sub>4 \ L r2)" +using assms +apply - +apply(rule royB) +apply(rule allI) +apply(drule_tac x="s" in spec) +apply(drule_tac x="[]" in spec) +apply(simp) +done + +inductive + Roy2 :: "val \ rexp \ bool" ("2\ _ : _" [100, 100] 100) +where + "2\ Void : EMPTY" +| "2\ Char c : CHAR c" +| "2\ v : r1 \ 2\ Left v : ALT r1 r2" +| "\2\ v : r2; flat v \ L r1\ \ 2\ Right v : ALT r1 r2" +| "\2\ v1 : r1; 2\ v2 : r2; + \s t. (s \ L(ders (flat v1) r1) \ + s \ (flat v2 @ t) \ drop (length s) (flat v2) \ (L r2 ;; {t}) \ s = [])\ \ + 2\ Seq v1 v2 : SEQ r1 r2" +| "\2\ v : r; 2\ Stars vs : STAR r; flat v \ []; + \s t. (s \ L(ders (flat v) r) \ + s \ (flat (Stars vs) @ t) \ drop (length s) (flat (Stars vs)) \ (L (STAR r) ;; {t}) \ s = [])\\ + 2\ Stars (v#vs) : STAR r" +| "2\ Stars [] : STAR r" + +lemma Roy2_props: + assumes "2\ v : r" + shows "\ v : r" +using assms +apply(induct) +apply(auto intro: Prf.intros) +done + +lemma Roy_mkeps_nullable: + assumes "nullable(r)" + shows "2\ (mkeps r) : r" +using assms +apply(induct rule: nullable.induct) +apply(auto intro: Roy2.intros) +apply (metis Roy2.intros(4) mkeps_flat nullable_correctness) +apply(rule Roy2.intros) +apply(simp_all) +apply(rule allI) +apply(rule impI) +apply(simp add: ders_correctness Ders_def) +apply(auto simp add: Sequ_def) +apply(simp add: mkeps_flat) +apply(auto simp add: prefix_def) +done + section {* Alternative Posix definition *} inductive @@ -1045,6 +1165,45 @@ \ (s1 @ s2) \ STAR r \ Stars (v # vs)" | "[] \ STAR r \ Stars []" +lemma PMatch1: + assumes "s \ r \ v" + shows "\ v : r" "flat v = s" +using assms +apply(induct s r v rule: PMatch.induct) +apply(auto) +apply (metis Prf.intros(4)) +apply (metis Prf.intros(5)) +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 + assumes "\ v : r" + shows "(flat v) \ r \ v" +using assms +apply(induct) +apply(auto intro: PMatch.intros) +apply(rule PMatch.intros) +apply(simp) +apply(simp) +apply(simp) +apply(auto)[1] +done + +lemma + assumes "s \ r \ v" + shows "\ v : r" +using assms +apply(induct) +apply(auto intro: Roy.intros) +apply (metis PMatch1(2) Roy.intros(4)) +apply (metis PMatch1(2) Roy.intros(5)) +by (metis L.simps(6) PMatch1(2) Roy.intros(6)) + + lemma PMatch_mkeps: assumes "nullable r" shows "[] \ r \ mkeps r" @@ -1067,19 +1226,6 @@ apply(metis PMatch.intros(7)) done -lemma PMatch1: - assumes "s \ r \ v" - shows "\ v : r" "flat v = s" -using assms -apply(induct s r v rule: PMatch.induct) -apply(auto) -apply (metis Prf.intros(4)) -apply (metis Prf.intros(5)) -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" @@ -1342,6 +1488,96 @@ apply(simp add: Der_def) done +lemma PMatch_Roy2: + assumes "2\ v : (der c r)" + shows "2\ (injval r c v) : r" +using assms +apply(induct c r arbitrary: v rule: der.induct) +apply(auto) +apply(erule Roy2.cases) +apply(simp_all) +apply(erule Roy2.cases) +apply(simp_all) +apply(case_tac "c = c'") +apply(simp) +apply(erule Roy2.cases) +apply(simp_all) +apply (metis Roy2.intros(2)) +apply(erule Roy2.cases) +apply(simp_all) +apply(erule Roy2.cases) +apply(simp_all) +apply(clarify) +apply (metis Roy2.intros(3)) +apply(clarify) +apply(rule Roy2.intros(4)) +apply(metis) +apply(simp add: der_correctness Der_def) +apply(subst v4) +apply (metis Roy2_props) +apply(simp) +apply(case_tac "nullable r1") +apply(simp) +apply(erule Roy2.cases) +apply(simp_all) +apply(clarify) +apply(erule Roy2.cases) +apply(simp_all) +apply(clarify) +apply(rule Roy2.intros) +apply metis +apply(simp) +apply(auto)[1] +apply(simp add: ders_correctness Ders_def) +apply(simp add: der_correctness Der_def) +apply(drule_tac x="s" in spec) +apply(drule mp) +apply(rule conjI) +apply(subst (asm) v4) +apply (metis Roy2_props) +apply(simp) +apply(rule_tac x="t" in exI) +apply(simp) +apply(simp) +apply(rule Roy2.intros) +apply (metis Roy_mkeps_nullable) +apply metis +apply(auto)[1] +apply(simp add: ders_correctness Ders_def) +apply(subst (asm) mkeps_flat) +apply(simp) +apply(simp) +apply(subst (asm) v4) +apply (metis Roy2_props) +apply(subst (asm) v4) +apply (metis Roy2_props) +apply(simp add: Sequ_def prefix_def) +apply(auto)[1] +apply(simp add: append_eq_Cons_conv) +apply(auto) +apply(drule_tac x="ys'" in spec) +apply(drule mp) +apply(simp add: der_correctness Der_def) +apply(simp add: append_eq_append_conv2) +apply(auto)[1] +prefer 2 +apply(erule Roy2.cases) +apply(simp_all) +apply(rule Roy2.intros) +apply metis +apply(simp) +apply(auto)[1] +apply(simp add: ders_correctness Ders_def) +apply(subst (asm) v4) +apply (metis Roy2_props) +apply(drule_tac x="s" in spec) +apply(drule mp) +apply(rule conjI) +apply(simp add: der_correctness Der_def) +apply(auto)[1] +oops + + lemma lex_correct1: assumes "s \ L r" shows "lex r s = None" @@ -1436,10 +1672,181 @@ | "(Char c) \(CHAR c) (Char c)" | "flat (Stars (v # vs)) = [] \ (Stars []) \(STAR r) (Stars (v # vs))" | "flat (Stars (v # vs)) \ [] \ (Stars (v # vs)) \(STAR r) (Stars [])" -| "v1 \r v2 \ (Stars (v1 # vs1)) \(STAR r) (Stars (v2 # vs2))" +| "\v1 \r v2; v1 \ v2\ \ (Stars (v1 # vs1)) \(STAR r) (Stars (v2 # vs2))" | "(Stars vs1) \(STAR r) (Stars vs2) \ (Stars (v # vs1)) \(STAR r) (Stars (v # vs2))" | "(Stars []) \(STAR r) (Stars [])" +inductive ValOrd2 :: "val \ string \ val \ bool" ("_ 2\_ _" [100, 100, 100] 100) +where + "v2 2\s v2' \ (Seq v1 v2) 2\(flat v1 @ s) (Seq v1 v2')" +| "\v1 2\s v1'; v1 \ v1'\ \ (Seq v1 v2) 2\s (Seq v1' v2')" +| "length (flat v1) \ length (flat v2) \ (Left v1) 2\(flat v1) (Right v2)" +| "length (flat v2) > length (flat v1) \ (Right v2) 2\(flat v2) (Left v1)" +| "v2 2\s v2' \ (Right v2) 2\s (Right v2')" +| "v1 2\s v1' \ (Left v1) 2\s (Left v1')" +| "Void 2\[] Void" +| "(Char c) 2\[c] (Char c)" +| "flat (Stars (v # vs)) = [] \ (Stars []) 2\[] (Stars (v # vs))" +| "flat (Stars (v # vs)) \ [] \ (Stars (v # vs)) 2\(flat (Stars (v # vs))) (Stars [])" +| "\v1 \r v2; v1 \ v2\ \ (Stars (v1 # vs1)) 2\(flat v1) (Stars (v2 # vs2))" +| "(Stars vs1) 2\s (Stars vs2) \ (Stars (v # vs1)) 2\(flat v @ s) (Stars (v # vs2))" +| "(Stars []) 2\[] (Stars [])" + + +lemma admissibility: + assumes "2\ v : r" "\ v' : r" "flat v' \ flat v" + shows "v \r v'" +using assms +apply(induct arbitrary: v') +apply(erule Prf.cases) +apply(simp_all)[7] +apply (metis ValOrd.intros(7)) +apply(erule Prf.cases) +apply(simp_all)[7] +apply (metis ValOrd.intros(8)) +apply(erule Prf.cases) +apply(simp_all)[7] +apply (metis ValOrd.intros(6)) +apply (metis ValOrd.intros(3) length_sprefix less_imp_le_nat order_refl sprefix_def) +apply(erule Prf.cases) +apply(simp_all)[7] +apply (metis Prf_flat_L ValOrd.intros(4) length_sprefix sprefix_def) +apply (metis ValOrd.intros(5)) +(* Seq case *) +apply(erule Prf.cases) +apply(clarify)+ +prefer 2 +apply(clarify) +prefer 2 +apply(clarify) +prefer 2 +apply(clarify) +prefer 2 +apply(clarify) +prefer 2 +apply(clarify) +prefer 2 +apply(clarify) +apply(subgoal_tac "flat v1 \ flat v1a \ flat v1a \ flat v1") +prefer 2 +apply(simp add: prefix_def sprefix_def) +apply (metis append_eq_append_conv2) +apply(erule disjE) +apply(subst (asm) sprefix_def) +apply(subst (asm) (5) prefix_def) +apply(clarify) +apply(subgoal_tac "(s3 @ flat v2a) \ flat v2") +prefer 2 +apply(simp) +apply (metis append_assoc prefix_append) +apply(subgoal_tac "s3 \ []") +prefer 2 +apply (metis append_Nil2) +apply(subst (asm) (5) prefix_def) +apply(erule exE) +apply(drule_tac x="s3" in spec) +apply(drule_tac x="s3a" in spec) +apply(drule mp) +apply(rule conjI) +apply(simp add: ders_correctness Ders_def) +apply (metis Prf_flat_L) +apply(rule conjI) +apply(simp) +apply (metis append_assoc prefix_def) +apply(simp) +apply(subgoal_tac "drop (length s3) (flat v2) = flat v2a @ s3a") +apply(simp add: Sequ_def) +apply (metis Prf_flat_L) +thm drop_append +apply (metis append_eq_conv_conj) +apply(simp) +apply (metis ValOrd.intros(1) ValOrd.intros(2) flat.simps(5) prefix_append) +(* star cases *) +oops + + +lemma admisibility: + assumes "\ v : r" "\ v' : r" + shows "v \r v'" +using assms +apply(induct arbitrary: v') +prefer 5 +apply(drule royA) +apply(erule Prf.cases) +apply(simp_all)[7] +apply(clarify) +apply(case_tac "v1 = v1a") +apply(simp) +apply(rule ValOrd.intros) +apply metis +apply (metis ValOrd.intros(2)) +apply(erule Prf.cases) +apply(simp_all)[7] +apply (metis ValOrd.intros(7)) +apply(erule Prf.cases) +apply(simp_all)[7] +apply (metis ValOrd.intros(8)) +apply(erule Prf.cases) +apply(simp_all)[7] +apply (metis ValOrd.intros(6)) +apply(rule ValOrd.intros) +defer +apply(erule Prf.cases) +apply(simp_all)[7] +apply(clarify) +apply(rule ValOrd.intros) +(* seq case goes through *) +oops + + +lemma admisibility: + assumes "\ v : r" "\ v' : r" "flat v' \ flat v" + shows "v \r v'" +using assms +apply(induct arbitrary: v') +prefer 5 +apply(drule royA) +apply(erule Prf.cases) +apply(simp_all)[7] +apply(clarify) +apply(case_tac "v1 = v1a") +apply(simp) +apply(rule ValOrd.intros) +apply(subst (asm) (3) prefix_def) +apply(erule exE) +apply(simp) +apply (metis prefix_def) +(* the unequal case *) +apply(subgoal_tac "flat v1 \ flat v1a \ flat v1a \ flat v1") +prefer 2 +apply(simp add: prefix_def sprefix_def) +apply (metis append_eq_append_conv2) +apply(erule disjE) +(* first case flat v1 \ flat v1a *) +apply(subst (asm) sprefix_def) +apply(subst (asm) (5) prefix_def) +apply(clarify) +apply(subgoal_tac "(s3 @ flat v2a) \ flat v2") +prefer 2 +apply(simp) +apply (metis append_assoc prefix_append) +apply(subgoal_tac "s3 \ []") +prefer 2 +apply (metis append_Nil2) +(* HERE *) +apply(subst (asm) (5) prefix_def) +apply(erule exE) +apply(simp add: ders_correctness Ders_def) +apply(simp add: prefix_def) +apply(clarify) +apply(subst (asm) append_eq_append_conv2) +apply(erule exE) +apply(erule disjE) +apply(clarify) +oops + + + lemma ValOrd_refl: assumes "\ v : r" shows "v \r v" @@ -1509,7 +1916,77 @@ apply(simp_all)[7] apply(auto) apply (metis ValOrd.intros(10) ValOrd.intros(9)) -by (metis ValOrd.intros(11)) +apply(case_tac "v = va") +prefer 2 +apply (metis ValOrd.intros(11)) +apply(simp) +apply(rule ValOrd.intros(12)) +apply(erule contrapos_np) +apply(rule ValOrd.intros(12)) +oops + +lemma Roy_posix: + assumes "\ v : r" "\ v' : r" "flat v' \ flat v" + shows "v \r v'" +using assms +apply(induct r arbitrary: v v' rule: rexp.induct) +apply(erule Prf.cases) +apply(simp_all)[7] +apply(erule Prf.cases) +apply(simp_all)[7] +apply(erule Roy.cases) +apply(simp_all) +apply (metis ValOrd.intros(7)) +apply(erule Prf.cases) +apply(simp_all)[7] +apply(erule Roy.cases) +apply(simp_all) +apply (metis ValOrd.intros(8)) +prefer 2 +apply(erule Prf.cases) +apply(simp_all)[7] +apply(erule Roy.cases) +apply(simp_all) +apply(clarify) +apply (metis ValOrd.intros(6)) +apply(clarify) +apply (metis Prf_flat_L ValOrd.intros(4) length_sprefix sprefix_def) +apply(erule Roy.cases) +apply(simp_all) +apply (metis ValOrd.intros(3) length_sprefix less_imp_le_nat order_refl sprefix_def) +apply(clarify) +apply (metis ValOrd.intros(5)) +apply(erule Prf.cases) +apply(simp_all)[7] +apply(erule Roy.cases) +apply(simp_all) +apply(clarify) +apply(case_tac "v1a = v1") +apply(simp) +apply(rule ValOrd.intros) +apply (metis prefix_append) +apply(rule ValOrd.intros) +prefer 2 +apply(simp) +apply(simp add: prefix_def) +apply(auto)[1] +apply(simp add: append_eq_append_conv2) +apply(auto)[1] +apply(drule_tac x="v1a" in meta_spec) +apply(rotate_tac 9) +apply(drule_tac x="v1" in meta_spec) +apply(drule_tac meta_mp) +apply(simp) +apply(drule_tac meta_mp) +apply(simp) +apply(drule_tac meta_mp) +apply(simp) +apply(drule_tac x="us" in spec) +apply(drule_tac mp) +apply (metis Prf_flat_L) +apply(auto)[1] +oops + lemma ValOrd_anti: shows "\\ v1 : r; \ v2 : r; v1 \r v2; v2 \r v1\ \ v1 = v2" @@ -1577,57 +2054,6 @@ apply(simp_all) apply(auto)[1] prefer 2 -apply (metis Prf.intros(7) ValOrd.intros(11) not_Cons_self2) -prefer 2 -apply(auto)[1] -apply(rotate_tac 5) -apply(erule ValOrd.cases) -apply(simp_all) -apply (metis (no_types) Prf.intros(7) ValOrd.intros(11) not_Cons_self2) -apply (metis Prf.intros(7) ValOrd.intros(11) not_Cons_self2) -apply (metis Prf.intros(7) ValOrd.intros(11) not_Cons_self2) -apply (metis Prf.intros(7) ValOrd.intros(11) not_Cons_self2) -apply (metis Prf.intros(7) ValOrd.intros(11) not_Cons_self2) -apply (metis Prf.intros(7) ValOrd.intros(11) ValOrd_refl not_Cons_self2) -apply(erule ValOrd.cases) -apply(simp_all) -apply(erule ValOrd.cases) -apply(simp_all) -apply(rotate_tac 3) -apply(erule Prf.cases) -apply(simp_all)[7] -apply(clarify) -apply(erule ValOrd.cases) -apply(simp_all) -apply(erule ValOrd.cases) -apply(simp_all) -apply(clarify) -apply(rotate_tac 4) -apply(erule Prf.cases) -apply(simp_all)[7] -apply(clarify) -apply(erule ValOrd.cases) -apply(simp_all) -apply(erule ValOrd.cases) -apply(simp_all) -apply(clarify) - - -apply(erule ValOrd.cases) -apply(simp_all) -apply(auto)[1] -prefer 2 -prefer 3 -apply(auto)[1] -apply(erule Prf.cases) -apply(simp_all)[7] -apply(erule Prf.cases) -apply(simp_all)[7] -apply(clarify) -apply(rotate_tac 3) -apply(erule ValOrd.cases) -apply(simp_all) -apply(auto)[1] oops