| author | wenzelm | 
| Wed, 11 Jan 2012 21:04:22 +0100 | |
| changeset 46190 | a42c5f23109f | 
| parent 45236 | ac4a2a66707d | 
| permissions | -rw-r--r-- | 
| 10330 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 1 | (* Title: HOL/Library/List_Prefix.thy | 
| 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 2 | Author: Tobias Nipkow and Markus Wenzel, TU Muenchen | 
| 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 3 | *) | 
| 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 4 | |
| 14706 | 5 | header {* List prefixes and postfixes *}
 | 
| 10330 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 6 | |
| 15131 | 7 | theory List_Prefix | 
| 30663 
0b6aff7451b2
Main is (Complex_Main) base entry point in library theories
 haftmann parents: 
28562diff
changeset | 8 | imports List Main | 
| 15131 | 9 | begin | 
| 10330 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 10 | |
| 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 11 | subsection {* Prefix order on lists *}
 | 
| 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 12 | |
| 37474 | 13 | instantiation list :: (type) "{order, bot}"
 | 
| 25764 | 14 | begin | 
| 15 | ||
| 16 | definition | |
| 37474 | 17 | prefix_def: "xs \<le> ys \<longleftrightarrow> (\<exists>zs. ys = xs @ zs)" | 
| 10330 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 18 | |
| 25764 | 19 | definition | 
| 37474 | 20 | strict_prefix_def: "xs < ys \<longleftrightarrow> xs \<le> ys \<and> xs \<noteq> (ys::'a list)" | 
| 10330 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 21 | |
| 37474 | 22 | definition | 
| 23 | "bot = []" | |
| 24 | ||
| 25 | instance proof | |
| 26 | qed (auto simp add: prefix_def strict_prefix_def bot_list_def) | |
| 10330 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 27 | |
| 25764 | 28 | end | 
| 29 | ||
| 10389 | 30 | lemma prefixI [intro?]: "ys = xs @ zs ==> xs \<le> ys" | 
| 18730 | 31 | unfolding prefix_def by blast | 
| 10330 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 32 | |
| 21305 | 33 | lemma prefixE [elim?]: | 
| 34 | assumes "xs \<le> ys" | |
| 35 | obtains zs where "ys = xs @ zs" | |
| 23394 | 36 | using assms unfolding prefix_def by blast | 
| 10330 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 37 | |
| 10870 | 38 | lemma strict_prefixI' [intro?]: "ys = xs @ z # zs ==> xs < ys" | 
| 18730 | 39 | unfolding strict_prefix_def prefix_def by blast | 
| 10870 | 40 | |
| 41 | lemma strict_prefixE' [elim?]: | |
| 21305 | 42 | assumes "xs < ys" | 
| 43 | obtains z zs where "ys = xs @ z # zs" | |
| 10870 | 44 | proof - | 
| 21305 | 45 | from `xs < ys` obtain us where "ys = xs @ us" and "xs \<noteq> ys" | 
| 18730 | 46 | unfolding strict_prefix_def prefix_def by blast | 
| 21305 | 47 | with that show ?thesis by (auto simp add: neq_Nil_conv) | 
| 10870 | 48 | qed | 
| 49 | ||
| 10389 | 50 | lemma strict_prefixI [intro?]: "xs \<le> ys ==> xs \<noteq> ys ==> xs < (ys::'a list)" | 
| 18730 | 51 | unfolding strict_prefix_def by blast | 
| 10330 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 52 | |
| 10389 | 53 | lemma strict_prefixE [elim?]: | 
| 21305 | 54 | fixes xs ys :: "'a list" | 
| 55 | assumes "xs < ys" | |
| 56 | obtains "xs \<le> ys" and "xs \<noteq> ys" | |
| 23394 | 57 | using assms unfolding strict_prefix_def by blast | 
| 10330 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 58 | |
| 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 59 | |
| 10389 | 60 | subsection {* Basic properties of prefixes *}
 | 
