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