diff -r 00c9a95d492e -r e2828c4a1e23 thys/Positions.thy --- a/thys/Positions.thy Tue Jul 04 18:09:29 2017 +0100 +++ b/thys/Positions.thy Thu Jul 06 16:05:33 2017 +0100 @@ -57,15 +57,12 @@ lemma intlen_length: shows "intlen xs < intlen ys \ length xs < length ys" apply(induct xs arbitrary: ys) -apply(auto) -apply(case_tac ys) -apply(simp_all) -apply (smt intlen_bigger) -apply (smt Suc_mono intlen.simps(2) length_Suc_conv less_antisym) +apply (auto simp add: intlen_bigger not_less) +apply (metis intlen.elims intlen_bigger le_imp_0_less) +apply (smt Suc_lessI intlen.simps(2) length_Suc_conv nat_neq_iff) by (smt Suc_lessE intlen.simps(2) length_Suc_conv) - definition pflat_len :: "val \ nat list => int" where "pflat_len v p \ (if p \ Pos v then intlen (flat (at v p)) else -1)" @@ -120,32 +117,23 @@ using assms by(induct rule: lex_list.induct)(auto) - lemma lex_simps [simp]: fixes xs ys :: "nat list" shows "[] \lex ys \ ys \ []" and "xs \lex [] \ False" and "(x # xs) \lex (y # ys) \ (x < y \ (\ y < x \ xs \lex ys))" -apply - -apply (metis lex_irrfl lex_list.intros(1) list.exhaust) -using lex_list.cases apply blast -using lex_list.cases lex_list.intros(2) lex_list.intros(3) not_less_iff_gr_or_eq by fastforce - +apply(auto elim: lex_list.cases intro: lex_list.intros) +apply(auto simp add: neq_Nil_conv not_less_iff_gr_or_eq intro: lex_list.intros) +done lemma lex_trans: fixes ps1 ps2 ps3 :: "nat list" assumes "ps1 \lex ps2" "ps2 \lex ps3" shows "ps1 \lex ps3" using assms -apply(induct arbitrary: ps3 rule: lex_list.induct) -apply(erule lex_list.cases) -apply(simp_all) -apply(rotate_tac 2) -apply(erule lex_list.cases) -apply(simp_all) -apply(erule lex_list.cases) -apply(simp_all) -done +by (induct arbitrary: ps3 rule: lex_list.induct) + (auto elim: lex_list.cases) + lemma lex_trichotomous: fixes p q :: "nat list" @@ -164,10 +152,24 @@ definition PosOrd:: "val \ nat list \ val \ bool" ("_ \val _ _" [60, 60, 59] 60) where - "v1 \val p v2 \ p \ Pos v1 \ + "v1 \val p v2 \ pflat_len v1 p > pflat_len v2 p \ + (\q \ Pos v1 \ Pos v2. q \lex p \ pflat_len v1 q = pflat_len v2 q)" + +definition PosOrd2:: "val \ nat list \ val \ bool" ("_ \val2 _ _" [60, 60, 59] 60) +where + "v1 \val2 p v2 \ p \ Pos v1 \ pflat_len v1 p > pflat_len v2 p \ (\q \ Pos v1 \ Pos v2. q \lex p \ pflat_len v1 q = pflat_len v2 q)" +lemma XXX: + "v1 \val p v2 \ v1 \val2 p v2" +apply(auto simp add: PosOrd_def PosOrd2_def) +apply(auto simp add: pflat_len_def split: if_splits) +by (smt intlen_bigger) + + +(* some tests *) + definition ValFlat_ord:: "val \ nat list \ val \ bool" ("_ \fval _ _") where "v1 \fval p v2 \ p \ Pos v1 \ @@ -197,7 +199,7 @@ using assms unfolding ValFlat_ord_def PosOrd_def apply(clarify) -done +oops definition PosOrd_ex:: "val \ val \ bool" ("_ :\val _" [60, 59] 60) @@ -228,7 +230,7 @@ shows "v :\val v'" using assms unfolding PosOrd_ex_def -by (metis Pos_empty intlen_length lex_simps(2) pflat_len_simps(9) PosOrd_def) +by (metis intlen_length lex_simps(2) pflat_len_simps(9) PosOrd_def) lemma PosOrd_spreI: assumes "(flat v') \spre (flat v)" @@ -243,7 +245,7 @@ unfolding PosOrd_ex_def apply(rule_tac x="[0]" in exI) using assms -apply(auto simp add: PosOrd_def pflat_len_simps Pos_empty) +apply(auto simp add: PosOrd_def pflat_len_simps) apply(smt intlen_bigger) done @@ -275,13 +277,15 @@ using assms apply(simp add: PosOrd_ex_def) apply(erule exE) -apply(case_tac "p = []") +apply(case_tac p) apply(simp add: PosOrd_def) apply(auto simp add: pflat_len_simps) apply(rule_tac x="[]" in exI) apply(simp add: Pos_empty pflat_len_simps) apply(auto simp add: pflat_len_simps PosOrd_def) -apply(rule_tac x="ps" in exI) +apply(case_tac a) +apply(auto simp add: pflat_len_simps)[1] +apply(rule_tac x="list" in exI) apply(auto) apply(drule_tac x="0#q" in bspec) apply(simp) @@ -289,6 +293,7 @@ apply(drule_tac x="0#q" in bspec) apply(simp) apply(simp add: pflat_len_simps) +apply(simp add: pflat_len_def) done lemma PosOrd_RightE: @@ -297,13 +302,18 @@ using assms apply(simp add: PosOrd_ex_def) apply(erule exE) -apply(case_tac "p = []") +apply(case_tac p) apply(simp add: PosOrd_def) apply(auto simp add: pflat_len_simps) apply(rule_tac x="[]" in exI) apply(simp add: Pos_empty pflat_len_simps) +apply(case_tac a) +apply(simp add: pflat_len_def PosOrd_def) +apply(case_tac nat) +prefer 2 +apply(simp add: pflat_len_def PosOrd_def) apply(auto simp add: pflat_len_simps PosOrd_def) -apply(rule_tac x="ps" in exI) +apply(rule_tac x="list" in exI) apply(auto) apply(drule_tac x="Suc 0#q" in bspec) apply(simp) @@ -325,8 +335,6 @@ apply(rule_tac x="0#p" in exI) apply(subst PosOrd_def) apply(rule conjI) -apply(simp) -apply(rule conjI) apply(simp add: pflat_len_simps) apply(rule ballI) apply(rule impI) @@ -349,8 +357,6 @@ apply(rule_tac x="Suc 0#p" in exI) apply(subst PosOrd_def) apply(rule conjI) -apply(simp) -apply(rule conjI) apply(simp add: pflat_len_simps) apply(rule ballI) apply(rule impI) @@ -393,10 +399,14 @@ apply(simp add: Pos_empty) apply(rule ballI) apply(rule impI) +apply(auto)[1] apply(drule_tac x="Suc 0#q" in bspec) apply(simp) apply(simp add: pflat_len_simps) -apply(simp add: PosOrd_def) +apply(drule_tac x="Suc 0#q" in bspec) +apply(simp) +apply(simp add: pflat_len_simps) +apply(simp add: PosOrd_def pflat_len_def) done lemma PosOrd_StarsI: @@ -459,7 +469,7 @@ apply(simp) apply(case_tac a) apply(clarify) -apply(auto simp add: pflat_len_simps PosOrd_def pflat_len_def)[1] +apply(auto simp add: pflat_len_simps PosOrd_def pflat_len_def split: if_splits)[1] apply(clarify) apply(simp add: PosOrd_ex_def) apply(rule_tac x="nat#list" in exI) @@ -497,43 +507,41 @@ apply(auto) done - lemma PosOrd_trans: assumes "v1 :\val v2" "v2 :\val v3" shows "v1 :\val v3" -using assms -unfolding PosOrd_ex_def -apply(clarify) -apply(subgoal_tac "p = pa \ p \lex pa \ pa \lex p") -prefer 2 -apply(rule lex_trichotomous) -apply(erule disjE) -apply(simp) -apply(rule_tac x="pa" in exI) -apply(subst PosOrd_def) -apply(rule conjI) -apply(simp add: PosOrd_def) -apply(auto)[1] -apply(simp add: PosOrd_def) -apply(simp add: PosOrd_def) -apply(auto)[1] -using outside_lemma apply blast -apply(simp add: PosOrd_def) -apply(auto)[1] -using outside_lemma apply force -apply auto[1] -apply(simp add: PosOrd_def) -apply(auto)[1] -apply (metis (no_types, hide_lams) lex_trans outside_lemma) -apply(simp add: PosOrd_def) -apply(auto)[1] -by (smt intlen_bigger lex_trans outside_lemma pflat_len_def) +proof - + from assms obtain p p' + where as: "v1 \val p v2" "v2 \val p' v3" unfolding PosOrd_ex_def by blast + have "p = p' \ p \lex p' \ p' \lex p" + by (rule lex_trichotomous) + moreover + { assume "p = p'" + with as have "v1 \val p v3" unfolding PosOrd_def + by (smt outside_lemma) + then have " v1 :\val v3" unfolding PosOrd_ex_def by blast + } + moreover + { assume "p \lex p'" + with as have "v1 \val p v3" unfolding PosOrd_def + by (metis lex_trans outside_lemma) + then have " v1 :\val v3" unfolding PosOrd_ex_def by blast + } + moreover + { assume "p' \lex p" + with as have "v1 \val p' v3" unfolding PosOrd_def + by (smt Un_iff intlen_bigger lex_trans pflat_len_def) + then have "v1 :\val v3" unfolding PosOrd_ex_def by blast + } + ultimately show "v1 :\val v3" by blast +qed + lemma PosOrd_irrefl: assumes "v :\val v" shows "False" -using assms -by(auto simp add: PosOrd_ex_def PosOrd_def) +using assms unfolding PosOrd_ex_def PosOrd_def +by auto lemma PosOrd_almost_trichotomous: shows "v1 :\val v2 \ v2 :\val v1 \ (intlen (flat v1) = intlen (flat v2))" @@ -550,7 +558,7 @@ shows "False" using assms apply(auto simp add: PosOrd_ex_def PosOrd_def) -using assms(1) assms(2) PosOrd_irrefl PosOrd_trans by blast +using assms PosOrd_irrefl PosOrd_trans by blast lemma WW2: assumes "\(v1 :\val v2)" @@ -842,29 +850,8 @@ assumes "s \ r \ v" shows "v \ CPT r s" using assms -apply(induct rule: Posix.induct) -apply(simp add: CPT_def) -apply(rule CPrf.intros) -apply(simp add: CPT_def) -apply(rule CPrf.intros) -apply(simp add: CPT_def) -apply(rule CPrf.intros) -apply(simp) -apply(simp add: CPT_def) -apply(rule CPrf.intros) -apply(simp) -apply(simp add: CPT_def) -apply(rule CPrf.intros) -apply(simp) -apply(simp) -apply(simp add: CPT_def) -apply(rule CPrf.intros) -apply(simp) -apply(simp) -apply(simp) -apply(simp add: CPT_def) -apply(rule CPrf.intros) -done +by (induct rule: Posix.induct) + (auto simp add: CPT_def intro: CPrf.intros) section {* The Posix Value is smaller than any other Value *} @@ -954,7 +941,8 @@ qed next case (Posix_SEQ s1 r1 v1 s2 r2 v2 v3) - have as1: "s1 \ r1 \ v1" "s2 \ r2 \ v2" by fact+ + have "s1 \ r1 \ v1" "s2 \ r2 \ v2" by fact+ + then have as1: "s1 = flat v1" "s2 = flat v2" by (simp_all add: Posix1(2)) have IH1: "\v3. v3 \ CPT r1 s1 \ v1 :\val v3" by fact have IH2: "\v3. v3 \ CPT r2 s2 \ v2 :\val v3" by fact have cond: "\ (\s\<^sub>3 s\<^sub>4. s\<^sub>3 \ [] \ s\<^sub>3 @ s\<^sub>4 = s2 \ s1 @ s\<^sub>3 \ L r1 \ s\<^sub>4 \ L r2)" by fact @@ -968,17 +956,17 @@ then have "flat v3a \spre s1 \ (flat v3a = s1 \ flat v3b = s2)" using eqs by (simp add: sprefix_list_def append_eq_conv_conj) then have q2: "v1 :\val v3a \ (flat v3a = s1 \ flat v3b = s2)" - using PosOrd_spreI Posix1(2) as1(1) eqs by blast + using PosOrd_spreI as1(1) eqs by blast then have "v1 :\val v3a \ (v3a \ CPT r1 s1 \ v3b \ CPT r2 s2)" using eqs(2,3) by (auto simp add: CPT_def) then have "v1 :\val v3a \ (v1 :\val v3a \ v2 :\val v3b)" using IH1 IH2 by blast then have "Seq v1 v2 :\val Seq v3a v3b" using eqs q2 as1 - unfolding PosOrd_ex1_def - by (metis PosOrd_SeqI1 PosOrd_SeqI2 Posix1(2) flat.simps(5)) + unfolding PosOrd_ex1_def by (auto simp add: PosOrd_SeqI1 PosOrd_SeqI2) then show "Seq v1 v2 :\val v3" unfolding eqs by blast next case (Posix_STAR1 s1 r v s2 vs v3) - have as1: "s1 \ r \ v" "s2 \ STAR r \ Stars vs" by fact+ + have "s1 \ r \ v" "s2 \ STAR r \ Stars vs" by fact+ + then have as1: "s1 = flat v" "s2 = flat (Stars vs)" by (auto dest: Posix1(2)) have IH1: "\v3. v3 \ CPT r s1 \ v :\val v3" by fact have IH2: "\v3. v3 \ CPT (STAR r) s2 \ Stars vs :\val v3" by fact have cond: "\ (\s\<^sub>3 s\<^sub>4. s\<^sub>3 \ [] \ s\<^sub>3 @ s\<^sub>4 = s2 \ s1 @ s\<^sub>3 \ L r \ s\<^sub>4 \ L (STAR r))" by fact @@ -1000,13 +988,15 @@ then have "flat v3a \spre s1 \ (flat v3a = s1 \ flat (Stars vs3) = s2)" using NonEmpty(4) by (simp add: sprefix_list_def append_eq_conv_conj) then have q2: "v :\val v3a \ (flat v3a = s1 \ flat (Stars vs3) = s2)" - using PosOrd_spreI Posix1(2) as1(1) NonEmpty(4) by blast + using PosOrd_spreI as1(1) NonEmpty(4) by blast then have "v :\val v3a \ (v3a \ CPT r s1 \ Stars vs3 \ CPT (STAR r) s2)" using NonEmpty(2,3) by (auto simp add: CPT_def) - then have "v :\val v3a \ (v :\val v3a \ Stars vs :\val Stars vs3)" using IH1 IH2 by blast + then have "v :\val v3a \ (v :\val v3a \ Stars vs :\val Stars vs3)" using IH1 IH2 by blast + then have "v :\val v3a \ (v = v3a \ Stars vs :\val Stars vs3)" + unfolding PosOrd_ex1_def by auto then have "Stars (v # vs) :\val Stars (v3a # vs3)" using NonEmpty(4) q2 as1 unfolding PosOrd_ex1_def - by (metis PosOrd_StarsI PosOrd_StarsI2 Posix1(2) flat.simps(7) val.inject(5)) + by (metis PosOrd_StarsI PosOrd_StarsI2 flat.simps(7) val.inject(5)) then show "Stars (v # vs) :\val v3" unfolding NonEmpty by blast next case Empty @@ -1032,7 +1022,8 @@ unfolding CPTpre_def CPT_def sprefix_list_def prefix_list_def by auto moreover { assume "v2 \ CPT r s" - with assms(1) have "v1 :\val v2" by (rule Posix_PosOrd) + with assms(1) + have "v1 :\val v2" by (rule Posix_PosOrd) } moreover { assume "flat v2 \spre s" @@ -1074,7 +1065,7 @@ apply(auto simp add: CPT_def PT_def)[1] apply(erule Prf.cases) apply(simp_all) -apply (metis CPrf_stars Cons_eq_map_conv Posix_CPT Posix_STAR2 Posix_PosOrd_reverse list.exhaust list.set_intros(2) map_idI val.distinct(25)) +using CPrf_stars PosOrd_irrefl apply fastforce apply(clarify) apply(drule_tac x="Stars (a#v#vsa)" in spec) apply(simp) @@ -1123,23 +1114,7 @@ apply(subst (asm) (2) PosOrd_ex_def) apply(simp) apply (metis flat.simps(7) flat_Stars PosOrd_StarsI2 PosOrd_ex_def) -proof - - fix a :: val and vsa :: "val list" and s\<^sub>3 :: "char list" and vA :: val and vB :: "val list" - assume a1: "s\<^sub>3 \ []" - assume a2: "s\<^sub>3 @ concat (map flat vB) = concat (map flat vsa)" - assume a3: "flat vA = flat a @ s\<^sub>3" - assume a4: "\p. \ (Stars (vA # vB) \val p (Stars (a # vsa)))" - have f5: "\n cs. drop n (cs::char list) = [] \ n < length cs" - by (meson drop_eq_Nil not_less) - have f6: "\ length (flat vA) \ length (flat a)" - using a3 a1 by simp - have "flat (Stars (a # vsa)) = flat (Stars (vA # vB))" - using a3 a2 by simp - then show False - using f6 f5 a4 by (metis (full_types) drop_eq_Nil PosOrd_StarsI PosOrd_ex_def PosOrd_shorterI) -qed - - +by (metis PosOrd_StarsI PosOrd_ex_def PosOrd_spreI append_assoc append_self_conv flat.simps(7) flat_Stars prefix_list_def sprefix_list_def) section {* The Smallest Value is indeed the Posix Value *}