| 10330 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 61 | |
| 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 62 | theorem Nil_prefix [iff]: "[] \<le> xs" | 
| 10389 | 63 | by (simp add: prefix_def) | 
| 10330 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 64 | |
| 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 65 | theorem prefix_Nil [simp]: "(xs \<le> []) = (xs = [])" | 
| 10389 | 66 | by (induct xs) (simp_all add: prefix_def) | 
| 10330 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 67 | |
| 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 68 | lemma prefix_snoc [simp]: "(xs \<le> ys @ [y]) = (xs = ys @ [y] \<or> xs \<le> ys)" | 
| 10389 | 69 | proof | 
| 70 | assume "xs \<le> ys @ [y]" | |
| 71 | then obtain zs where zs: "ys @ [y] = xs @ zs" .. | |
| 72 | show "xs = ys @ [y] \<or> xs \<le> ys" | |
| 25564 | 73 | by (metis append_Nil2 butlast_append butlast_snoc prefixI zs) | 
| 10389 | 74 | next | 
| 75 | assume "xs = ys @ [y] \<or> xs \<le> ys" | |
| 23254 | 76 | then show "xs \<le> ys @ [y]" | 
| 45236 
ac4a2a66707d
replacing metis proofs with facts xt1 by new proof with more readable names
 bulwahn parents: 
38857diff
changeset | 77 | by (metis order_eq_iff order_trans prefixI) | 
| 10389 | 78 | qed | 
| 10330 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 79 | |
| 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 80 | lemma Cons_prefix_Cons [simp]: "(x # xs \<le> y # ys) = (x = y \<and> xs \<le> ys)" | 
| 10389 | 81 | by (auto simp add: prefix_def) | 
| 10330 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 82 | |
| 37474 | 83 | lemma less_eq_list_code [code]: | 
| 38857 
97775f3e8722
renamed class/constant eq to equal; tuned some instantiations
 haftmann parents: 
37474diff
changeset | 84 |   "([]\<Colon>'a\<Colon>{equal, ord} list) \<le> xs \<longleftrightarrow> True"
 | 
| 
97775f3e8722
renamed class/constant eq to equal; tuned some instantiations
 haftmann parents: 
37474diff
changeset | 85 |   "(x\<Colon>'a\<Colon>{equal, ord}) # xs \<le> [] \<longleftrightarrow> False"
 | 
| 
97775f3e8722
renamed class/constant eq to equal; tuned some instantiations
 haftmann parents: 
37474diff
changeset | 86 |   "(x\<Colon>'a\<Colon>{equal, ord}) # xs \<le> y # ys \<longleftrightarrow> x = y \<and> xs \<le> ys"
 | 
