thys/Positions.thy
changeset 251 925232418a15
parent 250 8927b737936f
child 252 022b80503766
equal deleted inserted replaced
250:8927b737936f 251:925232418a15
    19 | "Pos (Char c) = {[]}"
    19 | "Pos (Char c) = {[]}"
    20 | "Pos (Left v) = {[]} \<union> {0#ps | ps. ps \<in> Pos v}"
    20 | "Pos (Left v) = {[]} \<union> {0#ps | ps. ps \<in> Pos v}"
    21 | "Pos (Right v) = {[]} \<union> {1#ps | ps. ps \<in> Pos v}"
    21 | "Pos (Right v) = {[]} \<union> {1#ps | ps. ps \<in> Pos v}"
    22 | "Pos (Seq v1 v2) = {[]} \<union> {0#ps | ps. ps \<in> Pos v1} \<union> {1#ps | ps. ps \<in> Pos v2}" 
    22 | "Pos (Seq v1 v2) = {[]} \<union> {0#ps | ps. ps \<in> Pos v1} \<union> {1#ps | ps. ps \<in> Pos v2}" 
    23 | "Pos (Stars []) = {[]}"
    23 | "Pos (Stars []) = {[]}"
    24 | "Pos (Stars (v#vs)) = {[]} \<union> {0#ps | ps. ps \<in> Pos v} \<union> {(Suc n)#ps | n ps. n#ps \<in> Pos (Stars vs)}"
    24 | "Pos (Stars (v#vs)) = {[]} \<union> {0#ps | ps. ps \<in> Pos v} \<union> {Suc n#ps | n ps. n#ps \<in> Pos (Stars vs)}"
    25 
    25 
    26 lemma Pos_empty:
    26 lemma Pos_empty:
    27   shows "[] \<in> Pos v"
    27   shows "[] \<in> Pos v"
    28 apply(induct v rule: Pos.induct)
    28 by (induct v rule: Pos.induct)(auto)
    29 apply(auto)
       
    30 done
       
    31 
    29 
    32 fun intlen :: "'a list \<Rightarrow> int"
    30 fun intlen :: "'a list \<Rightarrow> int"
    33 where
    31 where
    34   "intlen [] = 0"
    32   "intlen [] = 0"
    35 | "intlen (x#xs) = 1 + intlen xs"
    33 | "intlen (x#xs) = 1 + intlen xs"
    36 
    34 
    37 lemma inlen_bigger:
    35 lemma inlen_bigger:
    38   shows "0 \<le> intlen xs"
    36   shows "0 \<le> intlen xs"
    39 apply(induct xs)
    37 by (induct xs)(auto)
    40 apply(auto)
       
    41 done 
       
    42 
    38 
    43 lemma intlen_append:
    39 lemma intlen_append:
    44   shows "intlen (xs @ ys) = intlen xs + intlen ys"
    40   shows "intlen (xs @ ys) = intlen xs + intlen ys"
    45 apply(induct xs arbitrary: ys)
    41 by (induct xs arbitrary: ys) (auto)
    46 apply(auto)
       
    47 done 
       
    48 
    42 
    49 lemma intlen_length:
    43 lemma intlen_length:
    50   assumes "length xs < length ys"
    44   assumes "length xs < length ys"
    51   shows "intlen xs < intlen ys"
    45   shows "intlen xs < intlen ys"
    52 using assms
    46 using assms
    67   and   "pflat_len (Seq v1 v2) (Suc 0#p) = pflat_len v2 p"
    61   and   "pflat_len (Seq v1 v2) (Suc 0#p) = pflat_len v2 p"
    68   and   "pflat_len (Left v) (0#p) = pflat_len v p"
    62   and   "pflat_len (Left v) (0#p) = pflat_len v p"
    69   and   "pflat_len (Left v) (Suc 0#p) = -1"
    63   and   "pflat_len (Left v) (Suc 0#p) = -1"
    70   and   "pflat_len (Right v) (Suc 0#p) = pflat_len v p"
    64   and   "pflat_len (Right v) (Suc 0#p) = pflat_len v p"
    71   and   "pflat_len (Right v) (0#p) = -1"
    65   and   "pflat_len (Right v) (0#p) = -1"
       
    66   and   "pflat_len (Stars (v#vs)) (Suc n#p) = pflat_len (Stars vs) (n#p)"
       
    67   and   "pflat_len (Stars (v#vs)) (0#p) = pflat_len v p"
    72   and   "pflat_len v [] = intlen (flat v)"
    68   and   "pflat_len v [] = intlen (flat v)"
    73 apply(auto simp add: pflat_len_def Pos_empty)
    69 by (auto simp add: pflat_len_def Pos_empty)
    74 done
       
    75 
    70 
    76 lemma pflat_len_Stars_simps:
    71 lemma pflat_len_Stars_simps:
    77   assumes "n < length vs"
    72   assumes "n < length vs"
    78   shows "pflat_len (Stars vs) (n#p) = pflat_len (vs!n) p"
    73   shows "pflat_len (Stars vs) (n#p) = pflat_len (vs!n) p"
    79 using assms 
    74 using assms 
    80 apply(induct vs arbitrary: n p)
    75 apply(induct vs arbitrary: n p)
    81 apply(simp)
    76 apply(auto simp add: less_Suc_eq_0_disj pflat_len_simps)
    82 apply(simp)
       
    83 apply(simp add: pflat_len_def)
       
    84 apply(auto)[1]
       
    85 apply (metis at.simps(6))
       
    86 apply (metis Suc_less_eq Suc_pred)
       
    87 by (metis diff_Suc_1 less_Suc_eq_0_disj nth_Cons')
       
    88 
       
    89 
       
    90 lemma pflat_len_Stars_simps2:
       
    91   shows "pflat_len (Stars (v#vs)) (Suc n # p) = pflat_len (Stars vs) (n#p)"
       
    92   and   "pflat_len (Stars (v#vs)) (0 # p) = pflat_len v p"
       
    93 using assms 
       
    94 apply(simp_all add: pflat_len_def)
       
    95 done
    77 done
    96 
    78 
    97 lemma Two_to_Three_aux:
    79 lemma Two_to_Three_aux:
    98   assumes "p \<in> Pos v1 \<union> Pos v2" "pflat_len v1 p = pflat_len v2 p"
    80   assumes "p \<in> Pos v1 \<union> Pos v2" "pflat_len v1 p = pflat_len v2 p"
    99   shows "p \<in> Pos v1 \<inter> Pos v2"
    81   shows "p \<in> Pos v1 \<inter> Pos v2"
   100 using assms
    82 using assms
   101 apply(simp add: pflat_len_def)
    83 apply(simp add: pflat_len_def)
   102 apply(auto split: if_splits)
    84 apply(auto split: if_splits)
   103 apply (smt inlen_bigger)+
    85 apply (smt inlen_bigger)+
   104 done
    86 done
   105 
       
   106 
    87 
   107 lemma Two_to_Three_orig:
    88 lemma Two_to_Three_orig:
   108   assumes "\<forall>p \<in> Pos v1 \<union> Pos v2. pflat_len v1 p = pflat_len v2 p"
    89   assumes "\<forall>p \<in> Pos v1 \<union> Pos v2. pflat_len v1 p = pflat_len v2 p"
   109   shows "Pos v1 = Pos v2"
    90   shows "Pos v1 = Pos v2"
   110 using assms
    91 using assms
   306 
   287 
   307 definition sprefix_list:: "'a list \<Rightarrow> 'a list \<Rightarrow> bool" ("_ \<sqsubset>spre _")
   288 definition sprefix_list:: "'a list \<Rightarrow> 'a list \<Rightarrow> bool" ("_ \<sqsubset>spre _")
   308 where
   289 where
   309   "ps1 \<sqsubset>spre ps2 \<equiv> (ps1 \<sqsubseteq>pre ps2 \<and> ps1 \<noteq> ps2)"
   290   "ps1 \<sqsubset>spre ps2 \<equiv> (ps1 \<sqsubseteq>pre ps2 \<and> ps1 \<noteq> ps2)"
   310 
   291 
   311 inductive lex_lists :: "nat list \<Rightarrow> nat list \<Rightarrow> bool" ("_ \<sqsubset>lex _")
   292 inductive lex_list :: "nat list \<Rightarrow> nat list \<Rightarrow> bool" ("_ \<sqsubset>lex _")
   312 where
   293 where
   313   "[] \<sqsubset>lex p#ps"
   294   "[] \<sqsubset>lex p#ps"
   314 | "ps1 \<sqsubset>lex ps2 \<Longrightarrow> (p#ps1) \<sqsubset>lex (p#ps2)"
   295 | "ps1 \<sqsubset>lex ps2 \<Longrightarrow> (p#ps1) \<sqsubset>lex (p#ps2)"
   315 | "p1 < p2 \<Longrightarrow> (p1#ps1) \<sqsubset>lex (p2#ps2)"
   296 | "p1 < p2 \<Longrightarrow> (p1#ps1) \<sqsubset>lex (p2#ps2)"
   316 
   297 
   317 lemma lex_irrfl:
   298 lemma lex_irrfl:
   318   fixes ps1 ps2 :: "nat list"
   299   fixes ps1 ps2 :: "nat list"
   319   assumes "ps1 \<sqsubset>lex ps2"
   300   assumes "ps1 \<sqsubset>lex ps2"
   320   shows "ps1 \<noteq> ps2"
   301   shows "ps1 \<noteq> ps2"
   321 using assms
   302 using assms
   322 apply(induct rule: lex_lists.induct)
   303 apply(induct rule: lex_list.induct)
   323 apply(auto)
   304 apply(auto)
   324 done
   305 done
   325 
   306 
   326 lemma lex_append:
   307 lemma lex_simps [simp]:
   327   assumes "ps2 \<noteq> []"  
       
   328   shows "ps \<sqsubset>lex ps @ ps2"
       
   329 using assms
       
   330 apply(induct ps)
       
   331 apply(auto intro: lex_lists.intros)
       
   332 apply(case_tac ps2)
       
   333 apply(simp)
       
   334 apply(simp)
       
   335 apply(auto intro: lex_lists.intros)
       
   336 done
       
   337 
       
   338 lemma lexordp_simps [simp]:
       
   339   fixes xs ys :: "nat list"
   308   fixes xs ys :: "nat list"
   340   shows "[] \<sqsubset>lex ys = (ys \<noteq> [])"
   309   shows "[] \<sqsubset>lex ys \<longleftrightarrow> ys \<noteq> []"
   341   and   "xs \<sqsubset>lex [] = False"
   310   and   "xs \<sqsubset>lex [] \<longleftrightarrow> False"
   342   and   "(x # xs) \<sqsubset>lex (y # ys) \<longleftrightarrow> (x < y \<or> (\<not> y < x \<and> xs \<sqsubset>lex ys))"
   311   and   "(x # xs) \<sqsubset>lex (y # ys) \<longleftrightarrow> (x < y \<or> (\<not> y < x \<and> xs \<sqsubset>lex ys))"
   343 apply -
   312 apply -
   344 apply (metis lex_append lex_lists.simps list.simps(3))
   313 apply (metis lex_irrfl lex_list.intros(1) list.exhaust)
   345 using lex_lists.cases apply blast
   314 using lex_list.cases apply blast
   346 using lex_lists.cases lex_lists.intros(2) lex_lists.intros(3) not_less_iff_gr_or_eq by fastforce
   315 using lex_list.cases lex_list.intros(2) lex_list.intros(3) not_less_iff_gr_or_eq by fastforce
   347 
   316 
   348 lemma lex_append_cancel [simp]:
       
   349   fixes ps ps1 ps2 :: "nat list"
       
   350   shows "ps @ ps1 \<sqsubset>lex ps @ ps2 \<longleftrightarrow> ps1 \<sqsubset>lex ps2"
       
   351 apply(induct ps)
       
   352 apply(auto)
       
   353 done
       
   354 
   317 
   355 lemma lex_trans:
   318 lemma lex_trans:
   356   fixes ps1 ps2 ps3 :: "nat list"
   319   fixes ps1 ps2 ps3 :: "nat list"
   357   assumes "ps1 \<sqsubset>lex ps2" "ps2 \<sqsubset>lex ps3"
   320   assumes "ps1 \<sqsubset>lex ps2" "ps2 \<sqsubset>lex ps3"
   358   shows "ps1 \<sqsubset>lex ps3"
   321   shows "ps1 \<sqsubset>lex ps3"
   359 using assms
   322 using assms
   360 apply(induct arbitrary: ps3 rule: lex_lists.induct)
   323 apply(induct arbitrary: ps3 rule: lex_list.induct)
   361 apply(erule lex_lists.cases)
   324 apply(erule lex_list.cases)
   362 apply(simp_all)
   325 apply(simp_all)
   363 apply(rotate_tac 2)
   326 apply(rotate_tac 2)
   364 apply(erule lex_lists.cases)
   327 apply(erule lex_list.cases)
   365 apply(simp_all)
   328 apply(simp_all)
   366 apply(erule lex_lists.cases)
   329 apply(erule lex_list.cases)
   367 apply(simp_all)
   330 apply(simp_all)
   368 done
   331 done
   369 
   332 
   370 lemma trichotomous_aux:
       
   371   fixes p q :: "nat list"
       
   372   assumes "p \<sqsubset>lex q" "p \<noteq> q"
       
   373   shows "\<not>(q \<sqsubset>lex p)"
       
   374 using assms
       
   375 apply(induct rule: lex_lists.induct)
       
   376 apply(auto)
       
   377 done
       
   378 
       
   379 lemma trichotomous_aux2:
       
   380   fixes p q :: "nat list"
       
   381   assumes "p \<sqsubset>lex q" "q \<sqsubset>lex p"
       
   382   shows "False"
       
   383 using assms
       
   384 apply(induct rule: lex_lists.induct)
       
   385 apply(auto)
       
   386 done
       
   387 
   333 
   388 lemma trichotomous:
   334 lemma trichotomous:
   389   fixes p q :: "nat list"
   335   fixes p q :: "nat list"
   390   shows "p = q \<or> p \<sqsubset>lex q \<or> q \<sqsubset>lex p"
   336   shows "p = q \<or> p \<sqsubset>lex q \<or> q \<sqsubset>lex p"
   391 apply(induct p arbitrary: q)
   337 apply(induct p arbitrary: q)
   392 apply(auto)
   338 apply(auto)
   393 apply(case_tac q)
   339 apply(case_tac q)
   394 apply(auto)
   340 apply(auto)
   395 done
   341 done
   396 
   342 
   397 (*
       
   398 definition dpos :: "val \<Rightarrow> val \<Rightarrow> nat list \<Rightarrow> bool" 
       
   399   where
       
   400   "dpos v1 v2 p \<equiv> (p \<in> Pos v1 \<union> Pos v2) \<and> (p \<notin> Pos v1 \<inter> Pos v2)"
       
   401 *)
       
   402 
       
   403 lemma outside_lemma:
   343 lemma outside_lemma:
   404   assumes "p \<notin> Pos v1 \<union> Pos v2"
   344   assumes "p \<notin> Pos v1 \<union> Pos v2"
   405   shows "pflat_len v1 p = pflat_len v2 p"
   345   shows "pflat_len v1 p = pflat_len v2 p"
   406 using assms
   346 using assms
   407 apply(auto simp add: pflat_len_def)
   347 apply(auto simp add: pflat_len_def)
   408 done
   348 done
   409 
       
   410 (*
       
   411 lemma dpos_lemma_aux:
       
   412   assumes "p \<in> Pos v1 \<union> Pos v2"
       
   413   and "pflat_len v1 p = pflat_len v2 p"
       
   414   shows "p \<in> Pos v1 \<inter> Pos v2"
       
   415 using assms
       
   416 apply(auto simp add: pflat_len_def)
       
   417 apply (smt inlen_bigger)
       
   418 apply (smt inlen_bigger)
       
   419 done
       
   420 
       
   421 lemma dpos_lemma:
       
   422   assumes "p \<in> Pos v1 \<union> Pos v2"
       
   423   and "pflat_len v1 p = pflat_len v2 p"
       
   424   shows "\<not>dpos v1 v2 p"
       
   425 using assms
       
   426 apply(auto simp add: dpos_def dpos_lemma_aux)
       
   427 using dpos_lemma_aux apply auto[1]
       
   428 using dpos_lemma_aux apply auto[1]
       
   429 done
       
   430 
       
   431 lemma dpos_lemma2:
       
   432   assumes "p \<in> Pos v1 \<union> Pos v2"
       
   433   and "dpos v1 v2 p"
       
   434   shows "pflat_len v1 p \<noteq> pflat_len v2 p"
       
   435 using assms
       
   436 using dpos_lemma by blast
       
   437 *)
       
   438 
   349 
   439 definition val_ord:: "val \<Rightarrow> nat list \<Rightarrow> val \<Rightarrow> bool" ("_ \<sqsubset>val _ _")
   350 definition val_ord:: "val \<Rightarrow> nat list \<Rightarrow> val \<Rightarrow> bool" ("_ \<sqsubset>val _ _")
   440 where
   351 where
   441   "v1 \<sqsubset>val p v2 \<equiv> (p \<in> Pos v1 \<and> pflat_len v1 p > pflat_len v2 p \<and>
   352   "v1 \<sqsubset>val p v2 \<equiv> (p \<in> Pos v1 \<and> pflat_len v1 p > pflat_len v2 p \<and>
   442                    (\<forall>q \<in> Pos v1 \<union> Pos v2. q \<sqsubset>lex p \<longrightarrow> pflat_len v1 q = pflat_len v2 q))"
   353                    (\<forall>q \<in> Pos v1 \<union> Pos v2. q \<sqsubset>lex p \<longrightarrow> pflat_len v1 q = pflat_len v2 q))"
   451   "v1 :\<sqsubseteq>val v2 \<equiv> v1 :\<sqsubset>val v2 \<or> v1 = v2"
   362   "v1 :\<sqsubseteq>val v2 \<equiv> v1 :\<sqsubset>val v2 \<or> v1 = v2"
   452 
   363 
   453 lemma val_ord_shorterI:
   364 lemma val_ord_shorterI:
   454   assumes "length (flat v') < length (flat v)"
   365   assumes "length (flat v') < length (flat v)"
   455   shows "v :\<sqsubset>val v'" 
   366   shows "v :\<sqsubset>val v'" 
   456 using assms(1)
   367 using assms
   457 apply(subst val_ord_ex_def)
   368 unfolding val_ord_ex_def
   458 apply(rule_tac x="[]" in exI)
   369 by (metis Pos_empty intlen_length lex_simps(2) pflat_len_simps(9) val_ord_def)
   459 apply(subst val_ord_def)
   370 
   460 apply(rule conjI)
   371 lemma val_ord_spreI:
   461 apply (simp add: Pos_empty)
       
   462 apply(rule conjI)
       
   463 apply(simp add: pflat_len_simps)
       
   464 apply (simp add: intlen_length)
       
   465 apply(simp)
       
   466 done
       
   467 
       
   468 lemma val_ord_spre:
       
   469   assumes "(flat v') \<sqsubset>spre (flat v)"
   372   assumes "(flat v') \<sqsubset>spre (flat v)"
   470   shows "v :\<sqsubset>val v'" 
   373   shows "v :\<sqsubset>val v'" 
       
   374 using assms
       
   375 apply(rule_tac val_ord_shorterI)
       
   376 by (metis append_eq_conv_conj le_less_linear prefix_list_def sprefix_list_def take_all)
       
   377 
       
   378 lemma val_ord_LeftI:
       
   379   assumes "v :\<sqsubset>val v'" "flat v = flat v'"
       
   380   shows "(Left v) :\<sqsubset>val (Left v')" 
   471 using assms(1)
   381 using assms(1)
   472 apply(rule_tac val_ord_shorterI)
   382 unfolding val_ord_ex_def
   473 apply(simp add: sprefix_list_def prefix_list_def)
       
   474 apply(auto)
   383 apply(auto)
   475 apply(case_tac ps')
   384 apply(rule_tac x="0#p" in exI)
       
   385 using assms(2)
       
   386 apply(auto simp add: val_ord_def pflat_len_simps)
       
   387 done
       
   388 
       
   389 lemma val_ord_RightI:
       
   390   assumes "v :\<sqsubset>val v'" "flat v = flat v'"
       
   391   shows "(Right v) :\<sqsubset>val (Right v')" 
       
   392 using assms(1)
       
   393 unfolding val_ord_ex_def
   476 apply(auto)
   394 apply(auto)
   477 by (metis append_eq_conv_conj drop_all le_less_linear neq_Nil_conv)
   395 apply(rule_tac x="Suc 0#p" in exI)
   478 
       
   479 
       
   480 lemma val_ord_ALTI:
       
   481   assumes "v \<sqsubset>val p v'" "flat v = flat v'"
       
   482   shows "(Left v) \<sqsubset>val (0#p) (Left v')" 
       
   483 using assms(1)
       
   484 apply(subst (asm) val_ord_def)
       
   485 apply(erule conjE)
       
   486 apply(subst val_ord_def)
       
   487 apply(rule conjI)
       
   488 apply(simp)
       
   489 apply(rule conjI)
       
   490 apply(simp add: pflat_len_simps)
       
   491 apply(rule ballI)
       
   492 apply(rule impI)
       
   493 apply(simp only: Pos.simps)
       
   494 apply(auto)[1]
       
   495 using assms(2)
   396 using assms(2)
   496 apply(simp add: pflat_len_simps)
   397 apply(auto simp add: val_ord_def pflat_len_simps)
   497 apply(auto simp add: pflat_len_simps)[2]
   398 done
   498 done
   399 
   499 
       
   500 lemma val_ord_ALTI2:
       
   501   assumes "v \<sqsubset>val p v'" "flat v = flat v'"
       
   502   shows "(Right v) \<sqsubset>val (1#p) (Right v')" 
       
   503 using assms(1)
       
   504 apply(subst (asm) val_ord_def)
       
   505 apply(erule conjE)
       
   506 apply(subst val_ord_def)
       
   507 apply(rule conjI)
       
   508 apply(simp)
       
   509 apply(rule conjI)
       
   510 apply(simp add: pflat_len_simps)
       
   511 apply(rule ballI)
       
   512 apply(rule impI)
       
   513 apply(simp only: Pos.simps)
       
   514 apply(auto)[1]
       
   515 using assms(2)
       
   516 apply(simp add: pflat_len_simps)
       
   517 apply(auto simp add: pflat_len_simps)[2]
       
   518 done
       
   519 
   400 
   520 lemma val_ord_ALTE:
   401 lemma val_ord_ALTE:
   521   assumes "(Left v1) \<sqsubset>val (p # ps) (Left v2)"
   402   assumes "(Left v1) \<sqsubset>val (p # ps) (Left v2)"
   522   shows "p = 0 \<and> v1 \<sqsubset>val ps v2"
   403   shows "p = 0 \<and> v1 \<sqsubset>val ps v2"
   523 using assms(1)
   404 using assms(1)
   524 apply(simp add: val_ord_def)
   405 apply(simp add: val_ord_def)
   525 apply(auto simp add: pflat_len_simps)
   406 apply(auto simp add: pflat_len_simps)
   526 apply (metis (no_types, hide_lams) assms lex_lists.intros(2) outside_lemma pflat_len_simps(3) val_ord_def)
   407 apply (metis (no_types, hide_lams) assms lex_list.intros(2) outside_lemma pflat_len_simps(3) val_ord_def)
   527 by (metis (no_types, hide_lams) assms lex_lists.intros(2) outside_lemma pflat_len_simps(3) val_ord_def)
   408 by (metis (no_types, hide_lams) assms lex_list.intros(2) outside_lemma pflat_len_simps(3) val_ord_def)
   528 
   409 
   529 lemma val_ord_ALTE2:
   410 lemma val_ord_ALTE2:
   530   assumes "(Right v1) \<sqsubset>val (p # ps) (Right v2)"
   411   assumes "(Right v1) \<sqsubset>val (p # ps) (Right v2)"
   531   shows "p = 1 \<and> v1 \<sqsubset>val ps v2"
   412   shows "p = 1 \<and> v1 \<sqsubset>val ps v2"
   532 using assms(1)
   413 using assms(1)
   533 apply(simp add: val_ord_def)
   414 apply(simp add: val_ord_def)
   534 apply(auto simp add: pflat_len_simps)
   415 apply(auto simp add: pflat_len_simps)
   535 apply (metis (no_types, hide_lams) assms lex_lists.intros(2) outside_lemma pflat_len_simps(5) val_ord_def)
   416 apply (metis (no_types, hide_lams) assms lex_list.intros(2) outside_lemma pflat_len_simps(5) val_ord_def)
   536 by (metis (no_types, hide_lams) assms lex_lists.intros(2) outside_lemma pflat_len_simps(5) val_ord_def)
   417 by (metis (no_types, hide_lams) assms lex_list.intros(2) outside_lemma pflat_len_simps(5) val_ord_def)
   537 
   418 
   538 lemma val_ord_STARI:
   419 lemma val_ord_STARI:
   539   assumes "v1 \<sqsubset>val p v2" "flat (Stars (v1#vs1)) = flat (Stars (v2#vs2))"
   420   assumes "v1 \<sqsubset>val p v2" "flat (Stars (v1#vs1)) = flat (Stars (v2#vs2))"
   540   shows "(Stars (v1#vs1)) \<sqsubset>val (0#p) (Stars (v2#vs2))" 
   421   shows "(Stars (v1#vs1)) \<sqsubset>val (0#p) (Stars (v2#vs2))" 
   541 using assms(1)
   422 using assms(1)
   583 apply(rule ballI)
   464 apply(rule ballI)
   584 apply(rule impI)
   465 apply(rule impI)
   585 apply(simp)
   466 apply(simp)
   586 using assms(2)
   467 using assms(2)
   587 apply(auto)
   468 apply(auto)
   588 apply (simp add: pflat_len_simps(7))
   469 apply (simp add: pflat_len_simps(9))
   589 apply (simp add: pflat_len_Stars_simps)
   470 apply (simp add: pflat_len_Stars_simps)
   590 using assms(2)
   471 using assms(2)
   591 apply(auto simp add: pflat_len_def)[1]
   472 apply(auto simp add: pflat_len_def)[1]
   592 apply force
   473 apply force
   593 apply force
   474 apply force
   793 apply(simp add: val_ord_def)
   674 apply(simp add: val_ord_def)
   794 apply(auto)[1]
   675 apply(auto)[1]
   795 by (metis IntE Two_to_Three_aux UnCI lex_trans outside_lemma)
   676 by (metis IntE Two_to_Three_aux UnCI lex_trans outside_lemma)
   796 
   677 
   797 
   678 
   798 lemma Pos_pre:
       
   799   assumes "p \<in> Pos v" "q \<sqsubseteq>pre p"
       
   800   shows "q \<in> Pos v"
       
   801 using assms
       
   802 apply(induct v arbitrary: p q rule: Pos.induct)
       
   803 apply(simp_all add: prefix_list_def)
       
   804 apply (meson append_eq_Cons_conv append_is_Nil_conv)
       
   805 apply (meson append_eq_Cons_conv append_is_Nil_conv)
       
   806 apply (metis (no_types, lifting) Cons_eq_append_conv append_is_Nil_conv)
       
   807 apply(auto)
       
   808 apply (meson append_eq_Cons_conv)
       
   809 apply(simp add: append_eq_Cons_conv)
       
   810 apply(auto)
       
   811 done
       
   812 
       
   813 lemma lex_lists_order:
       
   814   assumes "q' \<sqsubset>lex q" "\<not>(q' \<sqsubseteq>pre q)"
       
   815   shows "\<not>(q \<sqsubset>lex q')"
       
   816 using assms
       
   817 apply(induct rule: lex_lists.induct)
       
   818 apply(simp add: prefix_list_def)
       
   819 apply(auto)
       
   820 using trichotomous_aux2 by auto
       
   821 
       
   822 lemma lex_appendL:
       
   823   assumes "q \<sqsubset>lex p" 
       
   824   shows "q \<sqsubset>lex p @ q'"
       
   825 using assms
       
   826 apply(induct arbitrary: q' rule: lex_lists.induct)
       
   827 apply(auto)
       
   828 done
       
   829 
       
   830 
       
   831 inductive 
   679 inductive 
   832   CPrf :: "val \<Rightarrow> rexp \<Rightarrow> bool" ("\<Turnstile> _ : _" [100, 100] 100)
   680   CPrf :: "val \<Rightarrow> rexp \<Rightarrow> bool" ("\<Turnstile> _ : _" [100, 100] 100)
   833 where
   681 where
   834  "\<lbrakk>\<Turnstile> v1 : r1; \<Turnstile> v2 : r2\<rbrakk> \<Longrightarrow> \<Turnstile>  Seq v1 v2 : SEQ r1 r2"
   682  "\<lbrakk>\<Turnstile> v1 : r1; \<Turnstile> v2 : r2\<rbrakk> \<Longrightarrow> \<Turnstile>  Seq v1 v2 : SEQ r1 r2"
   835 | "\<Turnstile> v1 : r1 \<Longrightarrow> \<Turnstile> Left v1 : ALT r1 r2"
   683 | "\<Turnstile> v1 : r1 \<Longrightarrow> \<Turnstile> Left v1 : ALT r1 r2"
   941 apply(auto simp add: CPT_def image_def intro: CPrf.intros)[1]
   789 apply(auto simp add: CPT_def image_def intro: CPrf.intros)[1]
   942 apply(erule CPrf.cases)
   790 apply(erule CPrf.cases)
   943 apply(simp_all)[7]
   791 apply(simp_all)[7]
   944 done
   792 done
   945 
   793 
   946 lemma CPTpre_SEQ:
       
   947   assumes "v \<in> CPTpre (SEQ r1 r2) s"
       
   948   shows "\<exists>s'. flat v = s' \<and> (s' \<sqsubseteq>pre s) \<and> s' \<in> L (SEQ r1 r2)"
       
   949 using assms
       
   950 apply(simp add: CPTpre_simps)
       
   951 apply(auto simp add: CPTpre_def)
       
   952 apply (simp add: prefix_list_def)
       
   953 by (metis L.simps(4) L_flat_Prf1 Prf.intros(1) Prf_CPrf flat.simps(5))
       
   954 
       
   955 term "{vs. Stars vs \<in> A}"
       
   956 
       
   957 lemma test: 
   794 lemma test: 
   958   assumes "finite A"
   795   assumes "finite A"
   959   shows "finite {vs. Stars vs \<in> A}"
   796   shows "finite {vs. Stars vs \<in> A}"
   960 using assms
   797 using assms
   961 apply(induct A)
   798 apply(induct A)
  1136 apply(erule disjE)
   973 apply(erule disjE)
  1137 apply(subst (asm) val_ord_ex_def)
   974 apply(subst (asm) val_ord_ex_def)
  1138 apply(erule exE)
   975 apply(erule exE)
  1139 apply(subst val_ord_ex1_def)
   976 apply(subst val_ord_ex1_def)
  1140 apply(rule disjI1)
   977 apply(rule disjI1)
       
   978 apply(rule val_ord_LeftI)
  1141 apply(subst val_ord_ex_def)
   979 apply(subst val_ord_ex_def)
  1142 apply(rule_tac x="0#p" in exI)
   980 apply(auto)[1]
  1143 apply(rule val_ord_ALTI)
       
  1144 apply(simp)
       
  1145 using Posix1(2) apply blast
   981 using Posix1(2) apply blast
  1146 using val_ord_ex1_def apply blast
   982 using val_ord_ex1_def apply blast
  1147 apply(subst val_ord_ex1_def)
   983 apply(subst val_ord_ex1_def)
  1148 apply(rule disjI1)
   984 apply(rule disjI1)
  1149 apply (simp add: Posix1(2) val_ord_shorterI)
   985 apply (simp add: Posix1(2) val_ord_shorterI)
  1190 apply(drule_tac x="v2a" in meta_spec)
  1026 apply(drule_tac x="v2a" in meta_spec)
  1191 apply(drule meta_mp)
  1027 apply(drule meta_mp)
  1192 apply(auto simp add: CPTpre_def)[1]
  1028 apply(auto simp add: CPTpre_def)[1]
  1193 apply(subst (asm) val_ord_ex1_def)
  1029 apply(subst (asm) val_ord_ex1_def)
  1194 apply(erule disjE)
  1030 apply(erule disjE)
  1195 apply(subst (asm) val_ord_ex_def)
       
  1196 apply(erule exE)
       
  1197 apply(subst val_ord_ex1_def)
  1031 apply(subst val_ord_ex1_def)
  1198 apply(rule disjI1)
  1032 apply(rule disjI1)
  1199 apply(subst val_ord_ex_def)
  1033 apply(rule val_ord_RightI)
  1200 apply(rule_tac x="1#p" in exI)
       
  1201 apply(rule val_ord_ALTI2)
       
  1202 apply(simp)
  1034 apply(simp)
  1203 using Posix1(2) apply blast
  1035 using Posix1(2) apply blast
  1204 apply (simp add: val_ord_ex1_def)
  1036 apply (simp add: val_ord_ex1_def)
  1205 apply(subst val_ord_ex1_def)
  1037 apply(subst val_ord_ex1_def)
  1206 apply(rule disjI1)
  1038 apply(rule disjI1)
  1251 apply (subst val_ord_ex1_def)
  1083 apply (subst val_ord_ex1_def)
  1252 apply(rule disjI1)
  1084 apply(rule disjI1)
  1253 apply (subst val_ord_ex_def)
  1085 apply (subst val_ord_ex_def)
  1254 apply(case_tac p)
  1086 apply(case_tac p)
  1255 apply(simp)
  1087 apply(simp)
  1256 apply (metis Posix1(2) flat_Stars not_less_iff_gr_or_eq pflat_len_simps(7) same_append_eq val_ord_def)
  1088 apply (metis Posix1(2) append_eq_conv_conj flat_Stars not_less_iff_gr_or_eq pflat_len_simps(9) val_ord_def)
       
  1089 
       
  1090 
       
  1091 
  1257 using Posix1(2) val_ord_STARI2 apply fastforce
  1092 using Posix1(2) val_ord_STARI2 apply fastforce
  1258 apply(simp add: val_ord_ex1_def)
  1093 apply(simp add: val_ord_ex1_def)
  1259 apply (subst (asm) val_ord_ex_def)
  1094 apply (subst (asm) val_ord_ex_def)
  1260 apply(erule exE)
  1095 apply(erule exE)
  1261 apply (subst val_ord_ex1_def)
  1096 apply (subst val_ord_ex1_def)
  1281 apply(simp(no_asm)  add: val_ord_def)
  1116 apply(simp(no_asm)  add: val_ord_def)
  1282 apply(rule conjI)
  1117 apply(rule conjI)
  1283 apply(simp add: val_ord_def)
  1118 apply(simp add: val_ord_def)
  1284 apply(rule conjI)
  1119 apply(rule conjI)
  1285 apply(simp add: val_ord_def)
  1120 apply(simp add: val_ord_def)
  1286 apply(auto simp add: pflat_len_simps pflat_len_Stars_simps2)[1]
  1121 apply(auto simp add: pflat_len_simps)[1]
  1287 apply(rule ballI)
  1122 apply(rule ballI)
  1288 apply(rule impI)
  1123 apply(rule impI)
  1289 apply(simp add: val_ord_def pflat_len_simps pflat_len_Stars_simps2 intlen_append)
  1124 apply(simp add: val_ord_def pflat_len_simps intlen_append)
  1290 apply(clarify)
  1125 apply(clarify)
  1291 apply(case_tac q)
  1126 apply(case_tac q)
  1292 apply(simp add: val_ord_def pflat_len_simps pflat_len_Stars_simps2 intlen_append)
  1127 apply(simp add: val_ord_def pflat_len_simps intlen_append)
  1293 apply(clarify)
  1128 apply(clarify)
  1294 apply(erule disjE)
  1129 apply(erule disjE)
  1295 prefer 2
  1130 prefer 2
  1296 apply(drule_tac x="Suc a # list" in bspec)
  1131 apply(drule_tac x="Suc a # list" in bspec)
  1297 apply(simp)
  1132 apply(simp)
  1298 apply(drule mp)
  1133 apply(drule mp)
  1299 apply(simp)
  1134 apply(simp)
  1300 apply(simp add: val_ord_def pflat_len_simps pflat_len_Stars_simps2 intlen_append)
  1135 apply(simp add: val_ord_def pflat_len_simps intlen_append)
  1301 apply(drule_tac x="Suc a # list" in bspec)
  1136 apply(drule_tac x="Suc a # list" in bspec)
  1302 apply(simp)
  1137 apply(simp)
  1303 apply(drule mp)
  1138 apply(drule mp)
  1304 apply(simp)
  1139 apply(simp)
  1305 apply(simp add: val_ord_def pflat_len_simps pflat_len_Stars_simps2 intlen_append)
  1140 apply(simp add: val_ord_def pflat_len_simps intlen_append)
  1306 done
  1141 done
  1307 
  1142 
  1308 
  1143 
  1309 lemma Posix_val_ord_reverse:
  1144 lemma Posix_val_ord_reverse:
  1310   assumes "s \<in> r \<rightarrow> v1" 
  1145   assumes "s \<in> r \<rightarrow> v1" 
  1311   shows "\<not>(\<exists>v2 \<in> CPT r s. v2 :\<sqsubset>val v1)"
  1146   shows "\<not>(\<exists>v2 \<in> CPT r s. v2 :\<sqsubset>val v1)"
  1312 using assms
  1147 using assms
  1313 by (metis Posix_val_ord_stronger less_irrefl val_ord_def 
  1148 by (metis Posix_val_ord_stronger less_irrefl val_ord_def 
  1314     val_ord_ex1_def val_ord_ex_def val_ord_ex_trans)
  1149     val_ord_ex1_def val_ord_ex_def val_ord_ex_trans)
  1315 
  1150 
  1316 thm Posix.intros(6)
       
  1317 
       
  1318 inductive Prop :: "rexp \<Rightarrow> val list \<Rightarrow> bool"
       
  1319 where
       
  1320   "Prop r []"
       
  1321 | "\<lbrakk>Prop r vs; 
       
  1322     \<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = concat (map flat vs) \<and> flat v @ s\<^sub>3 \<in> L r \<and> s\<^sub>4 \<in> L (STAR r))\<rbrakk> 
       
  1323    \<Longrightarrow> Prop r (v # vs)"
       
  1324 
  1151 
  1325 lemma STAR_val_ord_ex:
  1152 lemma STAR_val_ord_ex:
  1326   assumes "Stars (v # vs1) :\<sqsubset>val Stars (v # vs2)"
  1153   assumes "Stars (v # vs1) :\<sqsubset>val Stars (v # vs2)"
  1327   shows "Stars vs1 :\<sqsubset>val Stars vs2"
  1154   shows "Stars vs1 :\<sqsubset>val Stars vs2"
  1328 using assms
  1155 using assms
  1337 apply(simp)
  1164 apply(simp)
  1338 apply(case_tac a)
  1165 apply(case_tac a)
  1339 apply(clarify)
  1166 apply(clarify)
  1340 prefer 2
  1167 prefer 2
  1341 using STAR_val_ord val_ord_ex_def apply blast
  1168 using STAR_val_ord val_ord_ex_def apply blast
  1342 apply(auto simp add: pflat_len_Stars_simps2 val_ord_def pflat_len_def)[1]
  1169 apply(auto simp add: pflat_len_simps val_ord_def pflat_len_def)[1]
  1343 done
  1170 done
  1344 
  1171 
  1345 lemma STAR_val_ord_exI:
  1172 lemma STAR_val_ord_exI:
  1346   assumes "Stars vs1 :\<sqsubset>val Stars vs2" "flat (Stars vs1) = flat (Stars vs2)"
  1173   assumes "Stars vs1 :\<sqsubset>val Stars vs2" "flat (Stars vs1) = flat (Stars vs2)"
  1347   shows "Stars (vs @ vs1) :\<sqsubset>val Stars (vs @ vs2)"
  1174   shows "Stars (vs @ vs1) :\<sqsubset>val Stars (vs @ vs2)"
  1382 apply(erule STAR_val_ord_ex_append)
  1209 apply(erule STAR_val_ord_ex_append)
  1383 apply(rule STAR_val_ord_exI)
  1210 apply(rule STAR_val_ord_exI)
  1384 apply(auto)
  1211 apply(auto)
  1385 done
  1212 done
  1386 
  1213 
  1387 lemma Posix_STARI:
       
  1388   assumes "\<forall>v \<in> set vs. flat v \<noteq> [] \<and> (flat v) \<in> r \<rightarrow> v" "Prop r vs"
       
  1389   shows "flat (Stars vs) \<in> STAR r \<rightarrow> Stars vs"
       
  1390 using assms
       
  1391 apply(induct vs arbitrary: r)
       
  1392 apply(simp)
       
  1393 apply(rule Posix.intros)
       
  1394 apply(simp)
       
  1395 apply(rule Posix.intros)
       
  1396 apply(simp)
       
  1397 apply(auto)[1]
       
  1398 apply(erule Prop.cases)
       
  1399 apply(simp)
       
  1400 apply(simp)
       
  1401 apply(simp)
       
  1402 apply(erule Prop.cases)
       
  1403 apply(simp)
       
  1404 apply(auto)[1]
       
  1405 done
       
  1406 
  1214 
  1407 lemma CPrf_stars:
  1215 lemma CPrf_stars:
  1408   assumes "\<Turnstile> Stars vs : STAR r"
  1216   assumes "\<Turnstile> Stars vs : STAR r"
  1409   shows "\<forall>v \<in> set vs. flat v \<noteq> [] \<and> \<Turnstile> v : r"
  1217   shows "\<forall>v \<in> set vs. flat v \<noteq> [] \<and> \<Turnstile> v : r"
  1410 using assms
  1218 using assms
  1460 apply(simp)
  1268 apply(simp)
  1461 apply(drule mp)
  1269 apply(drule mp)
  1462 apply (meson CPrf_stars Prf.intros(7) Prf_CPrf list.set_intros(1))
  1270 apply (meson CPrf_stars Prf.intros(7) Prf_CPrf list.set_intros(1))
  1463 apply(subst (asm) (2) val_ord_ex_def)
  1271 apply(subst (asm) (2) val_ord_ex_def)
  1464 apply(simp)
  1272 apply(simp)
  1465 apply (metis flat.simps(7) flat_Stars intlen.cases not_less_iff_gr_or_eq pflat_len_simps(7) val_ord_STARI2 val_ord_def val_ord_ex_def)
  1273 apply (metis flat.simps(7) flat_Stars intlen.cases not_less_iff_gr_or_eq pflat_len_simps(9) val_ord_STARI2 val_ord_def val_ord_ex_def)
  1466 apply(auto simp add: CPT_def PT_def)[1]
  1274 apply(auto simp add: CPT_def PT_def)[1]
  1467 using CPrf_stars apply auto[1]
  1275 using CPrf_stars apply auto[1]
  1468 apply(auto)[1]
  1276 apply(auto)[1]
  1469 apply(auto simp add: CPT_def PT_def)[1]
  1277 apply(auto simp add: CPT_def PT_def)[1]
  1470 apply(subgoal_tac "\<exists>vA. flat vA = flat a @ s\<^sub>3 \<and> \<turnstile> vA : r")
  1278 apply(subgoal_tac "\<exists>vA. flat vA = flat a @ s\<^sub>3 \<and> \<turnstile> vA : r")
  1500 apply(drule mp)
  1308 apply(drule mp)
  1501 apply (simp add: Posix1a Prf.intros(7))
  1309 apply (simp add: Posix1a Prf.intros(7))
  1502 apply(simp)
  1310 apply(simp)
  1503 apply(subst (asm) (2) val_ord_ex_def)
  1311 apply(subst (asm) (2) val_ord_ex_def)
  1504 apply(simp)
  1312 apply(simp)
  1505 apply (metis flat.simps(7) flat_Stars intlen.cases not_less_iff_gr_or_eq pflat_len_simps(7) val_ord_STARI2 val_ord_def val_ord_ex_def)
  1313 apply (metis flat.simps(7) flat_Stars intlen.cases not_less_iff_gr_or_eq pflat_len_simps(9) val_ord_STARI2 val_ord_def val_ord_ex_def)
  1506 proof -
  1314 proof -
  1507   fix a :: val and vsa :: "val list" and s\<^sub>3 :: "char list" and vA :: val and vB :: "val list"
  1315   fix a :: val and vsa :: "val list" and s\<^sub>3 :: "char list" and vA :: val and vB :: "val list"
  1508   assume a1: "s\<^sub>3 \<noteq> []"
  1316   assume a1: "s\<^sub>3 \<noteq> []"
  1509   assume a2: "s\<^sub>3 @ concat (map flat vB) = concat (map flat vsa)"
  1317   assume a2: "s\<^sub>3 @ concat (map flat vB) = concat (map flat vsa)"
  1510   assume a3: "flat vA = flat a @ s\<^sub>3"
  1318   assume a3: "flat vA = flat a @ s\<^sub>3"
  1574 apply(drule_tac x="Left v2" in spec)
  1382 apply(drule_tac x="Left v2" in spec)
  1575 apply(simp)
  1383 apply(simp)
  1576 apply(drule mp)
  1384 apply(drule mp)
  1577 apply(rule Prf.intros)
  1385 apply(rule Prf.intros)
  1578 apply(simp)
  1386 apply(simp)
  1579 apply (meson val_ord_ALTI val_ord_ex_def)
  1387 apply (meson val_ord_LeftI)
  1580 apply(assumption)
  1388 apply(assumption)
  1581 (* ALT Right *)
  1389 (* ALT Right *)
  1582 apply(auto simp add: CPT_def)[1]
  1390 apply(auto simp add: CPT_def)[1]
  1583 apply(rule Posix.intros)
  1391 apply(rule Posix.intros)
  1584 apply(rotate_tac 1)
  1392 apply(rotate_tac 1)
  1591 apply(drule_tac x="Right v2a" in spec)
  1399 apply(drule_tac x="Right v2a" in spec)
  1592 apply(simp)
  1400 apply(simp)
  1593 apply(drule mp)
  1401 apply(drule mp)
  1594 apply(rule Prf.intros)
  1402 apply(rule Prf.intros)
  1595 apply(simp)
  1403 apply(simp)
  1596 apply(subst (asm) (2) val_ord_ex_def)
  1404 apply(drule val_ord_RightI)
  1597 apply(erule exE)
       
  1598 apply(drule val_ord_ALTI2)
       
  1599 apply(assumption)
  1405 apply(assumption)
  1600 apply(auto simp add: val_ord_ex_def)[1]
  1406 apply(auto simp add: val_ord_ex_def)[1]
  1601 apply(assumption)
  1407 apply(assumption)
  1602 apply(auto)[1]
  1408 apply(auto)[1]
  1603 apply(subgoal_tac "\<exists>v2'. flat v2' = flat v2 \<and> \<turnstile> v2' : r1a")
  1409 apply(subgoal_tac "\<exists>v2'. flat v2' = flat v2 \<and> \<turnstile> v2' : r1a")