thys/ReStar.thy
changeset 146 da81ffac4b10
parent 145 97735ef233be
child 149 ec3d221bfc45
equal deleted inserted replaced
145:97735ef233be 146:da81ffac4b10
   338 
   338 
   339 
   339 
   340 section {* Our Alternative Posix definition *}
   340 section {* Our Alternative Posix definition *}
   341 
   341 
   342 inductive 
   342 inductive 
   343   PMatch :: "string \<Rightarrow> rexp \<Rightarrow> val \<Rightarrow> bool" ("_ \<in> _ \<rightarrow> _" [100, 100, 100] 100)
   343   Posix :: "string \<Rightarrow> rexp \<Rightarrow> val \<Rightarrow> bool" ("_ \<in> _ \<rightarrow> _" [100, 100, 100] 100)
   344 where
   344 where
   345   "[] \<in> ONE \<rightarrow> Void"
   345   "[] \<in> ONE \<rightarrow> Void"
   346 | "[c] \<in> (CHAR c) \<rightarrow> (Char c)"
   346 | "[c] \<in> (CHAR c) \<rightarrow> (Char c)"
   347 | "s \<in> r1 \<rightarrow> v \<Longrightarrow> s \<in> (ALT r1 r2) \<rightarrow> (Left v)"
   347 | "s \<in> r1 \<rightarrow> v \<Longrightarrow> s \<in> (ALT r1 r2) \<rightarrow> (Left v)"
   348 | "\<lbrakk>s \<in> r2 \<rightarrow> v; s \<notin> L(r1)\<rbrakk> \<Longrightarrow> s \<in> (ALT r1 r2) \<rightarrow> (Right v)"
   348 | "\<lbrakk>s \<in> r2 \<rightarrow> v; s \<notin> L(r1)\<rbrakk> \<Longrightarrow> s \<in> (ALT r1 r2) \<rightarrow> (Right v)"
   352 | "\<lbrakk>s1 \<in> r \<rightarrow> v; s2 \<in> STAR r \<rightarrow> Stars vs; flat v \<noteq> [];
   352 | "\<lbrakk>s1 \<in> r \<rightarrow> v; s2 \<in> STAR r \<rightarrow> Stars vs; flat v \<noteq> [];
   353     \<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>
   353     \<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>
   354     \<Longrightarrow> (s1 @ s2) \<in> STAR r \<rightarrow> Stars (v # vs)"
   354     \<Longrightarrow> (s1 @ s2) \<in> STAR r \<rightarrow> Stars (v # vs)"
   355 | "[] \<in> STAR r \<rightarrow> Stars []"
   355 | "[] \<in> STAR r \<rightarrow> Stars []"
   356 
   356 
   357 inductive_cases PMatch_elims:
   357 inductive_cases Posix_elims:
   358   "s \<in> ONE \<rightarrow> v"
   358   "s \<in> ONE \<rightarrow> v"
   359   "s \<in> CHAR c \<rightarrow> v"
   359   "s \<in> CHAR c \<rightarrow> v"
   360   "s \<in> ALT r1 r2 \<rightarrow> v"
   360   "s \<in> ALT r1 r2 \<rightarrow> v"
   361   "s \<in> SEQ r1 r2 \<rightarrow> v"
   361   "s \<in> SEQ r1 r2 \<rightarrow> v"
   362   "s \<in> STAR r \<rightarrow> v"
   362   "s \<in> STAR r \<rightarrow> v"
   363 
   363 
   364 lemma PMatch1:
   364 lemma Posix1:
   365   assumes "s \<in> r \<rightarrow> v"
   365   assumes "s \<in> r \<rightarrow> v"
   366   shows "s \<in> L r" "flat v = s"
   366   shows "s \<in> L r" "flat v = s"
   367 using assms
   367 using assms
   368 by (induct s r v rule: PMatch.induct)
   368 by (induct s r v rule: Posix.induct)
   369    (auto simp add: Sequ_def)
   369    (auto simp add: Sequ_def)
   370 
   370 
   371 
   371 
   372 lemma PMatch1a:
   372 lemma Posix1a:
   373   assumes "s \<in> r \<rightarrow> v"
   373   assumes "s \<in> r \<rightarrow> v"
   374   shows "\<turnstile> v : r"
   374   shows "\<turnstile> v : r"
   375 using assms
   375 using assms
   376 apply(induct s r v rule: PMatch.induct)
   376 apply(induct s r v rule: Posix.induct)
   377 apply(auto intro: Prf.intros)
   377 apply(auto intro: Prf.intros)
   378 done
   378 done
   379 
   379 
   380 lemma PMatch_mkeps:
   380 lemma Posix_mkeps:
   381   assumes "nullable r"
   381   assumes "nullable r"
   382   shows "[] \<in> r \<rightarrow> mkeps r"
   382   shows "[] \<in> r \<rightarrow> mkeps r"
   383 using assms
   383 using assms
   384 apply(induct r)
   384 apply(induct r)
   385 apply(auto intro: PMatch.intros simp add: nullable_correctness Sequ_def)
   385 apply(auto intro: Posix.intros simp add: nullable_correctness Sequ_def)
   386 apply(subst append.simps(1)[symmetric])
   386 apply(subst append.simps(1)[symmetric])
   387 apply(rule PMatch.intros)
   387 apply(rule Posix.intros)
   388 apply(auto)
   388 apply(auto)
   389 done
   389 done
   390 
   390 
   391 
   391 
   392 lemma PMatch_determ:
   392 lemma Posix_determ:
   393   assumes "s \<in> r \<rightarrow> v1" "s \<in> r \<rightarrow> v2"
   393   assumes "s \<in> r \<rightarrow> v1" "s \<in> r \<rightarrow> v2"
   394   shows "v1 = v2"
   394   shows "v1 = v2"
   395 using assms
   395 using assms
   396 apply(induct s r v1 arbitrary: v2 rule: PMatch.induct)
   396 apply(induct s r v1 arbitrary: v2 rule: Posix.induct)
   397 apply(erule PMatch.cases)
   397 apply(erule Posix.cases)
   398 apply(simp_all)[7]
   398 apply(simp_all)[7]
   399 apply(erule PMatch.cases)
   399 apply(erule Posix.cases)
   400 apply(simp_all)[7]
   400 apply(simp_all)[7]
   401 apply(rotate_tac 2)
   401 apply(rotate_tac 2)
   402 apply(erule PMatch.cases)
   402 apply(erule Posix.cases)
   403 apply(simp_all (no_asm_use))[7]
   403 apply(simp_all (no_asm_use))[7]
   404 apply(clarify)
   404 apply(clarify)
   405 apply(force)
   405 apply(force)
   406 apply(clarify)
   406 apply(clarify)
   407 apply(drule PMatch1(1))
   407 apply(drule Posix1(1))
   408 apply(simp)
   408 apply(simp)
   409 apply(rotate_tac 3)
   409 apply(rotate_tac 3)
   410 apply(erule PMatch.cases)
   410 apply(erule Posix.cases)
   411 apply(simp_all (no_asm_use))[7]
   411 apply(simp_all (no_asm_use))[7]
   412 apply(drule PMatch1(1))+
   412 apply(drule Posix1(1))+
   413 apply(simp)
   413 apply(simp)
   414 apply(simp)
   414 apply(simp)
   415 apply(rotate_tac 5)
   415 apply(rotate_tac 5)
   416 apply(erule PMatch.cases)
   416 apply(erule Posix.cases)
   417 apply(simp_all (no_asm_use))[7]
   417 apply(simp_all (no_asm_use))[7]
   418 apply(clarify)
   418 apply(clarify)
   419 apply(subgoal_tac "s1 = s1a")
   419 apply(subgoal_tac "s1 = s1a")
   420 apply(blast)
   420 apply(blast)
   421 apply(simp add: append_eq_append_conv2)
   421 apply(simp add: append_eq_append_conv2)
   422 apply(clarify)
   422 apply(clarify)
   423 apply (metis PMatch1(1) append_self_conv)
   423 apply (metis Posix1(1) append_self_conv)
   424 apply(rotate_tac 6)
   424 apply(rotate_tac 6)
   425 apply(erule PMatch.cases)
   425 apply(erule Posix.cases)
   426 apply(simp_all (no_asm_use))[7]
   426 apply(simp_all (no_asm_use))[7]
   427 apply(clarify)
   427 apply(clarify)
   428 apply(subgoal_tac "s1 = s1a")
   428 apply(subgoal_tac "s1 = s1a")
   429 apply(simp)
   429 apply(simp)
   430 apply(blast)
   430 apply(blast)
   431 apply(simp  (no_asm_use) add: append_eq_append_conv2)
   431 apply(simp  (no_asm_use) add: append_eq_append_conv2)
   432 apply(clarify)
   432 apply(clarify)
   433 apply (metis L.simps(6) PMatch1(1) append_self_conv)
   433 apply (metis L.simps(6) Posix1(1) append_self_conv)
   434 apply(clarify)
   434 apply(clarify)
   435 apply(rotate_tac 2)
   435 apply(rotate_tac 2)
   436 apply(erule PMatch.cases)
   436 apply(erule Posix.cases)
   437 apply(simp_all (no_asm_use))[7]
   437 apply(simp_all (no_asm_use))[7]
   438 using PMatch1(2) apply auto[1]
   438 using Posix1(2) apply auto[1]
   439 using PMatch1(2) apply blast
   439 using Posix1(2) apply blast
   440 apply(erule PMatch.cases)
   440 apply(erule Posix.cases)
   441 apply(simp_all (no_asm_use))[7]
   441 apply(simp_all (no_asm_use))[7]
   442 apply(clarify)
   442 apply(clarify)
   443 apply (simp add: PMatch1(2))
   443 apply (simp add: Posix1(2))
   444 apply(simp)
   444 apply(simp)
   445 done
   445 done
   446 
   446 
   447 (* a proof that does not need proj *)
   447 (* a proof that does not need proj *)
   448 lemma PMatch2_roy_version:
   448 lemma Posix2_roy_version:
   449   assumes "s \<in> (der c r) \<rightarrow> v"
   449   assumes "s \<in> (der c r) \<rightarrow> v"
   450   shows "(c # s) \<in> r \<rightarrow> (injval r c v)"
   450   shows "(c # s) \<in> r \<rightarrow> (injval r c v)"
   451 using assms
   451 using assms
   452 proof(induct r arbitrary: s v rule: rexp.induct)
   452 proof(induct r arbitrary: s v rule: rexp.induct)
   453   case ZERO
   453   case ZERO
   469     case eq
   469     case eq
   470     have "s \<in> der c (CHAR d) \<rightarrow> v" by fact
   470     have "s \<in> der c (CHAR d) \<rightarrow> v" by fact
   471     then have "s \<in> ONE \<rightarrow> v" using eq by simp
   471     then have "s \<in> ONE \<rightarrow> v" using eq by simp
   472     then have eqs: "s = [] \<and> v = Void" by cases simp
   472     then have eqs: "s = [] \<and> v = Void" by cases simp
   473     show "(c # s) \<in> CHAR d \<rightarrow> injval (CHAR d) c v" using eq eqs 
   473     show "(c # s) \<in> CHAR d \<rightarrow> injval (CHAR d) c v" using eq eqs 
   474     by (auto intro: PMatch.intros)
   474     by (auto intro: Posix.intros)
   475   next
   475   next
   476     case ineq
   476     case ineq
   477     have "s \<in> der c (CHAR d) \<rightarrow> v" by fact
   477     have "s \<in> der c (CHAR d) \<rightarrow> v" by fact
   478     then have "s \<in> ZERO \<rightarrow> v" using ineq by simp
   478     then have "s \<in> ZERO \<rightarrow> v" using ineq by simp
   479     then have "False" by cases
   479     then have "False" by cases
   491   then show "(c # s) \<in> ALT r1 r2 \<rightarrow> injval (ALT r1 r2) c v"
   491   then show "(c # s) \<in> ALT r1 r2 \<rightarrow> injval (ALT r1 r2) c v"
   492   proof (cases)
   492   proof (cases)
   493     case left
   493     case left
   494     have "s \<in> der c r1 \<rightarrow> v'" by fact
   494     have "s \<in> der c r1 \<rightarrow> v'" by fact
   495     then have "(c # s) \<in> r1 \<rightarrow> injval r1 c v'" using IH1 by simp
   495     then have "(c # s) \<in> r1 \<rightarrow> injval r1 c v'" using IH1 by simp
   496     then have "(c # s) \<in> ALT r1 r2 \<rightarrow> injval (ALT r1 r2) c (Left v')" by (auto intro: PMatch.intros)
   496     then have "(c # s) \<in> ALT r1 r2 \<rightarrow> injval (ALT r1 r2) c (Left v')" by (auto intro: Posix.intros)
   497     then show "(c # s) \<in> ALT r1 r2 \<rightarrow> injval (ALT r1 r2) c v" using left by simp
   497     then show "(c # s) \<in> ALT r1 r2 \<rightarrow> injval (ALT r1 r2) c v" using left by simp
   498   next 
   498   next 
   499     case right
   499     case right
   500     have "s \<notin> L (der c r1)" by fact
   500     have "s \<notin> L (der c r1)" by fact
   501     then have "c # s \<notin> L r1" by (simp add: der_correctness Der_def)
   501     then have "c # s \<notin> L r1" by (simp add: der_correctness Der_def)
   502     moreover 
   502     moreover 
   503     have "s \<in> der c r2 \<rightarrow> v'" by fact
   503     have "s \<in> der c r2 \<rightarrow> v'" by fact
   504     then have "(c # s) \<in> r2 \<rightarrow> injval r2 c v'" using IH2 by simp
   504     then have "(c # s) \<in> r2 \<rightarrow> injval r2 c v'" using IH2 by simp
   505     ultimately have "(c # s) \<in> ALT r1 r2 \<rightarrow> injval (ALT r1 r2) c (Right v')" 
   505     ultimately have "(c # s) \<in> ALT r1 r2 \<rightarrow> injval (ALT r1 r2) c (Right v')" 
   506       by (auto intro: PMatch.intros)
   506       by (auto intro: Posix.intros)
   507     then show "(c # s) \<in> ALT r1 r2 \<rightarrow> injval (ALT r1 r2) c v" using right by simp
   507     then show "(c # s) \<in> ALT r1 r2 \<rightarrow> injval (ALT r1 r2) c v" using right by simp
   508   qed
   508   qed
   509 next
   509 next
   510   case (SEQ r1 r2)
   510   case (SEQ r1 r2)
   511   have IH1: "\<And>s v. s \<in> der c r1 \<rightarrow> v \<Longrightarrow> (c # s) \<in> r1 \<rightarrow> injval r1 c v" by fact
   511   have IH1: "\<And>s v. s \<in> der c r1 \<rightarrow> v \<Longrightarrow> (c # s) \<in> r1 \<rightarrow> injval r1 c v" by fact
   521         "s \<in> der c r2 \<rightarrow> v1" "nullable r1" "s1 @ s2 \<notin> L (SEQ (der c r1) r2)"
   521         "s \<in> der c r2 \<rightarrow> v1" "nullable r1" "s1 @ s2 \<notin> L (SEQ (der c r1) r2)"
   522       | (not_nullable) v1 v2 s1 s2 where
   522       | (not_nullable) v1 v2 s1 s2 where
   523         "v = Seq v1 v2" "s = s1 @ s2" 
   523         "v = Seq v1 v2" "s = s1 @ s2" 
   524         "s1 \<in> der c r1 \<rightarrow> v1" "s2 \<in> r2 \<rightarrow> v2" "\<not>nullable r1" 
   524         "s1 \<in> der c r1 \<rightarrow> v1" "s2 \<in> r2 \<rightarrow> v2" "\<not>nullable r1" 
   525         "\<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 (der c r1) \<and> s\<^sub>4 \<in> L r2)"
   525         "\<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 (der c r1) \<and> s\<^sub>4 \<in> L r2)"
   526         by (force split: if_splits elim!: PMatch_elims simp add: Sequ_def der_correctness Der_def)   
   526         by (force split: if_splits elim!: Posix_elims simp add: Sequ_def der_correctness Der_def)   
   527   then show "(c # s) \<in> SEQ r1 r2 \<rightarrow> injval (SEQ r1 r2) c v" 
   527   then show "(c # s) \<in> SEQ r1 r2 \<rightarrow> injval (SEQ r1 r2) c v" 
   528     proof (cases)
   528     proof (cases)
   529       case left_nullable
   529       case left_nullable
   530       have "s1 \<in> der c r1 \<rightarrow> v1" by fact
   530       have "s1 \<in> der c r1 \<rightarrow> v1" by fact
   531       then have "(c # s1) \<in> r1 \<rightarrow> injval r1 c v1" using IH1 by simp
   531       then have "(c # s1) \<in> r1 \<rightarrow> injval r1 c v1" using IH1 by simp
   532       moreover
   532       moreover
   533       have "\<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 (der c r1) \<and> s\<^sub>4 \<in> L r2)" by fact
   533       have "\<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 (der c r1) \<and> s\<^sub>4 \<in> L r2)" by fact
   534       then have "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> (c # s1) @ s\<^sub>3 \<in> L r1 \<and> s\<^sub>4 \<in> L r2)" by (simp add: der_correctness Der_def)
   534       then have "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> (c # s1) @ s\<^sub>3 \<in> L r1 \<and> s\<^sub>4 \<in> L r2)" by (simp add: der_correctness Der_def)
   535       ultimately have "((c # s1) @ s2) \<in> SEQ r1 r2 \<rightarrow> Seq (injval r1 c v1) v2" using left_nullable by (rule_tac PMatch.intros)
   535       ultimately have "((c # s1) @ s2) \<in> SEQ r1 r2 \<rightarrow> Seq (injval r1 c v1) v2" using left_nullable by (rule_tac Posix.intros)
   536       then show "(c # s) \<in> SEQ r1 r2 \<rightarrow> injval (SEQ r1 r2) c v" using left_nullable by simp
   536       then show "(c # s) \<in> SEQ r1 r2 \<rightarrow> injval (SEQ r1 r2) c v" using left_nullable by simp
   537     next
   537     next
   538       case right_nullable
   538       case right_nullable
   539       have "nullable r1" by fact
   539       have "nullable r1" by fact
   540       then have "[] \<in> r1 \<rightarrow> (mkeps r1)" by (rule PMatch_mkeps)
   540       then have "[] \<in> r1 \<rightarrow> (mkeps r1)" by (rule Posix_mkeps)
   541       moreover
   541       moreover
   542       have "s \<in> der c r2 \<rightarrow> v1" by fact
   542       have "s \<in> der c r2 \<rightarrow> v1" by fact
   543       then have "(c # s) \<in> r2 \<rightarrow> (injval r2 c v1)" using IH2 by simp
   543       then have "(c # s) \<in> r2 \<rightarrow> (injval r2 c v1)" using IH2 by simp
   544       moreover
   544       moreover
   545       have "s1 @ s2 \<notin> L (SEQ (der c r1) r2)" by fact
   545       have "s1 @ s2 \<notin> L (SEQ (der c r1) r2)" by fact
   546       then have "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = c # s \<and> [] @ s\<^sub>3 \<in> L r1 \<and> s\<^sub>4 \<in> L r2)" using right_nullable
   546       then have "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = c # s \<and> [] @ s\<^sub>3 \<in> L r1 \<and> s\<^sub>4 \<in> L r2)" using right_nullable
   547         by(auto simp add: der_correctness Der_def append_eq_Cons_conv Sequ_def)
   547         by(auto simp add: der_correctness Der_def append_eq_Cons_conv Sequ_def)
   548       ultimately have "([] @ (c # s)) \<in> SEQ r1 r2 \<rightarrow> Seq (mkeps r1) (injval r2 c v1)"
   548       ultimately have "([] @ (c # s)) \<in> SEQ r1 r2 \<rightarrow> Seq (mkeps r1) (injval r2 c v1)"
   549       by(rule PMatch.intros)
   549       by(rule Posix.intros)
   550       then show "(c # s) \<in> SEQ r1 r2 \<rightarrow> injval (SEQ r1 r2) c v" using right_nullable by simp
   550       then show "(c # s) \<in> SEQ r1 r2 \<rightarrow> injval (SEQ r1 r2) c v" using right_nullable by simp
   551     next
   551     next
   552       case not_nullable
   552       case not_nullable
   553       have "s1 \<in> der c r1 \<rightarrow> v1" by fact
   553       have "s1 \<in> der c r1 \<rightarrow> v1" by fact
   554       then have "(c # s1) \<in> r1 \<rightarrow> injval r1 c v1" using IH1 by simp
   554       then have "(c # s1) \<in> r1 \<rightarrow> injval r1 c v1" using IH1 by simp
   555       moreover
   555       moreover
   556       have "\<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 (der c r1) \<and> s\<^sub>4 \<in> L r2)" by fact
   556       have "\<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 (der c r1) \<and> s\<^sub>4 \<in> L r2)" by fact
   557       then have "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> (c # s1) @ s\<^sub>3 \<in> L r1 \<and> s\<^sub>4 \<in> L r2)" by (simp add: der_correctness Der_def)
   557       then have "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> (c # s1) @ s\<^sub>3 \<in> L r1 \<and> s\<^sub>4 \<in> L r2)" by (simp add: der_correctness Der_def)
   558       ultimately have "((c # s1) @ s2) \<in> SEQ r1 r2 \<rightarrow> Seq (injval r1 c v1) v2" using not_nullable 
   558       ultimately have "((c # s1) @ s2) \<in> SEQ r1 r2 \<rightarrow> Seq (injval r1 c v1) v2" using not_nullable 
   559         by (rule_tac PMatch.intros) (simp_all) 
   559         by (rule_tac Posix.intros) (simp_all) 
   560       then show "(c # s) \<in> SEQ r1 r2 \<rightarrow> injval (SEQ r1 r2) c v" using not_nullable by simp
   560       then show "(c # s) \<in> SEQ r1 r2 \<rightarrow> injval (SEQ r1 r2) c v" using not_nullable by simp
   561     qed
   561     qed
   562 next
   562 next
   563   case (STAR r)
   563   case (STAR r)
   564   have IH: "\<And>s v. s \<in> der c r \<rightarrow> v \<Longrightarrow> (c # s) \<in> r \<rightarrow> injval r c v" by fact
   564   have IH: "\<And>s v. s \<in> der c r \<rightarrow> v \<Longrightarrow> (c # s) \<in> r \<rightarrow> injval r c v" by fact
   566   then consider
   566   then consider
   567       (cons) v1 vs s1 s2 where 
   567       (cons) v1 vs s1 s2 where 
   568         "v = Seq v1 (Stars vs)" "s = s1 @ s2" 
   568         "v = Seq v1 (Stars vs)" "s = s1 @ s2" 
   569         "s1 \<in> der c r \<rightarrow> v1" "s2 \<in> (STAR r) \<rightarrow> (Stars vs)"
   569         "s1 \<in> der c r \<rightarrow> v1" "s2 \<in> (STAR r) \<rightarrow> (Stars vs)"
   570         "\<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 (der c r) \<and> s\<^sub>4 \<in> L (STAR r))" 
   570         "\<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 (der c r) \<and> s\<^sub>4 \<in> L (STAR r))" 
   571         apply(auto elim!: PMatch_elims(1-4) simp add: der_correctness Der_def intro: PMatch.intros)
   571         apply(auto elim!: Posix_elims(1-4) simp add: der_correctness Der_def intro: Posix.intros)
   572         apply(rotate_tac 3)
   572         apply(rotate_tac 3)
   573         apply(erule_tac PMatch_elims(5))
   573         apply(erule_tac Posix_elims(5))
   574         apply (simp add: PMatch.intros(6))
   574         apply (simp add: Posix.intros(6))
   575         using PMatch.intros(7) by blast
   575         using Posix.intros(7) by blast
   576     then show "(c # s) \<in> STAR r \<rightarrow> injval (STAR r) c v" 
   576     then show "(c # s) \<in> STAR r \<rightarrow> injval (STAR r) c v" 
   577     proof (cases)
   577     proof (cases)
   578       case cons
   578       case cons
   579           have "s1 \<in> der c r \<rightarrow> v1" by fact
   579           have "s1 \<in> der c r \<rightarrow> v1" by fact
   580           then have "(c # s1) \<in> r \<rightarrow> injval r c v1" using IH by simp
   580           then have "(c # s1) \<in> r \<rightarrow> injval r c v1" using IH by simp
   581         moreover
   581         moreover
   582           have "s2 \<in> STAR r \<rightarrow> Stars vs" by fact
   582           have "s2 \<in> STAR r \<rightarrow> Stars vs" by fact
   583         moreover 
   583         moreover 
   584           have "(c # s1) \<in> r \<rightarrow> injval r c v1" by fact 
   584           have "(c # s1) \<in> r \<rightarrow> injval r c v1" by fact 
   585           then have "flat (injval r c v1) = (c # s1)" by (rule PMatch1)
   585           then have "flat (injval r c v1) = (c # s1)" by (rule Posix1)
   586           then have "flat (injval r c v1) \<noteq> []" by simp
   586           then have "flat (injval r c v1) \<noteq> []" by simp
   587         moreover 
   587         moreover 
   588           have "\<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 (der c r) \<and> s\<^sub>4 \<in> L (STAR r))" by fact
   588           have "\<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 (der c r) \<and> s\<^sub>4 \<in> L (STAR r))" by fact
   589           then have "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> (c # s1) @ s\<^sub>3 \<in> L r \<and> s\<^sub>4 \<in> L (STAR r))" 
   589           then have "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> (c # s1) @ s\<^sub>3 \<in> L r \<and> s\<^sub>4 \<in> L (STAR r))" 
   590             by (simp add: der_correctness Der_def)
   590             by (simp add: der_correctness Der_def)
   591         ultimately 
   591         ultimately 
   592         have "((c # s1) @ s2) \<in> STAR r \<rightarrow> Stars (injval r c v1 # vs)" by (rule PMatch.intros)
   592         have "((c # s1) @ s2) \<in> STAR r \<rightarrow> Stars (injval r c v1 # vs)" by (rule Posix.intros)
   593         then show "(c # s) \<in> STAR r \<rightarrow> injval (STAR r) c v" using cons by(simp)
   593         then show "(c # s) \<in> STAR r \<rightarrow> injval (STAR r) c v" using cons by(simp)
   594     qed
   594     qed
   595 qed
   595 qed
   596 
   596 
   597 
   597 
   645   assumes "s \<in> L r"
   645   assumes "s \<in> L r"
   646   shows "\<exists>v. lexer r s = Some(v) \<and> s \<in> r \<rightarrow> v"
   646   shows "\<exists>v. lexer r s = Some(v) \<and> s \<in> r \<rightarrow> v"
   647 using assms
   647 using assms
   648 apply(induct s arbitrary: r)
   648 apply(induct s arbitrary: r)
   649 apply(simp)
   649 apply(simp)
   650 apply (metis PMatch_mkeps nullable_correctness)
   650 apply (metis Posix_mkeps nullable_correctness)
   651 apply(drule_tac x="der a r" in meta_spec)
   651 apply(drule_tac x="der a r" in meta_spec)
   652 apply(drule meta_mp)
   652 apply(drule meta_mp)
   653 apply(simp add: der_correctness Der_def)
   653 apply(simp add: der_correctness Der_def)
   654 apply(auto)
   654 apply(auto)
   655 by (metis PMatch2_roy_version)
   655 by (metis Posix2_roy_version)
   656 
   656 
   657 lemma lex_correct3a:
   657 lemma lex_correct3a:
   658   shows "s \<in> L r \<longleftrightarrow> (\<exists>v. lexer r s = Some(v) \<and> s \<in> r \<rightarrow> v)"
   658   shows "s \<in> L r \<longleftrightarrow> (\<exists>v. lexer r s = Some(v) \<and> s \<in> r \<rightarrow> v)"
   659 using assms
   659 using assms
   660 apply(induct s arbitrary: r)
   660 apply(induct s arbitrary: r)
   661 apply(simp)
   661 apply(simp)
   662 apply (metis PMatch_mkeps nullable_correctness)
   662 apply (metis Posix_mkeps nullable_correctness)
   663 apply(drule_tac x="der a r" in meta_spec)
   663 apply(drule_tac x="der a r" in meta_spec)
   664 apply(auto)
   664 apply(auto)
   665 apply(metis PMatch2_roy_version)
   665 apply(metis Posix2_roy_version)
   666 apply(simp add: der_correctness Der_def)
   666 apply(simp add: der_correctness Der_def)
   667 using lex_correct1a 
   667 using lex_correct1a 
   668 apply fastforce
   668 apply fastforce
   669 apply(simp add: der_correctness Der_def)
   669 apply(simp add: der_correctness Der_def)
   670 by (simp add: lex_correct1a)
   670 by (simp add: lex_correct1a)
   672 lemma lex_correct3b:
   672 lemma lex_correct3b:
   673   shows "s \<in> L r \<longleftrightarrow> (\<exists>!v. lexer r s = Some(v) \<and> s \<in> r \<rightarrow> v)"
   673   shows "s \<in> L r \<longleftrightarrow> (\<exists>!v. lexer r s = Some(v) \<and> s \<in> r \<rightarrow> v)"
   674 using assms
   674 using assms
   675 apply(induct s arbitrary: r)
   675 apply(induct s arbitrary: r)
   676 apply(simp)
   676 apply(simp)
   677 apply (metis PMatch_mkeps nullable_correctness)
   677 apply (metis Posix_mkeps nullable_correctness)
   678 apply(drule_tac x="der a r" in meta_spec)
   678 apply(drule_tac x="der a r" in meta_spec)
   679 apply(simp add: der_correctness Der_def)
   679 apply(simp add: der_correctness Der_def)
   680 apply(case_tac "lexer (der a r) s = None")
   680 apply(case_tac "lexer (der a r) s = None")
   681 apply(simp)
   681 apply(simp)
   682 apply(simp)
   682 apply(simp)
   683 apply(clarify)
   683 apply(clarify)
   684 apply(rule iffI)
   684 apply(rule iffI)
   685 apply(auto)
   685 apply(auto)
   686 apply(rule PMatch2_roy_version)
   686 apply(rule Posix2_roy_version)
   687 apply(simp)
   687 apply(simp)
   688 using PMatch1(1) by auto
   688 using Posix1(1) by auto
   689 
   689 
   690 section {* Lexer including simplifications *}
   690 section {* Lexer including simplifications *}
   691 
   691 
   692 
   692 
   693 fun F_RIGHT where
   693 fun F_RIGHT where