| 37474 | 87 | by simp_all | 
| 88 | ||
| 10330 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 89 | lemma same_prefix_prefix [simp]: "(xs @ ys \<le> xs @ zs) = (ys \<le> zs)" | 
| 10389 | 90 | by (induct xs) simp_all | 
| 10330 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 91 | |
| 10389 | 92 | lemma same_prefix_nil [iff]: "(xs @ ys \<le> xs) = (ys = [])" | 
| 25692 | 93 | by (metis append_Nil2 append_self_conv order_eq_iff prefixI) | 
| 25665 | 94 | |
| 10330 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 95 | lemma prefix_prefix [simp]: "xs \<le> ys ==> xs \<le> ys @ zs" | 
| 25692 | 96 | by (metis order_le_less_trans prefixI strict_prefixE strict_prefixI) | 
| 25665 | 97 | |
| 14300 | 98 | lemma append_prefixD: "xs @ ys \<le> zs \<Longrightarrow> xs \<le> zs" | 
| 17201 | 99 | by (auto simp add: prefix_def) | 
| 14300 | 100 | |
| 10330 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 101 | theorem prefix_Cons: "(xs \<le> y # ys) = (xs = [] \<or> (\<exists>zs. xs = y # zs \<and> zs \<le> ys))" | 
| 10389 | 102 | by (cases xs) (auto simp add: prefix_def) | 
| 10330 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 103 | |
| 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 104 | theorem prefix_append: | 
| 25564 | 105 | "(xs \<le> ys @ zs) = (xs \<le> ys \<or> (\<exists>us. xs = ys @ us \<and> us \<le> zs))" | 
| 10330 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 106 | apply (induct zs rule: rev_induct) | 
| 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 107 | apply force | 
| 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 108 | apply (simp del: append_assoc add: append_assoc [symmetric]) | 
| 25564 | 109 | apply (metis append_eq_appendI) | 
| 10330 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 110 | done | 
| 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 111 | |
| 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 112 | lemma append_one_prefix: | 
| 25564 | 113 | "xs \<le> ys ==> length xs < length ys ==> xs @ [ys ! length xs] \<le> ys" | 
| 25692 | 114 | unfolding prefix_def | 
| 115 | by (metis Cons_eq_appendI append_eq_appendI append_eq_conv_conj | |
| 116 | eq_Nil_appendI nth_drop') | |
| 25665 | 117 | |
| 10330 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 118 | theorem prefix_length_le: "xs \<le> ys ==> length xs \<le> length ys" | 
| 10389 | 119 | by (auto simp add: prefix_def) | 
| 10330 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 120 | |
| 14300 | 121 | lemma prefix_same_cases: | 
| 25564 | 122 | "(xs\<^isub>1::'a list) \<le> ys \<Longrightarrow> xs\<^isub>2 \<le> ys \<Longrightarrow> xs\<^isub>1 \<le> xs\<^isub>2 \<or> xs\<^isub>2 \<le> xs\<^isub>1" | 
| 25692 | 123 | unfolding prefix_def by (metis append_eq_append_conv2) | 
| 25665 | 124 | |
| 25564 | 125 | lemma set_mono_prefix: "xs \<le> ys \<Longrightarrow> set xs \<subseteq> set ys" | 
| 25692 | 126 | by (auto simp add: prefix_def) | 
| 14300 | 127 | |
| 25564 | 128 | lemma take_is_prefix: "take n xs \<le> xs" | 
| 25692 | 129 | unfolding prefix_def by (metis append_take_drop_id) | 
| 25665 | 130 | |
| 25692 | 131 | lemma map_prefixI: "xs \<le> ys \<Longrightarrow> map f xs \<le> map f ys" | 
| 132 | by (auto simp: prefix_def) | |
| 25322 | 133 | |
| 25692 | 134 | lemma prefix_length_less: "xs < ys \<Longrightarrow> length xs < length ys" | 
| 135 | by (auto simp: strict_prefix_def prefix_def) | |
| 25665 | 136 | |
| 37474 | 137 | lemma strict_prefix_simps [simp, code]: | 
| 138 | "xs < [] \<longleftrightarrow> False" | |
| 139 | "[] < x # xs \<longleftrightarrow> True" | |
| 140 | "x # xs < y # ys \<longleftrightarrow> x = y \<and> xs < ys" | |
| 25692 | 141 | by (simp_all add: strict_prefix_def cong: conj_cong) | 
| 25299 | 142 | |
| 25564 | 143 | lemma take_strict_prefix: "xs < ys \<Longrightarrow> take n xs < ys" | 
| 25692 | 144 | apply (induct n arbitrary: xs ys) | 
| 145 | apply (case_tac ys, simp_all)[1] | |
| 146 | apply (metis order_less_trans strict_prefixI take_is_prefix) | |
| 147 | done | |
| 25299 | 148 | |
| 25355 | 149 | lemma not_prefix_cases: | 
| 25299 | 150 | assumes pfx: "\<not> ps \<le> ls" | 
| 25356 | 151 | obtains | 
| 152 | (c1) "ps \<noteq> []" and "ls = []" | |
| 153 | | (c2) a as x xs where "ps = a#as" and "ls = x#xs" and "x = a" and "\<not> as \<le> xs" | |
| 154 | | (c3) a as x xs where "ps = a#as" and "ls = x#xs" and "x \<noteq> a" | |
| 25299 | 155 | proof (cases ps) | 
| 25692 | 156 | case Nil then show ?thesis using pfx by simp | 
| 25299 | 157 | next | 
| 158 | case (Cons a as) | |
| 25692 | 159 | note c = `ps = a#as` | 
| 25299 | 160 | show ?thesis | 
| 161 | proof (cases ls) | |
| 25692 | 162 | case Nil then show ?thesis by (metis append_Nil2 pfx c1 same_prefix_nil) | 
| 25299 | 163 | next | 
| 164 | case (Cons x xs) | |
| 165 | show ?thesis | |
| 166 | proof (cases "x = a") | |
| 25355 | 167 | case True | 
| 168 | have "\<not> as \<le> xs" using pfx c Cons True by simp | |
| 169 | with c Cons True show ?thesis by (rule c2) | |
| 170 | next | |
| 171 | case False | |
| 172 | with c Cons show ?thesis by (rule c3) | |
| 25299 | 173 | qed | 
| 174 | qed | |
| 175 | qed | |
| 176 | ||
| 177 | lemma not_prefix_induct [consumes 1, case_names Nil Neq Eq]: | |
| 178 | assumes np: "\<not> ps \<le> ls" | |
| 25356 | 179 | and base: "\<And>x xs. P (x#xs) []" | 
| 180 | and r1: "\<And>x xs y ys. x \<noteq> y \<Longrightarrow> P (x#xs) (y#ys)" | |
| 181 | and r2: "\<And>x xs y ys. \<lbrakk> x = y; \<not> xs \<le> ys; P xs ys \<rbrakk> \<Longrightarrow> P (x#xs) (y#ys)" | |
| 182 | shows "P ps ls" using np | |
| 25299 | 183 | proof (induct ls arbitrary: ps) | 
| 25355 | 184 | case Nil then show ?case | 
| 25299 | 185 | by (auto simp: neq_Nil_conv elim!: not_prefix_cases intro!: base) | 
| 186 | next | |
| 25355 | 187 | case (Cons y ys) | 
| 188 | then have npfx: "\<not> ps \<le> (y # ys)" by simp | |
| 189 | then obtain x xs where pv: "ps = x # xs" | |
| 25299 | 190 | by (rule not_prefix_cases) auto | 
| 25564 | 191 | show ?case by (metis Cons.hyps Cons_prefix_Cons npfx pv r1 r2) | 
| 25299 | 192 | qed | 
| 14300 | 193 | |
| 25356 | 194 | |
| 10389 | 195 | subsection {* Parallel lists *}
 | 
| 196 | ||
| 19086 | 197 | definition | 
| 21404 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 wenzelm parents: 
21305diff
changeset | 198 | parallel :: "'a list => 'a list => bool" (infixl "\<parallel>" 50) where | 
| 19086 | 199 | "(xs \<parallel> ys) = (\<not> xs \<le> ys \<and> \<not> ys \<le> xs)" | 
| 10389 | 200 | |
| 201 | lemma parallelI [intro]: "\<not> xs \<le> ys ==> \<not> ys \<le> xs ==> xs \<parallel> ys" | |
| 25692 | 202 | unfolding parallel_def by blast | 
| 10330 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 203 | |
| 10389 | 204 | lemma parallelE [elim]: | 
| 25692 | 205 | assumes "xs \<parallel> ys" | 
| 206 | obtains "\<not> xs \<le> ys \<and> \<not> ys \<le> xs" | |
| 207 | using assms unfolding parallel_def by blast | |
| 10330 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 208 | |
| 10389 | 209 | theorem prefix_cases: | 
| 25692 | 210 | obtains "xs \<le> ys" | "ys < xs" | "xs \<parallel> ys" | 
| 211 | unfolding parallel_def strict_prefix_def by blast | |
| 10330 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 212 | |
| 10389 | 213 | theorem parallel_decomp: | 
| 214 | "xs \<parallel> ys ==> \<exists>as b bs c cs. b \<noteq> c \<and> xs = as @ b # bs \<and> ys = as @ c # cs" | |
| 10408 | 215 | proof (induct xs rule: rev_induct) | 
| 11987 | 216 | case Nil | 
| 23254 | 217 | then have False by auto | 
| 218 | then show ?case .. | |
| 10408 | 219 | next | 
| 11987 | 220 | case (snoc x xs) | 
| 221 | show ?case | |
| 10408 | 222 | proof (rule prefix_cases) | 
| 223 | assume le: "xs \<le> ys" | |
| 224 | then obtain ys' where ys: "ys = xs @ ys'" .. | |
| 225 | show ?thesis | |
| 226 | proof (cases ys') | |
| 25564 | 227 | assume "ys' = []" | 
| 25692 | 228 | then show ?thesis by (metis append_Nil2 parallelE prefixI snoc.prems ys) | 
| 10389 | 229 | next | 
| 10408 | 230 | fix c cs assume ys': "ys' = c # cs" | 
| 25692 | 231 | then show ?thesis | 
| 232 | by (metis Cons_eq_appendI eq_Nil_appendI parallelE prefixI | |
| 233 | same_prefix_prefix snoc.prems ys) | |
| 10389 | 234 | qed | 
| 10408 | 235 | next | 
| 23254 | 236 | assume "ys < xs" then have "ys \<le> xs @ [x]" by (simp add: strict_prefix_def) | 
| 11987 | 237 | with snoc have False by blast | 
| 23254 | 238 | then show ?thesis .. | 
| 10408 | 239 | next | 
| 240 | assume "xs \<parallel> ys" | |
| 11987 | 241 | with snoc obtain as b bs c cs where neq: "(b::'a) \<noteq> c" | 
| 10408 | 242 | and xs: "xs = as @ b # bs" and ys: "ys = as @ c # cs" | 
| 243 | by blast | |
| 244 | from xs have "xs @ [x] = as @ b # (bs @ [x])" by simp | |
| 245 | with neq ys show ?thesis by blast | |
| 10389 | 246 | qed | 
| 247 | qed | |
| 10330 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 248 | |
| 25564 | 249 | lemma parallel_append: "a \<parallel> b \<Longrightarrow> a @ c \<parallel> b @ d" | 
| 25692 | 250 | apply (rule parallelI) | 
| 251 | apply (erule parallelE, erule conjE, | |
| 252 | induct rule: not_prefix_induct, simp+)+ | |
| 253 | done | |
| 25299 | 254 | |
| 25692 | 255 | lemma parallel_appendI: "xs \<parallel> ys \<Longrightarrow> x = xs @ xs' \<Longrightarrow> y = ys @ ys' \<Longrightarrow> x \<parallel> y" | 
| 256 | by (simp add: parallel_append) | |
| 25299 | 257 | |
| 25692 | 258 | lemma parallel_commute: "a \<parallel> b \<longleftrightarrow> b \<parallel> a" | 
| 259 | unfolding parallel_def by auto | |
| 14538 
1d9d75a8efae
removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
 oheimb parents: 
14300diff
changeset | 260 | |
| 25356 | 261 | |
| 14538 
1d9d75a8efae
removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
 oheimb parents: 
14300diff
changeset | 262 | subsection {* Postfix order on lists *}
 | 
| 17201 | 263 | |
| 19086 | 264 | definition | 
| 21404 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 wenzelm parents: 
21305diff
changeset | 265 |   postfix :: "'a list => 'a list => bool"  ("(_/ >>= _)" [51, 50] 50) where
 | 
| 19086 | 266 | "(xs >>= ys) = (\<exists>zs. xs = zs @ ys)" | 
| 14538 
1d9d75a8efae
removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
 oheimb parents: 
14300diff
changeset | 267 | |
| 21305 | 268 | lemma postfixI [intro?]: "xs = zs @ ys ==> xs >>= ys" | 
| 25692 | 269 | unfolding postfix_def by blast | 
| 21305 | 270 | |
| 271 | lemma postfixE [elim?]: | |
| 25692 | 272 | assumes "xs >>= ys" | 
| 273 | obtains zs where "xs = zs @ ys" | |
| 274 | using assms unfolding postfix_def by blast | |
| 21305 | 275 | |
| 276 | lemma postfix_refl [iff]: "xs >>= xs" | |
| 14706 | 277 | by (auto simp add: postfix_def) | 
| 17201 | 278 | lemma postfix_trans: "\<lbrakk>xs >>= ys; ys >>= zs\<rbrakk> \<Longrightarrow> xs >>= zs" | 
| 14706 | 279 | by (auto simp add: postfix_def) | 
| 17201 | 280 | lemma postfix_antisym: "\<lbrakk>xs >>= ys; ys >>= xs\<rbrakk> \<Longrightarrow> xs = ys" | 
| 14706 | 281 | by (auto simp add: postfix_def) | 
| 14538 
1d9d75a8efae
removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
 oheimb parents: 
14300diff
changeset | 282 | |
| 17201 | 283 | lemma Nil_postfix [iff]: "xs >>= []" | 
| 14706 | 284 | by (simp add: postfix_def) | 
| 17201 | 285 | lemma postfix_Nil [simp]: "([] >>= xs) = (xs = [])" | 
| 21305 | 286 | by (auto simp add: postfix_def) | 
| 14538 
1d9d75a8efae
removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
 oheimb parents: 
14300diff
changeset | 287 | |
| 17201 | 288 | lemma postfix_ConsI: "xs >>= ys \<Longrightarrow> x#xs >>= ys" | 
| 14706 | 289 | by (auto simp add: postfix_def) | 
| 17201 | 290 | lemma postfix_ConsD: "xs >>= y#ys \<Longrightarrow> xs >>= ys" | 
| 14706 | 291 | by (auto simp add: postfix_def) | 
| 14538 
1d9d75a8efae
removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
 oheimb parents: 
14300diff
changeset | 292 | |
| 17201 | 293 | lemma postfix_appendI: "xs >>= ys \<Longrightarrow> zs @ xs >>= ys" | 
| 14706 | 294 | by (auto simp add: postfix_def) | 
| 17201 | 295 | lemma postfix_appendD: "xs >>= zs @ ys \<Longrightarrow> xs >>= ys" | 
| 21305 | 296 | by (auto simp add: postfix_def) | 
| 14538 
1d9d75a8efae
removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
 oheimb parents: 
14300diff
changeset | 297 | |
| 21305 | 298 | lemma postfix_is_subset: "xs >>= ys ==> set ys \<subseteq> set xs" | 
| 299 | proof - | |
| 300 | assume "xs >>= ys" | |
| 301 | then obtain zs where "xs = zs @ ys" .. | |
| 302 | then show ?thesis by (induct zs) auto | |
| 303 | qed | |
| 14538 
1d9d75a8efae
removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
 oheimb parents: 
14300diff
changeset | 304 | |
| 21305 | 305 | lemma postfix_ConsD2: "x#xs >>= y#ys ==> xs >>= ys" | 
| 306 | proof - | |
| 307 | assume "x#xs >>= y#ys" | |
| 308 | then obtain zs where "x#xs = zs @ y#ys" .. | |
| 309 | then show ?thesis | |
| 310 | by (induct zs) (auto intro!: postfix_appendI postfix_ConsI) | |
| 311 | qed | |
| 14538 
1d9d75a8efae
removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
 oheimb parents: 
14300diff
changeset | 312 | |
| 37474 | 313 | lemma postfix_to_prefix [code]: "xs >>= ys \<longleftrightarrow> rev ys \<le> rev xs" | 
| 21305 | 314 | proof | 
| 315 | assume "xs >>= ys" | |
| 316 | then obtain zs where "xs = zs @ ys" .. | |
| 317 | then have "rev xs = rev ys @ rev zs" by simp | |
| 318 | then show "rev ys <= rev xs" .. | |
| 319 | next | |
| 320 | assume "rev ys <= rev xs" | |
| 321 | then obtain zs where "rev xs = rev ys @ zs" .. | |
| 322 | then have "rev (rev xs) = rev zs @ rev (rev ys)" by simp | |
| 323 | then have "xs = rev zs @ ys" by simp | |
| 324 | then show "xs >>= ys" .. | |
| 325 | qed | |
| 17201 | 326 | |
| 25564 | 327 | lemma distinct_postfix: "distinct xs \<Longrightarrow> xs >>= ys \<Longrightarrow> distinct ys" | 
| 25692 | 328 | by (clarsimp elim!: postfixE) | 
| 25299 | 329 | |
| 25564 | 330 | lemma postfix_map: "xs >>= ys \<Longrightarrow> map f xs >>= map f ys" | 
| 25692 | 331 | by (auto elim!: postfixE intro: postfixI) | 
| 25299 | 332 | |
| 25356 | 333 | lemma postfix_drop: "as >>= drop n as" | 
| 25692 | 334 | unfolding postfix_def | 
| 335 | apply (rule exI [where x = "take n as"]) | |
| 336 | apply simp | |
| 337 | done | |
| 25299 | 338 | |
| 25564 | 339 | lemma postfix_take: "xs >>= ys \<Longrightarrow> xs = take (length xs - length ys) xs @ ys" | 
| 25692 | 340 | by (clarsimp elim!: postfixE) | 
| 25299 | 341 | |
| 25356 | 342 | lemma parallelD1: "x \<parallel> y \<Longrightarrow> \<not> x \<le> y" | 
| 25692 | 343 | by blast | 
| 25299 | 344 | |
| 25356 | 345 | lemma parallelD2: "x \<parallel> y \<Longrightarrow> \<not> y \<le> x" | 
| 25692 | 346 | by blast | 
| 25355 | 347 | |
| 348 | lemma parallel_Nil1 [simp]: "\<not> x \<parallel> []" | |
| 25692 | 349 | unfolding parallel_def by simp | 
| 25355 | 350 | |
| 25299 | 351 | lemma parallel_Nil2 [simp]: "\<not> [] \<parallel> x" | 
| 25692 | 352 | unfolding parallel_def by simp | 
| 25299 | 353 | |
| 25564 | 354 | lemma Cons_parallelI1: "a \<noteq> b \<Longrightarrow> a # as \<parallel> b # bs" | 
| 25692 | 355 | by auto | 
| 25299 | 356 | |
| 25564 | 357 | lemma Cons_parallelI2: "\<lbrakk> a = b; as \<parallel> bs \<rbrakk> \<Longrightarrow> a # as \<parallel> b # bs" | 
| 25692 | 358 | by (metis Cons_prefix_Cons parallelE parallelI) | 
| 25665 | 359 | |
| 25299 | 360 | lemma not_equal_is_parallel: | 
| 361 | assumes neq: "xs \<noteq> ys" | |
| 25356 | 362 | and len: "length xs = length ys" | 
| 363 | shows "xs \<parallel> ys" | |
| 25299 | 364 | using len neq | 
| 25355 | 365 | proof (induct rule: list_induct2) | 
| 26445 | 366 | case Nil | 
| 25356 | 367 | then show ?case by simp | 
| 25299 | 368 | next | 
| 26445 | 369 | case (Cons a as b bs) | 
| 25355 | 370 | have ih: "as \<noteq> bs \<Longrightarrow> as \<parallel> bs" by fact | 
| 25299 | 371 | show ?case | 
| 372 | proof (cases "a = b") | |
| 25355 | 373 | case True | 
| 26445 | 374 | then have "as \<noteq> bs" using Cons by simp | 
| 25355 | 375 | then show ?thesis by (rule Cons_parallelI2 [OF True ih]) | 
| 25299 | 376 | next | 
| 377 | case False | |
| 25355 | 378 | then show ?thesis by (rule Cons_parallelI1) | 
| 25299 | 379 | qed | 
| 380 | qed | |
| 22178 | 381 | |
| 10330 
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
 wenzelm parents: diff
changeset | 382 | end |