author | nipkow |
Mon, 23 May 2016 22:43:11 +0200 | |
changeset 63117 | acb6d72fc42e |
parent 61076 | bdc1e2f0a86a |
child 63149 | f5dbab18c404 |
permissions | -rw-r--r-- |
49087 | 1 |
(* Title: HOL/Library/Sublist.thy |
10330
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff
changeset
|
2 |
Author: Tobias Nipkow and Markus Wenzel, TU Muenchen |
49087 | 3 |
Author: Christian Sternagel, JAIST |
10330
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 |
|
60500 | 6 |
section \<open>List prefixes, suffixes, and homeomorphic embedding\<close> |
10330
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff
changeset
|
7 |
|
49087 | 8 |
theory Sublist |
9 |
imports Main |
|
15131 | 10 |
begin |
10330
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff
changeset
|
11 |
|
60500 | 12 |
subsection \<open>Prefix order on lists\<close> |
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
13 |
|
63117 | 14 |
definition prefix :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool" |
15 |
where "prefix xs ys \<longleftrightarrow> (\<exists>zs. ys = xs @ zs)" |
|
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
16 |
|
63117 | 17 |
definition strict_prefix :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool" |
18 |
where "strict_prefix xs ys \<longleftrightarrow> prefix xs ys \<and> xs \<noteq> ys" |
|
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
19 |
|
63117 | 20 |
interpretation prefix_order: order prefix strict_prefix |
21 |
by standard (auto simp: prefix_def strict_prefix_def) |
|
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
22 |
|
63117 | 23 |
interpretation prefix_bot: order_bot Nil prefix strict_prefix |
24 |
by standard (simp add: prefix_def) |
|
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
25 |
|
63117 | 26 |
lemma prefixI [intro?]: "ys = xs @ zs \<Longrightarrow> prefix xs ys" |
27 |
unfolding prefix_def by blast |
|
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
28 |
|
63117 | 29 |
lemma prefixE [elim?]: |
30 |
assumes "prefix xs ys" |
|
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
31 |
obtains zs where "ys = xs @ zs" |
63117 | 32 |
using assms unfolding prefix_def by blast |
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
33 |
|
63117 | 34 |
lemma strict_prefixI' [intro?]: "ys = xs @ z # zs \<Longrightarrow> strict_prefix xs ys" |
35 |
unfolding strict_prefix_def prefix_def by blast |
|
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
36 |
|
63117 | 37 |
lemma strict_prefixE' [elim?]: |
38 |
assumes "strict_prefix xs ys" |
|
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
39 |
obtains z zs where "ys = xs @ z # zs" |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
40 |
proof - |
63117 | 41 |
from \<open>strict_prefix xs ys\<close> obtain us where "ys = xs @ us" and "xs \<noteq> ys" |
42 |
unfolding strict_prefix_def prefix_def by blast |
|
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
43 |
with that show ?thesis by (auto simp add: neq_Nil_conv) |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
44 |
qed |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
45 |
|
63117 | 46 |
lemma strict_prefixI [intro?]: "prefix xs ys \<Longrightarrow> xs \<noteq> ys \<Longrightarrow> strict_prefix xs ys" |
47 |
unfolding strict_prefix_def by blast |
|
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
48 |
|
63117 | 49 |
lemma strict_prefixE [elim?]: |
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
50 |
fixes xs ys :: "'a list" |
63117 | 51 |
assumes "strict_prefix xs ys" |
52 |
obtains "prefix xs ys" and "xs \<noteq> ys" |
|
53 |
using assms unfolding strict_prefix_def by blast |
|
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
54 |
|
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
55 |
|
60500 | 56 |
subsection \<open>Basic properties of prefixes\<close> |
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
57 |
|
63117 | 58 |
theorem Nil_prefix [iff]: "prefix [] xs" |
59 |
by (simp add: prefix_def) |
|
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
60 |
|
63117 | 61 |
theorem prefix_Nil [simp]: "(prefix xs []) = (xs = [])" |
62 |
by (induct xs) (simp_all add: prefix_def) |
|
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
63 |
|
63117 | 64 |
lemma prefix_snoc [simp]: "prefix xs (ys @ [y]) \<longleftrightarrow> xs = ys @ [y] \<or> prefix xs ys" |
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
65 |
proof |
63117 | 66 |
assume "prefix xs (ys @ [y])" |
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
67 |
then obtain zs where zs: "ys @ [y] = xs @ zs" .. |
63117 | 68 |
show "xs = ys @ [y] \<or> prefix xs ys" |
69 |
by (metis append_Nil2 butlast_append butlast_snoc prefixI zs) |
|
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
70 |
next |
63117 | 71 |
assume "xs = ys @ [y] \<or> prefix xs ys" |
72 |
then show "prefix xs (ys @ [y])" |
|
73 |
by (metis prefix_order.eq_iff prefix_order.order_trans prefixI) |
|
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
74 |
qed |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
75 |
|
63117 | 76 |
lemma Cons_prefix_Cons [simp]: "prefix (x # xs) (y # ys) = (x = y \<and> prefix xs ys)" |
77 |
by (auto simp add: prefix_def) |
|
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
78 |
|
63117 | 79 |
lemma prefix_code [code]: |
80 |
"prefix [] xs \<longleftrightarrow> True" |
|
81 |
"prefix (x # xs) [] \<longleftrightarrow> False" |
|
82 |
"prefix (x # xs) (y # ys) \<longleftrightarrow> x = y \<and> prefix xs ys" |
|
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
83 |
by simp_all |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
84 |
|
63117 | 85 |
lemma same_prefix_prefix [simp]: "prefix (xs @ ys) (xs @ zs) = prefix ys zs" |
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
86 |
by (induct xs) simp_all |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
87 |
|
63117 | 88 |
lemma same_prefix_nil [iff]: "prefix (xs @ ys) xs = (ys = [])" |
89 |
by (metis append_Nil2 append_self_conv prefix_order.eq_iff prefixI) |
|
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
90 |
|
63117 | 91 |
lemma prefix_prefix [simp]: "prefix xs ys \<Longrightarrow> prefix xs (ys @ zs)" |
92 |
by (metis prefix_order.le_less_trans prefixI strict_prefixE strict_prefixI) |
|
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
93 |
|
63117 | 94 |
lemma append_prefixD: "prefix (xs @ ys) zs \<Longrightarrow> prefix xs zs" |
95 |
by (auto simp add: prefix_def) |
|
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
96 |
|
63117 | 97 |
theorem prefix_Cons: "prefix xs (y # ys) = (xs = [] \<or> (\<exists>zs. xs = y # zs \<and> prefix zs ys))" |
98 |
by (cases xs) (auto simp add: prefix_def) |
|
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
99 |
|
63117 | 100 |
theorem prefix_append: |
101 |
"prefix xs (ys @ zs) = (prefix xs ys \<or> (\<exists>us. xs = ys @ us \<and> prefix us zs))" |
|
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
102 |
apply (induct zs rule: rev_induct) |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
103 |
apply force |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
104 |
apply (simp del: append_assoc add: append_assoc [symmetric]) |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
105 |
apply (metis append_eq_appendI) |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
106 |
done |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
107 |
|
63117 | 108 |
lemma append_one_prefix: |
109 |
"prefix xs ys \<Longrightarrow> length xs < length ys \<Longrightarrow> prefix (xs @ [ys ! length xs]) ys" |
|
110 |
proof (unfold prefix_def) |
|
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
111 |
assume a1: "\<exists>zs. ys = xs @ zs" |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
112 |
then obtain sk :: "'a list" where sk: "ys = xs @ sk" by fastforce |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
113 |
assume a2: "length xs < length ys" |
61076 | 114 |
have f1: "\<And>v. ([]::'a list) @ v = v" using append_Nil2 by simp |
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
115 |
have "[] \<noteq> sk" using a1 a2 sk less_not_refl by force |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
116 |
hence "\<exists>v. xs @ hd sk # v = ys" using sk by (metis hd_Cons_tl) |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
117 |
thus "\<exists>zs. ys = (xs @ [ys ! length xs]) @ zs" using f1 by fastforce |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
118 |
qed |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
119 |
|
63117 | 120 |
theorem prefix_length_le: "prefix xs ys \<Longrightarrow> length xs \<le> length ys" |
121 |
by (auto simp add: prefix_def) |
|
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
122 |
|
63117 | 123 |
lemma prefix_same_cases: |
124 |
"prefix (xs\<^sub>1::'a list) ys \<Longrightarrow> prefix xs\<^sub>2 ys \<Longrightarrow> prefix xs\<^sub>1 xs\<^sub>2 \<or> prefix xs\<^sub>2 xs\<^sub>1" |
|
125 |
unfolding prefix_def by (force simp: append_eq_append_conv2) |
|
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
126 |
|
63117 | 127 |
lemma set_mono_prefix: "prefix xs ys \<Longrightarrow> set xs \<subseteq> set ys" |
128 |
by (auto simp add: prefix_def) |
|
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
129 |
|
63117 | 130 |
lemma take_is_prefix: "prefix (take n xs) xs" |
131 |
unfolding prefix_def by (metis append_take_drop_id) |
|
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
132 |
|
63117 | 133 |
lemma map_prefixI: "prefix xs ys \<Longrightarrow> prefix (map f xs) (map f ys)" |
134 |
by (auto simp: prefix_def) |
|
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
135 |
|
63117 | 136 |
lemma prefix_length_less: "strict_prefix xs ys \<Longrightarrow> length xs < length ys" |
137 |
by (auto simp: strict_prefix_def prefix_def) |
|
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
138 |
|
63117 | 139 |
lemma strict_prefix_simps [simp, code]: |
140 |
"strict_prefix xs [] \<longleftrightarrow> False" |
|
141 |
"strict_prefix [] (x # xs) \<longleftrightarrow> True" |
|
142 |
"strict_prefix (x # xs) (y # ys) \<longleftrightarrow> x = y \<and> strict_prefix xs ys" |
|
143 |
by (simp_all add: strict_prefix_def cong: conj_cong) |
|
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
144 |
|
63117 | 145 |
lemma take_strict_prefix: "strict_prefix xs ys \<Longrightarrow> strict_prefix (take n xs) ys" |
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
146 |
apply (induct n arbitrary: xs ys) |
59997 | 147 |
apply (case_tac ys; simp) |
63117 | 148 |
apply (metis prefix_order.less_trans strict_prefixI take_is_prefix) |
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
149 |
done |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
150 |
|
63117 | 151 |
lemma not_prefix_cases: |
152 |
assumes pfx: "\<not> prefix ps ls" |
|
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
153 |
obtains |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
154 |
(c1) "ps \<noteq> []" and "ls = []" |
63117 | 155 |
| (c2) a as x xs where "ps = a#as" and "ls = x#xs" and "x = a" and "\<not> prefix as xs" |
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
156 |
| (c3) a as x xs where "ps = a#as" and "ls = x#xs" and "x \<noteq> a" |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
157 |
proof (cases ps) |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
158 |
case Nil |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
159 |
then show ?thesis using pfx by simp |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
160 |
next |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
161 |
case (Cons a as) |
60500 | 162 |
note c = \<open>ps = a#as\<close> |
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
163 |
show ?thesis |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
164 |
proof (cases ls) |
63117 | 165 |
case Nil then show ?thesis by (metis append_Nil2 pfx c1 same_prefix_nil) |
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
166 |
next |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
167 |
case (Cons x xs) |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
168 |
show ?thesis |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
169 |
proof (cases "x = a") |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
170 |
case True |
63117 | 171 |
have "\<not> prefix as xs" using pfx c Cons True by simp |
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
172 |
with c Cons True show ?thesis by (rule c2) |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
173 |
next |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
174 |
case False |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
175 |
with c Cons show ?thesis by (rule c3) |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
176 |
qed |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
177 |
qed |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
178 |
qed |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
179 |
|
63117 | 180 |
lemma not_prefix_induct [consumes 1, case_names Nil Neq Eq]: |
181 |
assumes np: "\<not> prefix ps ls" |
|
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
182 |
and base: "\<And>x xs. P (x#xs) []" |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
183 |
and r1: "\<And>x xs y ys. x \<noteq> y \<Longrightarrow> P (x#xs) (y#ys)" |
63117 | 184 |
and r2: "\<And>x xs y ys. \<lbrakk> x = y; \<not> prefix xs ys; P xs ys \<rbrakk> \<Longrightarrow> P (x#xs) (y#ys)" |
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
185 |
shows "P ps ls" using np |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
186 |
proof (induct ls arbitrary: ps) |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
187 |
case Nil then show ?case |
63117 | 188 |
by (auto simp: neq_Nil_conv elim!: not_prefix_cases intro!: base) |
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
189 |
next |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
190 |
case (Cons y ys) |
63117 | 191 |
then have npfx: "\<not> prefix ps (y # ys)" by simp |
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
192 |
then obtain x xs where pv: "ps = x # xs" |
63117 | 193 |
by (rule not_prefix_cases) auto |
194 |
show ?case by (metis Cons.hyps Cons_prefix_Cons npfx pv r1 r2) |
|
55579
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
195 |
qed |
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
196 |
|
207538943038
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents:
54538
diff
changeset
|
197 |
|
60500 | 198 |
subsection \<open>Parallel lists\<close> |
10389 | 199 |
|
50516 | 200 |
definition parallel :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool" (infixl "\<parallel>" 50) |
63117 | 201 |
where "(xs \<parallel> ys) = (\<not> prefix xs ys \<and> \<not> prefix ys xs)" |
10389 | 202 |
|
63117 | 203 |
lemma parallelI [intro]: "\<not> prefix xs ys \<Longrightarrow> \<not> prefix ys xs \<Longrightarrow> xs \<parallel> ys" |
25692 | 204 |
unfolding parallel_def by blast |
10330
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff
changeset
|
205 |
|
10389 | 206 |
lemma parallelE [elim]: |
25692 | 207 |
assumes "xs \<parallel> ys" |
63117 | 208 |
obtains "\<not> prefix xs ys \<and> \<not> prefix ys xs" |
25692 | 209 |
using assms unfolding parallel_def by blast |
10330
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff
changeset
|
210 |
|
63117 | 211 |
theorem prefix_cases: |
212 |
obtains "prefix xs ys" | "strict_prefix ys xs" | "xs \<parallel> ys" |
|
213 |
unfolding parallel_def strict_prefix_def by blast |
|
10330
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff
changeset
|
214 |
|
10389 | 215 |
theorem parallel_decomp: |
50516 | 216 |
"xs \<parallel> ys \<Longrightarrow> \<exists>as b bs c cs. b \<noteq> c \<and> xs = as @ b # bs \<and> ys = as @ c # cs" |
10408 | 217 |
proof (induct xs rule: rev_induct) |
11987 | 218 |
case Nil |
23254 | 219 |
then have False by auto |
220 |
then show ?case .. |
|
10408 | 221 |
next |
11987 | 222 |
case (snoc x xs) |
223 |
show ?case |
|
63117 | 224 |
proof (rule prefix_cases) |
225 |
assume le: "prefix xs ys" |
|
10408 | 226 |
then obtain ys' where ys: "ys = xs @ ys'" .. |
227 |
show ?thesis |
|
228 |
proof (cases ys') |
|
25564 | 229 |
assume "ys' = []" |
63117 | 230 |
then show ?thesis by (metis append_Nil2 parallelE prefixI snoc.prems ys) |
10389 | 231 |
next |
10408 | 232 |
fix c cs assume ys': "ys' = c # cs" |
54483 | 233 |
have "x \<noteq> c" using snoc.prems ys ys' by fastforce |
234 |
thus "\<exists>as b bs c cs. b \<noteq> c \<and> xs @ [x] = as @ b # bs \<and> ys = as @ c # cs" |
|
235 |
using ys ys' by blast |
|
10389 | 236 |
qed |
10408 | 237 |
next |
63117 | 238 |
assume "strict_prefix ys xs" |
239 |
then have "prefix ys (xs @ [x])" by (simp add: strict_prefix_def) |
|
11987 | 240 |
with snoc have False by blast |
23254 | 241 |
then show ?thesis .. |
10408 | 242 |
next |
243 |
assume "xs \<parallel> ys" |
|
11987 | 244 |
with snoc obtain as b bs c cs where neq: "(b::'a) \<noteq> c" |
10408 | 245 |
and xs: "xs = as @ b # bs" and ys: "ys = as @ c # cs" |
246 |
by blast |
|
247 |
from xs have "xs @ [x] = as @ b # (bs @ [x])" by simp |
|
248 |
with neq ys show ?thesis by blast |
|
10389 | 249 |
qed |
250 |
qed |
|
10330
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff
changeset
|
251 |
|
25564 | 252 |
lemma parallel_append: "a \<parallel> b \<Longrightarrow> a @ c \<parallel> b @ d" |
25692 | 253 |
apply (rule parallelI) |
254 |
apply (erule parallelE, erule conjE, |
|
63117 | 255 |
induct rule: not_prefix_induct, simp+)+ |
25692 | 256 |
done |
25299 | 257 |
|
25692 | 258 |
lemma parallel_appendI: "xs \<parallel> ys \<Longrightarrow> x = xs @ xs' \<Longrightarrow> y = ys @ ys' \<Longrightarrow> x \<parallel> y" |
259 |
by (simp add: parallel_append) |
|
25299 | 260 |
|
25692 | 261 |
lemma parallel_commute: "a \<parallel> b \<longleftrightarrow> b \<parallel> a" |
262 |
unfolding parallel_def by auto |
|
14538
1d9d75a8efae
removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents:
14300
diff
changeset
|
263 |
|
25356 | 264 |
|
60500 | 265 |
subsection \<open>Suffix order on lists\<close> |
17201 | 266 |
|
49107 | 267 |
definition suffixeq :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool" |
268 |
where "suffixeq xs ys = (\<exists>zs. ys = zs @ xs)" |
|
49087 | 269 |
|
49107 | 270 |
definition suffix :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool" |
271 |
where "suffix xs ys \<longleftrightarrow> (\<exists>us. ys = us @ xs \<and> us \<noteq> [])" |
|
14538
1d9d75a8efae
removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents:
14300
diff
changeset
|
272 |
|
49087 | 273 |
lemma suffix_imp_suffixeq: |
274 |
"suffix xs ys \<Longrightarrow> suffixeq xs ys" |
|
275 |
by (auto simp: suffixeq_def suffix_def) |
|
276 |
||
50516 | 277 |
lemma suffixeqI [intro?]: "ys = zs @ xs \<Longrightarrow> suffixeq xs ys" |
49087 | 278 |
unfolding suffixeq_def by blast |
21305 | 279 |
|
49087 | 280 |
lemma suffixeqE [elim?]: |
281 |
assumes "suffixeq xs ys" |
|
282 |
obtains zs where "ys = zs @ xs" |
|
283 |
using assms unfolding suffixeq_def by blast |
|
21305 | 284 |
|
49087 | 285 |
lemma suffixeq_refl [iff]: "suffixeq xs xs" |
286 |
by (auto simp add: suffixeq_def) |
|
287 |
lemma suffix_trans: |
|
288 |
"suffix xs ys \<Longrightarrow> suffix ys zs \<Longrightarrow> suffix xs zs" |
|
289 |
by (auto simp: suffix_def) |
|
290 |
lemma suffixeq_trans: "\<lbrakk>suffixeq xs ys; suffixeq ys zs\<rbrakk> \<Longrightarrow> suffixeq xs zs" |
|
291 |
by (auto simp add: suffixeq_def) |
|
292 |
lemma suffixeq_antisym: "\<lbrakk>suffixeq xs ys; suffixeq ys xs\<rbrakk> \<Longrightarrow> xs = ys" |
|
293 |
by (auto simp add: suffixeq_def) |
|
294 |
||
295 |
lemma suffixeq_tl [simp]: "suffixeq (tl xs) xs" |
|
296 |
by (induct xs) (auto simp: suffixeq_def) |
|
14538
1d9d75a8efae
removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents:
14300
diff
changeset
|
297 |
|
49087 | 298 |
lemma suffix_tl [simp]: "xs \<noteq> [] \<Longrightarrow> suffix (tl xs) xs" |
299 |
by (induct xs) (auto simp: suffix_def) |
|
14538
1d9d75a8efae
removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents:
14300
diff
changeset
|
300 |
|
49087 | 301 |
lemma Nil_suffixeq [iff]: "suffixeq [] xs" |
302 |
by (simp add: suffixeq_def) |
|
303 |
lemma suffixeq_Nil [simp]: "(suffixeq xs []) = (xs = [])" |
|
304 |
by (auto simp add: suffixeq_def) |
|
305 |
||
49107 | 306 |
lemma suffixeq_ConsI: "suffixeq xs ys \<Longrightarrow> suffixeq xs (y # ys)" |
49087 | 307 |
by (auto simp add: suffixeq_def) |
49107 | 308 |
lemma suffixeq_ConsD: "suffixeq (x # xs) ys \<Longrightarrow> suffixeq xs ys" |
49087 | 309 |
by (auto simp add: suffixeq_def) |
14538
1d9d75a8efae
removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents:
14300
diff
changeset
|
310 |
|
49087 | 311 |
lemma suffixeq_appendI: "suffixeq xs ys \<Longrightarrow> suffixeq xs (zs @ ys)" |
312 |
by (auto simp add: suffixeq_def) |
|
313 |
lemma suffixeq_appendD: "suffixeq (zs @ xs) ys \<Longrightarrow> suffixeq xs ys" |
|
314 |
by (auto simp add: suffixeq_def) |
|
315 |
||
316 |
lemma suffix_set_subset: |
|
317 |
"suffix xs ys \<Longrightarrow> set xs \<subseteq> set ys" by (auto simp: suffix_def) |
|
14538
1d9d75a8efae
removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents:
14300
diff
changeset
|
318 |
|
49087 | 319 |
lemma suffixeq_set_subset: |
320 |
"suffixeq xs ys \<Longrightarrow> set xs \<subseteq> set ys" by (auto simp: suffixeq_def) |
|
321 |
||
49107 | 322 |
lemma suffixeq_ConsD2: "suffixeq (x # xs) (y # ys) \<Longrightarrow> suffixeq xs ys" |
21305 | 323 |
proof - |
49107 | 324 |
assume "suffixeq (x # xs) (y # ys)" |
325 |
then obtain zs where "y # ys = zs @ x # xs" .. |
|
49087 | 326 |
then show ?thesis |
327 |
by (induct zs) (auto intro!: suffixeq_appendI suffixeq_ConsI) |
|
21305 | 328 |
qed |
14538
1d9d75a8efae
removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents:
14300
diff
changeset
|
329 |
|
63117 | 330 |
lemma suffixeq_to_prefix [code]: "suffixeq xs ys \<longleftrightarrow> prefix (rev xs) (rev ys)" |
49087 | 331 |
proof |
332 |
assume "suffixeq xs ys" |
|
333 |
then obtain zs where "ys = zs @ xs" .. |
|
334 |
then have "rev ys = rev xs @ rev zs" by simp |
|
63117 | 335 |
then show "prefix (rev xs) (rev ys)" .. |
49087 | 336 |
next |
63117 | 337 |
assume "prefix (rev xs) (rev ys)" |
49087 | 338 |
then obtain zs where "rev ys = rev xs @ zs" .. |
339 |
then have "rev (rev ys) = rev zs @ rev (rev xs)" by simp |
|
340 |
then have "ys = rev zs @ xs" by simp |
|
341 |
then show "suffixeq xs ys" .. |
|
21305 | 342 |
qed |
14538
1d9d75a8efae
removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents:
14300
diff
changeset
|
343 |
|
49087 | 344 |
lemma distinct_suffixeq: "distinct ys \<Longrightarrow> suffixeq xs ys \<Longrightarrow> distinct xs" |
345 |
by (clarsimp elim!: suffixeqE) |
|
17201 | 346 |
|
49087 | 347 |
lemma suffixeq_map: "suffixeq xs ys \<Longrightarrow> suffixeq (map f xs) (map f ys)" |
348 |
by (auto elim!: suffixeqE intro: suffixeqI) |
|
25299 | 349 |
|
49087 | 350 |
lemma suffixeq_drop: "suffixeq (drop n as) as" |
351 |
unfolding suffixeq_def |
|
25692 | 352 |
apply (rule exI [where x = "take n as"]) |
353 |
apply simp |
|
354 |
done |
|
25299 | 355 |
|
49087 | 356 |
lemma suffixeq_take: "suffixeq xs ys \<Longrightarrow> ys = take (length ys - length xs) ys @ xs" |
49107 | 357 |
by (auto elim!: suffixeqE) |
25299 | 358 |
|
49107 | 359 |
lemma suffixeq_suffix_reflclp_conv: "suffixeq = suffix\<^sup>=\<^sup>=" |
49087 | 360 |
proof (intro ext iffI) |
361 |
fix xs ys :: "'a list" |
|
362 |
assume "suffixeq xs ys" |
|
363 |
show "suffix\<^sup>=\<^sup>= xs ys" |
|
364 |
proof |
|
365 |
assume "xs \<noteq> ys" |
|
60500 | 366 |
with \<open>suffixeq xs ys\<close> show "suffix xs ys" |
49107 | 367 |
by (auto simp: suffixeq_def suffix_def) |
49087 | 368 |
qed |
369 |
next |
|
370 |
fix xs ys :: "'a list" |
|
371 |
assume "suffix\<^sup>=\<^sup>= xs ys" |
|
49107 | 372 |
then show "suffixeq xs ys" |
49087 | 373 |
proof |
49107 | 374 |
assume "suffix xs ys" then show "suffixeq xs ys" |
375 |
by (rule suffix_imp_suffixeq) |
|
49087 | 376 |
next |
49107 | 377 |
assume "xs = ys" then show "suffixeq xs ys" |
378 |
by (auto simp: suffixeq_def) |
|
49087 | 379 |
qed |
380 |
qed |
|
381 |
||
63117 | 382 |
lemma parallelD1: "x \<parallel> y \<Longrightarrow> \<not> prefix x y" |
25692 | 383 |
by blast |
25299 | 384 |
|
63117 | 385 |
lemma parallelD2: "x \<parallel> y \<Longrightarrow> \<not> prefix y x" |
25692 | 386 |
by blast |
25355 | 387 |
|
388 |
lemma parallel_Nil1 [simp]: "\<not> x \<parallel> []" |
|
25692 | 389 |
unfolding parallel_def by simp |
25355 | 390 |
|
25299 | 391 |
lemma parallel_Nil2 [simp]: "\<not> [] \<parallel> x" |
25692 | 392 |
unfolding parallel_def by simp |
25299 | 393 |
|
25564 | 394 |
lemma Cons_parallelI1: "a \<noteq> b \<Longrightarrow> a # as \<parallel> b # bs" |
25692 | 395 |
by auto |
25299 | 396 |
|
25564 | 397 |
lemma Cons_parallelI2: "\<lbrakk> a = b; as \<parallel> bs \<rbrakk> \<Longrightarrow> a # as \<parallel> b # bs" |
63117 | 398 |
by (metis Cons_prefix_Cons parallelE parallelI) |
25665 | 399 |
|
25299 | 400 |
lemma not_equal_is_parallel: |
401 |
assumes neq: "xs \<noteq> ys" |
|
25356 | 402 |
and len: "length xs = length ys" |
403 |
shows "xs \<parallel> ys" |
|
25299 | 404 |
using len neq |
25355 | 405 |
proof (induct rule: list_induct2) |
26445 | 406 |
case Nil |
25356 | 407 |
then show ?case by simp |
25299 | 408 |
next |
26445 | 409 |
case (Cons a as b bs) |
25355 | 410 |
have ih: "as \<noteq> bs \<Longrightarrow> as \<parallel> bs" by fact |
25299 | 411 |
show ?case |
412 |
proof (cases "a = b") |
|
25355 | 413 |
case True |
26445 | 414 |
then have "as \<noteq> bs" using Cons by simp |
25355 | 415 |
then show ?thesis by (rule Cons_parallelI2 [OF True ih]) |
25299 | 416 |
next |
417 |
case False |
|
25355 | 418 |
then show ?thesis by (rule Cons_parallelI1) |
25299 | 419 |
qed |
420 |
qed |
|
22178 | 421 |
|
49107 | 422 |
lemma suffix_reflclp_conv: "suffix\<^sup>=\<^sup>= = suffixeq" |
49087 | 423 |
by (intro ext) (auto simp: suffixeq_def suffix_def) |
424 |
||
49107 | 425 |
lemma suffix_lists: "suffix xs ys \<Longrightarrow> ys \<in> lists A \<Longrightarrow> xs \<in> lists A" |
49087 | 426 |
unfolding suffix_def by auto |
427 |
||
428 |
||
60500 | 429 |
subsection \<open>Homeomorphic embedding on lists\<close> |
49087 | 430 |
|
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
431 |
inductive list_emb :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> bool" |
49087 | 432 |
for P :: "('a \<Rightarrow> 'a \<Rightarrow> bool)" |
433 |
where |
|
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
434 |
list_emb_Nil [intro, simp]: "list_emb P [] ys" |
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
435 |
| list_emb_Cons [intro] : "list_emb P xs ys \<Longrightarrow> list_emb P xs (y#ys)" |
57498
ea44ec62a574
no built-in reflexivity of list embedding (which is more standard; now embedding is reflexive whenever the base-order is)
Christian Sternagel
parents:
57497
diff
changeset
|
436 |
| list_emb_Cons2 [intro]: "P x y \<Longrightarrow> list_emb P xs ys \<Longrightarrow> list_emb P (x#xs) (y#ys)" |
50516 | 437 |
|
57499
7e22776f2d32
added monotonicity lemma for list embedding
Christian Sternagel
parents:
57498
diff
changeset
|
438 |
lemma list_emb_mono: |
7e22776f2d32
added monotonicity lemma for list embedding
Christian Sternagel
parents:
57498
diff
changeset
|
439 |
assumes "\<And>x y. P x y \<longrightarrow> Q x y" |
7e22776f2d32
added monotonicity lemma for list embedding
Christian Sternagel
parents:
57498
diff
changeset
|
440 |
shows "list_emb P xs ys \<longrightarrow> list_emb Q xs ys" |
7e22776f2d32
added monotonicity lemma for list embedding
Christian Sternagel
parents:
57498
diff
changeset
|
441 |
proof |
7e22776f2d32
added monotonicity lemma for list embedding
Christian Sternagel
parents:
57498
diff
changeset
|
442 |
assume "list_emb P xs ys" |
7e22776f2d32
added monotonicity lemma for list embedding
Christian Sternagel
parents:
57498
diff
changeset
|
443 |
then show "list_emb Q xs ys" by (induct) (auto simp: assms) |
7e22776f2d32
added monotonicity lemma for list embedding
Christian Sternagel
parents:
57498
diff
changeset
|
444 |
qed |
7e22776f2d32
added monotonicity lemma for list embedding
Christian Sternagel
parents:
57498
diff
changeset
|
445 |
|
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
446 |
lemma list_emb_Nil2 [simp]: |
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
447 |
assumes "list_emb P xs []" shows "xs = []" |
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
448 |
using assms by (cases rule: list_emb.cases) auto |
49087 | 449 |
|
57498
ea44ec62a574
no built-in reflexivity of list embedding (which is more standard; now embedding is reflexive whenever the base-order is)
Christian Sternagel
parents:
57497
diff
changeset
|
450 |
lemma list_emb_refl: |
ea44ec62a574
no built-in reflexivity of list embedding (which is more standard; now embedding is reflexive whenever the base-order is)
Christian Sternagel
parents:
57497
diff
changeset
|
451 |
assumes "\<And>x. x \<in> set xs \<Longrightarrow> P x x" |
ea44ec62a574
no built-in reflexivity of list embedding (which is more standard; now embedding is reflexive whenever the base-order is)
Christian Sternagel
parents:
57497
diff
changeset
|
452 |
shows "list_emb P xs xs" |
ea44ec62a574
no built-in reflexivity of list embedding (which is more standard; now embedding is reflexive whenever the base-order is)
Christian Sternagel
parents:
57497
diff
changeset
|
453 |
using assms by (induct xs) auto |
49087 | 454 |
|
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
455 |
lemma list_emb_Cons_Nil [simp]: "list_emb P (x#xs) [] = False" |
49087 | 456 |
proof - |
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
457 |
{ assume "list_emb P (x#xs) []" |
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
458 |
from list_emb_Nil2 [OF this] have False by simp |
49087 | 459 |
} moreover { |
460 |
assume False |
|
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
461 |
then have "list_emb P (x#xs) []" by simp |
49087 | 462 |
} ultimately show ?thesis by blast |
463 |
qed |
|
464 |
||
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
465 |
lemma list_emb_append2 [intro]: "list_emb P xs ys \<Longrightarrow> list_emb P xs (zs @ ys)" |
49087 | 466 |
by (induct zs) auto |
467 |
||
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
468 |
lemma list_emb_prefix [intro]: |
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
469 |
assumes "list_emb P xs ys" shows "list_emb P xs (ys @ zs)" |
49087 | 470 |
using assms |
471 |
by (induct arbitrary: zs) auto |
|
472 |
||
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
473 |
lemma list_emb_ConsD: |
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
474 |
assumes "list_emb P (x#xs) ys" |
57498
ea44ec62a574
no built-in reflexivity of list embedding (which is more standard; now embedding is reflexive whenever the base-order is)
Christian Sternagel
parents:
57497
diff
changeset
|
475 |
shows "\<exists>us v vs. ys = us @ v # vs \<and> P x v \<and> list_emb P xs vs" |
49087 | 476 |
using assms |
49107 | 477 |
proof (induct x \<equiv> "x # xs" ys arbitrary: x xs) |
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
478 |
case list_emb_Cons |
49107 | 479 |
then show ?case by (metis append_Cons) |
49087 | 480 |
next |
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
481 |
case (list_emb_Cons2 x y xs ys) |
54483 | 482 |
then show ?case by blast |
49087 | 483 |
qed |
484 |
||
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
485 |
lemma list_emb_appendD: |
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
486 |
assumes "list_emb P (xs @ ys) zs" |
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
487 |
shows "\<exists>us vs. zs = us @ vs \<and> list_emb P xs us \<and> list_emb P ys vs" |
49087 | 488 |
using assms |
489 |
proof (induction xs arbitrary: ys zs) |
|
49107 | 490 |
case Nil then show ?case by auto |
49087 | 491 |
next |
492 |
case (Cons x xs) |
|
54483 | 493 |
then obtain us v vs where |
57498
ea44ec62a574
no built-in reflexivity of list embedding (which is more standard; now embedding is reflexive whenever the base-order is)
Christian Sternagel
parents:
57497
diff
changeset
|
494 |
zs: "zs = us @ v # vs" and p: "P x v" and lh: "list_emb P (xs @ ys) vs" |
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
495 |
by (auto dest: list_emb_ConsD) |
54483 | 496 |
obtain sk\<^sub>0 :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list" and sk\<^sub>1 :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list" where |
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
497 |
sk: "\<forall>x\<^sub>0 x\<^sub>1. \<not> list_emb P (xs @ x\<^sub>0) x\<^sub>1 \<or> sk\<^sub>0 x\<^sub>0 x\<^sub>1 @ sk\<^sub>1 x\<^sub>0 x\<^sub>1 = x\<^sub>1 \<and> list_emb P xs (sk\<^sub>0 x\<^sub>0 x\<^sub>1) \<and> list_emb P x\<^sub>0 (sk\<^sub>1 x\<^sub>0 x\<^sub>1)" |
54483 | 498 |
using Cons(1) by (metis (no_types)) |
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
499 |
hence "\<forall>x\<^sub>2. list_emb P (x # xs) (x\<^sub>2 @ v # sk\<^sub>0 ys vs)" using p lh by auto |
54483 | 500 |
thus ?case using lh zs sk by (metis (no_types) append_Cons append_assoc) |
49087 | 501 |
qed |
502 |
||
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
503 |
lemma list_emb_suffix: |
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
504 |
assumes "list_emb P xs ys" and "suffix ys zs" |
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
505 |
shows "list_emb P xs zs" |
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
506 |
using assms(2) and list_emb_append2 [OF assms(1)] by (auto simp: suffix_def) |
49087 | 507 |
|
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
508 |
lemma list_emb_suffixeq: |
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
509 |
assumes "list_emb P xs ys" and "suffixeq ys zs" |
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
510 |
shows "list_emb P xs zs" |
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
511 |
using assms and list_emb_suffix unfolding suffixeq_suffix_reflclp_conv by auto |
49087 | 512 |
|
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
513 |
lemma list_emb_length: "list_emb P xs ys \<Longrightarrow> length xs \<le> length ys" |
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
514 |
by (induct rule: list_emb.induct) auto |
49087 | 515 |
|
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
516 |
lemma list_emb_trans: |
57500
5a8b3e9d82a4
weaker assumption for "list_emb_trans"; added lemma
Christian Sternagel
parents:
57499
diff
changeset
|
517 |
assumes "\<And>x y z. \<lbrakk>x \<in> set xs; y \<in> set ys; z \<in> set zs; P x y; P y z\<rbrakk> \<Longrightarrow> P x z" |
5a8b3e9d82a4
weaker assumption for "list_emb_trans"; added lemma
Christian Sternagel
parents:
57499
diff
changeset
|
518 |
shows "\<lbrakk>list_emb P xs ys; list_emb P ys zs\<rbrakk> \<Longrightarrow> list_emb P xs zs" |
50516 | 519 |
proof - |
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
520 |
assume "list_emb P xs ys" and "list_emb P ys zs" |
57500
5a8b3e9d82a4
weaker assumption for "list_emb_trans"; added lemma
Christian Sternagel
parents:
57499
diff
changeset
|
521 |
then show "list_emb P xs zs" using assms |
49087 | 522 |
proof (induction arbitrary: zs) |
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
523 |
case list_emb_Nil show ?case by blast |
49087 | 524 |
next |
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
525 |
case (list_emb_Cons xs ys y) |
60500 | 526 |
from list_emb_ConsD [OF \<open>list_emb P (y#ys) zs\<close>] obtain us v vs |
57500
5a8b3e9d82a4
weaker assumption for "list_emb_trans"; added lemma
Christian Sternagel
parents:
57499
diff
changeset
|
527 |
where zs: "zs = us @ v # vs" and "P\<^sup>=\<^sup>= y v" and "list_emb P ys vs" by blast |
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
528 |
then have "list_emb P ys (v#vs)" by blast |
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
529 |
then have "list_emb P ys zs" unfolding zs by (rule list_emb_append2) |
57500
5a8b3e9d82a4
weaker assumption for "list_emb_trans"; added lemma
Christian Sternagel
parents:
57499
diff
changeset
|
530 |
from list_emb_Cons.IH [OF this] and list_emb_Cons.prems show ?case by auto |
49087 | 531 |
next |
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
532 |
case (list_emb_Cons2 x y xs ys) |
60500 | 533 |
from list_emb_ConsD [OF \<open>list_emb P (y#ys) zs\<close>] obtain us v vs |
57498
ea44ec62a574
no built-in reflexivity of list embedding (which is more standard; now embedding is reflexive whenever the base-order is)
Christian Sternagel
parents:
57497
diff
changeset
|
534 |
where zs: "zs = us @ v # vs" and "P y v" and "list_emb P ys vs" by blast |
57500
5a8b3e9d82a4
weaker assumption for "list_emb_trans"; added lemma
Christian Sternagel
parents:
57499
diff
changeset
|
535 |
with list_emb_Cons2 have "list_emb P xs vs" by auto |
57498
ea44ec62a574
no built-in reflexivity of list embedding (which is more standard; now embedding is reflexive whenever the base-order is)
Christian Sternagel
parents:
57497
diff
changeset
|
536 |
moreover have "P x v" |
49087 | 537 |
proof - |
57500
5a8b3e9d82a4
weaker assumption for "list_emb_trans"; added lemma
Christian Sternagel
parents:
57499
diff
changeset
|
538 |
from zs have "v \<in> set zs" by auto |
5a8b3e9d82a4
weaker assumption for "list_emb_trans"; added lemma
Christian Sternagel
parents:
57499
diff
changeset
|
539 |
moreover have "x \<in> set (x#xs)" and "y \<in> set (y#ys)" by simp_all |
50516 | 540 |
ultimately show ?thesis |
60500 | 541 |
using \<open>P x y\<close> and \<open>P y v\<close> and list_emb_Cons2 |
50516 | 542 |
by blast |
49087 | 543 |
qed |
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
544 |
ultimately have "list_emb P (x#xs) (v#vs)" by blast |
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
545 |
then show ?case unfolding zs by (rule list_emb_append2) |
49087 | 546 |
qed |
547 |
qed |
|
548 |
||
57500
5a8b3e9d82a4
weaker assumption for "list_emb_trans"; added lemma
Christian Sternagel
parents:
57499
diff
changeset
|
549 |
lemma list_emb_set: |
5a8b3e9d82a4
weaker assumption for "list_emb_trans"; added lemma
Christian Sternagel
parents:
57499
diff
changeset
|
550 |
assumes "list_emb P xs ys" and "x \<in> set xs" |
5a8b3e9d82a4
weaker assumption for "list_emb_trans"; added lemma
Christian Sternagel
parents:
57499
diff
changeset
|
551 |
obtains y where "y \<in> set ys" and "P x y" |
5a8b3e9d82a4
weaker assumption for "list_emb_trans"; added lemma
Christian Sternagel
parents:
57499
diff
changeset
|
552 |
using assms by (induct) auto |
5a8b3e9d82a4
weaker assumption for "list_emb_trans"; added lemma
Christian Sternagel
parents:
57499
diff
changeset
|
553 |
|
49087 | 554 |
|
60500 | 555 |
subsection \<open>Sublists (special case of homeomorphic embedding)\<close> |
49087 | 556 |
|
50516 | 557 |
abbreviation sublisteq :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool" |
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
558 |
where "sublisteq xs ys \<equiv> list_emb (op =) xs ys" |
49087 | 559 |
|
50516 | 560 |
lemma sublisteq_Cons2: "sublisteq xs ys \<Longrightarrow> sublisteq (x#xs) (x#ys)" by auto |
49087 | 561 |
|
50516 | 562 |
lemma sublisteq_same_length: |
563 |
assumes "sublisteq xs ys" and "length xs = length ys" shows "xs = ys" |
|
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
564 |
using assms by (induct) (auto dest: list_emb_length) |
49087 | 565 |
|
50516 | 566 |
lemma not_sublisteq_length [simp]: "length ys < length xs \<Longrightarrow> \<not> sublisteq xs ys" |
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
567 |
by (metis list_emb_length linorder_not_less) |
49087 | 568 |
|
569 |
lemma [code]: |
|
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
570 |
"list_emb P [] ys \<longleftrightarrow> True" |
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
571 |
"list_emb P (x#xs) [] \<longleftrightarrow> False" |
49087 | 572 |
by (simp_all) |
573 |
||
50516 | 574 |
lemma sublisteq_Cons': "sublisteq (x#xs) ys \<Longrightarrow> sublisteq xs ys" |
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
575 |
by (induct xs, simp, blast dest: list_emb_ConsD) |
49087 | 576 |
|
50516 | 577 |
lemma sublisteq_Cons2': |
578 |
assumes "sublisteq (x#xs) (x#ys)" shows "sublisteq xs ys" |
|
579 |
using assms by (cases) (rule sublisteq_Cons') |
|
49087 | 580 |
|
50516 | 581 |
lemma sublisteq_Cons2_neq: |
582 |
assumes "sublisteq (x#xs) (y#ys)" |
|
583 |
shows "x \<noteq> y \<Longrightarrow> sublisteq (x#xs) ys" |
|
49087 | 584 |
using assms by (cases) auto |
585 |
||
50516 | 586 |
lemma sublisteq_Cons2_iff [simp, code]: |
587 |
"sublisteq (x#xs) (y#ys) = (if x = y then sublisteq xs ys else sublisteq (x#xs) ys)" |
|
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
588 |
by (metis list_emb_Cons sublisteq_Cons2 sublisteq_Cons2' sublisteq_Cons2_neq) |
49087 | 589 |
|
50516 | 590 |
lemma sublisteq_append': "sublisteq (zs @ xs) (zs @ ys) \<longleftrightarrow> sublisteq xs ys" |
49087 | 591 |
by (induct zs) simp_all |
592 |
||
50516 | 593 |
lemma sublisteq_refl [simp, intro!]: "sublisteq xs xs" by (induct xs) simp_all |
49087 | 594 |
|
50516 | 595 |
lemma sublisteq_antisym: |
596 |
assumes "sublisteq xs ys" and "sublisteq ys xs" |
|
49087 | 597 |
shows "xs = ys" |
598 |
using assms |
|
599 |
proof (induct) |
|
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
600 |
case list_emb_Nil |
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
601 |
from list_emb_Nil2 [OF this] show ?case by simp |
49087 | 602 |
next |
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
603 |
case list_emb_Cons2 |
54483 | 604 |
thus ?case by simp |
49087 | 605 |
next |
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
606 |
case list_emb_Cons |
54483 | 607 |
hence False using sublisteq_Cons' by fastforce |
608 |
thus ?case .. |
|
49087 | 609 |
qed |
610 |
||
50516 | 611 |
lemma sublisteq_trans: "sublisteq xs ys \<Longrightarrow> sublisteq ys zs \<Longrightarrow> sublisteq xs zs" |
57500
5a8b3e9d82a4
weaker assumption for "list_emb_trans"; added lemma
Christian Sternagel
parents:
57499
diff
changeset
|
612 |
by (rule list_emb_trans [of _ _ _ "op ="]) auto |
49087 | 613 |
|
50516 | 614 |
lemma sublisteq_append_le_same_iff: "sublisteq (xs @ ys) ys \<longleftrightarrow> xs = []" |
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
615 |
by (auto dest: list_emb_length) |
49087 | 616 |
|
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
617 |
lemma list_emb_append_mono: |
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
618 |
"\<lbrakk> list_emb P xs xs'; list_emb P ys ys' \<rbrakk> \<Longrightarrow> list_emb P (xs@ys) (xs'@ys')" |
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
619 |
apply (induct rule: list_emb.induct) |
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
620 |
apply (metis eq_Nil_appendI list_emb_append2) |
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
621 |
apply (metis append_Cons list_emb_Cons) |
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
622 |
apply (metis append_Cons list_emb_Cons2) |
49107 | 623 |
done |
49087 | 624 |
|
625 |
||
60500 | 626 |
subsection \<open>Appending elements\<close> |
49087 | 627 |
|
50516 | 628 |
lemma sublisteq_append [simp]: |
629 |
"sublisteq (xs @ zs) (ys @ zs) \<longleftrightarrow> sublisteq xs ys" (is "?l = ?r") |
|
49087 | 630 |
proof |
50516 | 631 |
{ fix xs' ys' xs ys zs :: "'a list" assume "sublisteq xs' ys'" |
632 |
then have "xs' = xs @ zs & ys' = ys @ zs \<longrightarrow> sublisteq xs ys" |
|
49087 | 633 |
proof (induct arbitrary: xs ys zs) |
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
634 |
case list_emb_Nil show ?case by simp |
49087 | 635 |
next |
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
636 |
case (list_emb_Cons xs' ys' x) |
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
637 |
{ assume "ys=[]" then have ?case using list_emb_Cons(1) by auto } |
49087 | 638 |
moreover |
639 |
{ fix us assume "ys = x#us" |
|
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
640 |
then have ?case using list_emb_Cons(2) by(simp add: list_emb.list_emb_Cons) } |
49087 | 641 |
ultimately show ?case by (auto simp:Cons_eq_append_conv) |
642 |
next |
|
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
643 |
case (list_emb_Cons2 x y xs' ys') |
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
644 |
{ assume "xs=[]" then have ?case using list_emb_Cons2(1) by auto } |
49087 | 645 |
moreover |
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
646 |
{ fix us vs assume "xs=x#us" "ys=x#vs" then have ?case using list_emb_Cons2 by auto} |
49087 | 647 |
moreover |
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
648 |
{ fix us assume "xs=x#us" "ys=[]" then have ?case using list_emb_Cons2(2) by bestsimp } |
60500 | 649 |
ultimately show ?case using \<open>op = x y\<close> by (auto simp: Cons_eq_append_conv) |
49087 | 650 |
qed } |
651 |
moreover assume ?l |
|
652 |
ultimately show ?r by blast |
|
653 |
next |
|
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
654 |
assume ?r then show ?l by (metis list_emb_append_mono sublisteq_refl) |
49087 | 655 |
qed |
656 |
||
50516 | 657 |
lemma sublisteq_drop_many: "sublisteq xs ys \<Longrightarrow> sublisteq xs (zs @ ys)" |
49087 | 658 |
by (induct zs) auto |
659 |
||
50516 | 660 |
lemma sublisteq_rev_drop_many: "sublisteq xs ys \<Longrightarrow> sublisteq xs (ys @ zs)" |
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
661 |
by (metis append_Nil2 list_emb_Nil list_emb_append_mono) |
49087 | 662 |
|
663 |
||
60500 | 664 |
subsection \<open>Relation to standard list operations\<close> |
49087 | 665 |
|
50516 | 666 |
lemma sublisteq_map: |
667 |
assumes "sublisteq xs ys" shows "sublisteq (map f xs) (map f ys)" |
|
49087 | 668 |
using assms by (induct) auto |
669 |
||
50516 | 670 |
lemma sublisteq_filter_left [simp]: "sublisteq (filter P xs) xs" |
49087 | 671 |
by (induct xs) auto |
672 |
||
50516 | 673 |
lemma sublisteq_filter [simp]: |
674 |
assumes "sublisteq xs ys" shows "sublisteq (filter P xs) (filter P ys)" |
|
54483 | 675 |
using assms by induct auto |
49087 | 676 |
|
50516 | 677 |
lemma "sublisteq xs ys \<longleftrightarrow> (\<exists>N. xs = sublist ys N)" (is "?L = ?R") |
49087 | 678 |
proof |
679 |
assume ?L |
|
49107 | 680 |
then show ?R |
49087 | 681 |
proof (induct) |
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
682 |
case list_emb_Nil show ?case by (metis sublist_empty) |
49087 | 683 |
next |
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
684 |
case (list_emb_Cons xs ys x) |
49087 | 685 |
then obtain N where "xs = sublist ys N" by blast |
49107 | 686 |
then have "xs = sublist (x#ys) (Suc ` N)" |
49087 | 687 |
by (clarsimp simp add:sublist_Cons inj_image_mem_iff) |
49107 | 688 |
then show ?case by blast |
49087 | 689 |
next |
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
690 |
case (list_emb_Cons2 x y xs ys) |
49087 | 691 |
then obtain N where "xs = sublist ys N" by blast |
49107 | 692 |
then have "x#xs = sublist (x#ys) (insert 0 (Suc ` N))" |
49087 | 693 |
by (clarsimp simp add:sublist_Cons inj_image_mem_iff) |
57497
4106a2bc066a
renamed "list_hembeq" into slightly shorter "list_emb"
Christian Sternagel
parents:
55579
diff
changeset
|
694 |
moreover from list_emb_Cons2 have "x = y" by simp |
50516 | 695 |
ultimately show ?case by blast |
49087 | 696 |
qed |
697 |
next |
|
698 |
assume ?R |
|
699 |
then obtain N where "xs = sublist ys N" .. |
|
50516 | 700 |
moreover have "sublisteq (sublist ys N) ys" |
49107 | 701 |
proof (induct ys arbitrary: N) |
49087 | 702 |
case Nil show ?case by simp |
703 |
next |
|
49107 | 704 |
case Cons then show ?case by (auto simp: sublist_Cons) |
49087 | 705 |
qed |
706 |
ultimately show ?L by simp |
|
707 |
qed |
|
708 |
||
10330
4362e906b745
"List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff
changeset
|
709 |
end |