author | paulson |
Tue, 04 Aug 1998 16:06:55 +0200 | |
changeset 5242 | 3087dafb70ec |
parent 5200 | a23c23af335f |
child 5272 | 95cfd872fe66 |
permissions | -rw-r--r-- |
1465 | 1 |
(* Title: HOL/List |
923 | 2 |
ID: $Id$ |
1465 | 3 |
Author: Tobias Nipkow |
923 | 4 |
Copyright 1994 TU Muenchen |
5 |
||
6 |
List lemmas |
|
7 |
*) |
|
8 |
||
4935 | 9 |
Goal "!x. xs ~= x#xs"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
10 |
by (induct_tac "xs" 1); |
5129 | 11 |
by (Auto_tac); |
2608 | 12 |
qed_spec_mp "not_Cons_self"; |
3574 | 13 |
bind_thm("not_Cons_self2",not_Cons_self RS not_sym); |
14 |
Addsimps [not_Cons_self,not_Cons_self2]; |
|
923 | 15 |
|
4935 | 16 |
Goal "(xs ~= []) = (? y ys. xs = y#ys)"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
17 |
by (induct_tac "xs" 1); |
5129 | 18 |
by (Auto_tac); |
923 | 19 |
qed "neq_Nil_conv"; |
20 |
||
4830 | 21 |
(* Induction over the length of a list: *) |
4935 | 22 |
val [prem] = Goal |
4911 | 23 |
"(!!xs. (!ys. length ys < length xs --> P ys) ==> P xs) ==> P(xs)"; |
5132 | 24 |
by (rtac measure_induct 1 THEN etac prem 1); |
4911 | 25 |
qed "length_induct"; |
26 |
||
923 | 27 |
|
3468 | 28 |
(** "lists": the list-forming operator over sets **) |
3342
ec3b55fcb165
New operator "lists" for formalizing sets of lists
paulson
parents:
3292
diff
changeset
|
29 |
|
5043 | 30 |
Goalw lists.defs "A<=B ==> lists A <= lists B"; |
3342
ec3b55fcb165
New operator "lists" for formalizing sets of lists
paulson
parents:
3292
diff
changeset
|
31 |
by (rtac lfp_mono 1); |
ec3b55fcb165
New operator "lists" for formalizing sets of lists
paulson
parents:
3292
diff
changeset
|
32 |
by (REPEAT (ares_tac basic_monos 1)); |
ec3b55fcb165
New operator "lists" for formalizing sets of lists
paulson
parents:
3292
diff
changeset
|
33 |
qed "lists_mono"; |
3196 | 34 |
|
3468 | 35 |
val listsE = lists.mk_cases list.simps "x#l : lists A"; |
36 |
AddSEs [listsE]; |
|
37 |
AddSIs lists.intrs; |
|
38 |
||
5043 | 39 |
Goal "l: lists A ==> l: lists B --> l: lists (A Int B)"; |
3468 | 40 |
by (etac lists.induct 1); |
41 |
by (ALLGOALS Blast_tac); |
|
42 |
qed_spec_mp "lists_IntI"; |
|
43 |
||
4935 | 44 |
Goal "lists (A Int B) = lists A Int lists B"; |
4423 | 45 |
by (rtac (mono_Int RS equalityI) 1); |
4089 | 46 |
by (simp_tac (simpset() addsimps [mono_def, lists_mono]) 1); |
47 |
by (blast_tac (claset() addSIs [lists_IntI]) 1); |
|
3468 | 48 |
qed "lists_Int_eq"; |
49 |
Addsimps [lists_Int_eq]; |
|
50 |
||
3196 | 51 |
|
4643 | 52 |
(** Case analysis **) |
53 |
section "Case analysis"; |
|
2608 | 54 |
|
4935 | 55 |
val prems = Goal "[| P([]); !!x xs. P(x#xs) |] ==> P(xs)"; |
3457 | 56 |
by (induct_tac "xs" 1); |
57 |
by (REPEAT(resolve_tac prems 1)); |
|
2608 | 58 |
qed "list_cases"; |
59 |
||
4935 | 60 |
Goal "(xs=[] --> P([])) & (!y ys. xs=y#ys --> P(y#ys)) --> P(xs)"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
61 |
by (induct_tac "xs" 1); |
2891 | 62 |
by (Blast_tac 1); |
63 |
by (Blast_tac 1); |
|
2608 | 64 |
bind_thm("list_eq_cases", |
65 |
impI RSN (2,allI RSN (2,allI RSN (2,impI RS (conjI RS (result() RS mp)))))); |
|
66 |
||
3860 | 67 |
(** length **) |
68 |
(* needs to come before "@" because of thm append_eq_append_conv *) |
|
69 |
||
70 |
section "length"; |
|
71 |
||
4935 | 72 |
Goal "length(xs@ys) = length(xs)+length(ys)"; |
3860 | 73 |
by (induct_tac "xs" 1); |
5129 | 74 |
by (Auto_tac); |
3860 | 75 |
qed"length_append"; |
76 |
Addsimps [length_append]; |
|
77 |
||
5129 | 78 |
Goal "length (map f xs) = length xs"; |
79 |
by (induct_tac "xs" 1); |
|
80 |
by (Auto_tac); |
|
3860 | 81 |
qed "length_map"; |
82 |
Addsimps [length_map]; |
|
83 |
||
4935 | 84 |
Goal "length(rev xs) = length(xs)"; |
3860 | 85 |
by (induct_tac "xs" 1); |
5129 | 86 |
by (Auto_tac); |
3860 | 87 |
qed "length_rev"; |
88 |
Addsimps [length_rev]; |
|
89 |
||
5043 | 90 |
Goal "xs ~= [] ==> length(tl xs) = (length xs) - 1"; |
4423 | 91 |
by (exhaust_tac "xs" 1); |
5129 | 92 |
by (Auto_tac); |
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
93 |
qed "length_tl"; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
94 |
Addsimps [length_tl]; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
95 |
|
4935 | 96 |
Goal "(length xs = 0) = (xs = [])"; |
3860 | 97 |
by (induct_tac "xs" 1); |
5129 | 98 |
by (Auto_tac); |
3860 | 99 |
qed "length_0_conv"; |
100 |
AddIffs [length_0_conv]; |
|
101 |
||
4935 | 102 |
Goal "(0 = length xs) = (xs = [])"; |
3860 | 103 |
by (induct_tac "xs" 1); |
5129 | 104 |
by (Auto_tac); |
3860 | 105 |
qed "zero_length_conv"; |
106 |
AddIffs [zero_length_conv]; |
|
107 |
||
4935 | 108 |
Goal "(0 < length xs) = (xs ~= [])"; |
3860 | 109 |
by (induct_tac "xs" 1); |
5129 | 110 |
by (Auto_tac); |
3860 | 111 |
qed "length_greater_0_conv"; |
112 |
AddIffs [length_greater_0_conv]; |
|
113 |
||
923 | 114 |
(** @ - append **) |
115 |
||
3467 | 116 |
section "@ - append"; |
117 |
||
4935 | 118 |
Goal "(xs@ys)@zs = xs@(ys@zs)"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
119 |
by (induct_tac "xs" 1); |
5129 | 120 |
by (Auto_tac); |
923 | 121 |
qed "append_assoc"; |
2512 | 122 |
Addsimps [append_assoc]; |
923 | 123 |
|
4935 | 124 |
Goal "xs @ [] = xs"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
125 |
by (induct_tac "xs" 1); |
5129 | 126 |
by (Auto_tac); |
923 | 127 |
qed "append_Nil2"; |
2512 | 128 |
Addsimps [append_Nil2]; |
923 | 129 |
|
4935 | 130 |
Goal "(xs@ys = []) = (xs=[] & ys=[])"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
131 |
by (induct_tac "xs" 1); |
5129 | 132 |
by (Auto_tac); |
2608 | 133 |
qed "append_is_Nil_conv"; |
134 |
AddIffs [append_is_Nil_conv]; |
|
135 |
||
4935 | 136 |
Goal "([] = xs@ys) = (xs=[] & ys=[])"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
137 |
by (induct_tac "xs" 1); |
5129 | 138 |
by (Auto_tac); |
2608 | 139 |
qed "Nil_is_append_conv"; |
140 |
AddIffs [Nil_is_append_conv]; |
|
923 | 141 |
|
4935 | 142 |
Goal "(xs @ ys = xs) = (ys=[])"; |
3574 | 143 |
by (induct_tac "xs" 1); |
5129 | 144 |
by (Auto_tac); |
3574 | 145 |
qed "append_self_conv"; |
146 |
||
4935 | 147 |
Goal "(xs = xs @ ys) = (ys=[])"; |
3574 | 148 |
by (induct_tac "xs" 1); |
5129 | 149 |
by (Auto_tac); |
3574 | 150 |
qed "self_append_conv"; |
151 |
AddIffs [append_self_conv,self_append_conv]; |
|
152 |
||
4935 | 153 |
Goal "!ys. length xs = length ys | length us = length vs \ |
3860 | 154 |
\ --> (xs@us = ys@vs) = (xs=ys & us=vs)"; |
4423 | 155 |
by (induct_tac "xs" 1); |
156 |
by (rtac allI 1); |
|
157 |
by (exhaust_tac "ys" 1); |
|
158 |
by (Asm_simp_tac 1); |
|
159 |
by (fast_tac (claset() addIs [less_add_Suc2] addss simpset() |
|
3860 | 160 |
addEs [less_not_refl2 RSN (2,rev_notE)]) 1); |
4423 | 161 |
by (rtac allI 1); |
162 |
by (exhaust_tac "ys" 1); |
|
163 |
by (fast_tac (claset() addIs [less_add_Suc2] addss simpset() |
|
3860 | 164 |
addEs [(less_not_refl2 RS not_sym) RSN (2,rev_notE)]) 1); |
4423 | 165 |
by (Asm_simp_tac 1); |
3860 | 166 |
qed_spec_mp "append_eq_append_conv"; |
167 |
Addsimps [append_eq_append_conv]; |
|
168 |
||
4935 | 169 |
Goal "(xs @ ys = xs @ zs) = (ys=zs)"; |
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
170 |
by (Simp_tac 1); |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
171 |
qed "same_append_eq"; |
3860 | 172 |
|
4935 | 173 |
Goal "(xs @ [x] = ys @ [y]) = (xs = ys & x = y)"; |
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
174 |
by (Simp_tac 1); |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
175 |
qed "append1_eq_conv"; |
2608 | 176 |
|
4935 | 177 |
Goal "(ys @ xs = zs @ xs) = (ys=zs)"; |
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
178 |
by (Simp_tac 1); |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
179 |
qed "append_same_eq"; |
2608 | 180 |
|
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
181 |
AddSIs |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
182 |
[same_append_eq RS iffD2, append1_eq_conv RS iffD2, append_same_eq RS iffD2]; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
183 |
AddSDs |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
184 |
[same_append_eq RS iffD1, append1_eq_conv RS iffD1, append_same_eq RS iffD1]; |
3571 | 185 |
|
4935 | 186 |
Goal "(xs @ ys = ys) = (xs=[])"; |
5132 | 187 |
by (cut_inst_tac [("zs","[]")] append_same_eq 1); |
5129 | 188 |
by (Auto_tac); |
4647 | 189 |
qed "append_self_conv2"; |
190 |
||
4935 | 191 |
Goal "(ys = xs @ ys) = (xs=[])"; |
5132 | 192 |
by (simp_tac (simpset() addsimps |
4647 | 193 |
[simplify (simpset()) (read_instantiate[("ys","[]")]append_same_eq)]) 1); |
5132 | 194 |
by (Blast_tac 1); |
4647 | 195 |
qed "self_append_conv2"; |
196 |
AddIffs [append_self_conv2,self_append_conv2]; |
|
197 |
||
4935 | 198 |
Goal "xs ~= [] --> hd xs # tl xs = xs"; |
3457 | 199 |
by (induct_tac "xs" 1); |
5129 | 200 |
by (Auto_tac); |
2608 | 201 |
qed_spec_mp "hd_Cons_tl"; |
202 |
Addsimps [hd_Cons_tl]; |
|
923 | 203 |
|
4935 | 204 |
Goal "hd(xs@ys) = (if xs=[] then hd ys else hd xs)"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
205 |
by (induct_tac "xs" 1); |
5129 | 206 |
by (Auto_tac); |
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
207 |
qed "hd_append"; |
923 | 208 |
|
5043 | 209 |
Goal "xs ~= [] ==> hd(xs @ ys) = hd xs"; |
4089 | 210 |
by (asm_simp_tac (simpset() addsimps [hd_append] |
5183 | 211 |
addsplits [list.split]) 1); |
3571 | 212 |
qed "hd_append2"; |
213 |
Addsimps [hd_append2]; |
|
214 |
||
4935 | 215 |
Goal "tl(xs@ys) = (case xs of [] => tl(ys) | z#zs => zs@ys)"; |
5183 | 216 |
by (simp_tac (simpset() addsplits [list.split]) 1); |
2608 | 217 |
qed "tl_append"; |
218 |
||
5043 | 219 |
Goal "xs ~= [] ==> tl(xs @ ys) = (tl xs) @ ys"; |
4089 | 220 |
by (asm_simp_tac (simpset() addsimps [tl_append] |
5183 | 221 |
addsplits [list.split]) 1); |
3571 | 222 |
qed "tl_append2"; |
223 |
Addsimps [tl_append2]; |
|
224 |
||
4830 | 225 |
|
2608 | 226 |
(** map **) |
227 |
||
3467 | 228 |
section "map"; |
229 |
||
4935 | 230 |
Goal |
3465 | 231 |
"(!x. x : set xs --> f x = g x) --> map f xs = map g xs"; |
3457 | 232 |
by (induct_tac "xs" 1); |
5129 | 233 |
by (Auto_tac); |
2608 | 234 |
bind_thm("map_ext", impI RS (allI RS (result() RS mp))); |
235 |
||
4935 | 236 |
Goal "map (%x. x) = (%xs. xs)"; |
2608 | 237 |
by (rtac ext 1); |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
238 |
by (induct_tac "xs" 1); |
5129 | 239 |
by (Auto_tac); |
2608 | 240 |
qed "map_ident"; |
241 |
Addsimps[map_ident]; |
|
242 |
||
4935 | 243 |
Goal "map f (xs@ys) = map f xs @ map f ys"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
244 |
by (induct_tac "xs" 1); |
5129 | 245 |
by (Auto_tac); |
2608 | 246 |
qed "map_append"; |
247 |
Addsimps[map_append]; |
|
248 |
||
4935 | 249 |
Goalw [o_def] "map (f o g) xs = map f (map g xs)"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
250 |
by (induct_tac "xs" 1); |
5129 | 251 |
by (Auto_tac); |
2608 | 252 |
qed "map_compose"; |
253 |
Addsimps[map_compose]; |
|
254 |
||
4935 | 255 |
Goal "rev(map f xs) = map f (rev xs)"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
256 |
by (induct_tac "xs" 1); |
5129 | 257 |
by (Auto_tac); |
2608 | 258 |
qed "rev_map"; |
259 |
||
3589
244daa75f890
Added function `replicate' and lemmas map_cong and set_replicate.
nipkow
parents:
3586
diff
changeset
|
260 |
(* a congruence rule for map: *) |
4935 | 261 |
Goal |
3589
244daa75f890
Added function `replicate' and lemmas map_cong and set_replicate.
nipkow
parents:
3586
diff
changeset
|
262 |
"(xs=ys) --> (!x. x : set ys --> f x = g x) --> map f xs = map g ys"; |
4423 | 263 |
by (rtac impI 1); |
264 |
by (hyp_subst_tac 1); |
|
265 |
by (induct_tac "ys" 1); |
|
5129 | 266 |
by (Auto_tac); |
3589
244daa75f890
Added function `replicate' and lemmas map_cong and set_replicate.
nipkow
parents:
3586
diff
changeset
|
267 |
val lemma = result(); |
244daa75f890
Added function `replicate' and lemmas map_cong and set_replicate.
nipkow
parents:
3586
diff
changeset
|
268 |
bind_thm("map_cong",impI RSN (2,allI RSN (2,lemma RS mp RS mp))); |
244daa75f890
Added function `replicate' and lemmas map_cong and set_replicate.
nipkow
parents:
3586
diff
changeset
|
269 |
|
4935 | 270 |
Goal "(map f xs = []) = (xs = [])"; |
4423 | 271 |
by (induct_tac "xs" 1); |
5129 | 272 |
by (Auto_tac); |
3860 | 273 |
qed "map_is_Nil_conv"; |
274 |
AddIffs [map_is_Nil_conv]; |
|
275 |
||
4935 | 276 |
Goal "([] = map f xs) = (xs = [])"; |
4423 | 277 |
by (induct_tac "xs" 1); |
5129 | 278 |
by (Auto_tac); |
3860 | 279 |
qed "Nil_is_map_conv"; |
280 |
AddIffs [Nil_is_map_conv]; |
|
281 |
||
282 |
||
1169 | 283 |
(** rev **) |
284 |
||
3467 | 285 |
section "rev"; |
286 |
||
4935 | 287 |
Goal "rev(xs@ys) = rev(ys) @ rev(xs)"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
288 |
by (induct_tac "xs" 1); |
5129 | 289 |
by (Auto_tac); |
1169 | 290 |
qed "rev_append"; |
2512 | 291 |
Addsimps[rev_append]; |
1169 | 292 |
|
4935 | 293 |
Goal "rev(rev l) = l"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
294 |
by (induct_tac "l" 1); |
5129 | 295 |
by (Auto_tac); |
1169 | 296 |
qed "rev_rev_ident"; |
2512 | 297 |
Addsimps[rev_rev_ident]; |
1169 | 298 |
|
4935 | 299 |
Goal "(rev xs = []) = (xs = [])"; |
4423 | 300 |
by (induct_tac "xs" 1); |
5129 | 301 |
by (Auto_tac); |
3860 | 302 |
qed "rev_is_Nil_conv"; |
303 |
AddIffs [rev_is_Nil_conv]; |
|
304 |
||
4935 | 305 |
Goal "([] = rev xs) = (xs = [])"; |
4423 | 306 |
by (induct_tac "xs" 1); |
5129 | 307 |
by (Auto_tac); |
3860 | 308 |
qed "Nil_is_rev_conv"; |
309 |
AddIffs [Nil_is_rev_conv]; |
|
310 |
||
4935 | 311 |
val prems = Goal "[| P []; !!x xs. P xs ==> P(xs@[x]) |] ==> P xs"; |
5132 | 312 |
by (stac (rev_rev_ident RS sym) 1); |
4935 | 313 |
br(read_instantiate [("P","%xs. ?P(rev xs)")]list.induct)1; |
5132 | 314 |
by (ALLGOALS Simp_tac); |
315 |
by (resolve_tac prems 1); |
|
316 |
by (eresolve_tac prems 1); |
|
4935 | 317 |
qed "rev_induct"; |
318 |
||
319 |
Goal "(xs = [] --> P) --> (!ys y. xs = ys@[y] --> P) --> P"; |
|
5132 | 320 |
by (res_inst_tac [("xs","xs")] rev_induct 1); |
321 |
by (Auto_tac); |
|
4935 | 322 |
bind_thm ("rev_exhaust", |
323 |
impI RSN (2,allI RSN (2,allI RSN (2,impI RS (result() RS mp RS mp))))); |
|
324 |
||
2608 | 325 |
|
923 | 326 |
(** mem **) |
327 |
||
3467 | 328 |
section "mem"; |
329 |
||
4935 | 330 |
Goal "x mem (xs@ys) = (x mem xs | x mem ys)"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
331 |
by (induct_tac "xs" 1); |
5129 | 332 |
by (Auto_tac); |
923 | 333 |
qed "mem_append"; |
2512 | 334 |
Addsimps[mem_append]; |
923 | 335 |
|
4935 | 336 |
Goal "x mem [x:xs. P(x)] = (x mem xs & P(x))"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
337 |
by (induct_tac "xs" 1); |
5129 | 338 |
by (Auto_tac); |
923 | 339 |
qed "mem_filter"; |
2512 | 340 |
Addsimps[mem_filter]; |
923 | 341 |
|
3465 | 342 |
(** set **) |
1812 | 343 |
|
3467 | 344 |
section "set"; |
345 |
||
4935 | 346 |
Goal "set (xs@ys) = (set xs Un set ys)"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
347 |
by (induct_tac "xs" 1); |
5129 | 348 |
by (Auto_tac); |
3647
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
349 |
qed "set_append"; |
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
350 |
Addsimps[set_append]; |
1812 | 351 |
|
4935 | 352 |
Goal "(x mem xs) = (x: set xs)"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
353 |
by (induct_tac "xs" 1); |
5129 | 354 |
by (Auto_tac); |
3647
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
355 |
qed "set_mem_eq"; |
1812 | 356 |
|
4935 | 357 |
Goal "set l <= set (x#l)"; |
5129 | 358 |
by (Auto_tac); |
3647
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
359 |
qed "set_subset_Cons"; |
1936 | 360 |
|
4935 | 361 |
Goal "(set xs = {}) = (xs = [])"; |
3457 | 362 |
by (induct_tac "xs" 1); |
5129 | 363 |
by (Auto_tac); |
3647
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
364 |
qed "set_empty"; |
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
365 |
Addsimps [set_empty]; |
2608 | 366 |
|
4935 | 367 |
Goal "set(rev xs) = set(xs)"; |
3457 | 368 |
by (induct_tac "xs" 1); |
5129 | 369 |
by (Auto_tac); |
3647
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
370 |
qed "set_rev"; |
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
371 |
Addsimps [set_rev]; |
2608 | 372 |
|
4935 | 373 |
Goal "set(map f xs) = f``(set xs)"; |
3457 | 374 |
by (induct_tac "xs" 1); |
5129 | 375 |
by (Auto_tac); |
3647
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
376 |
qed "set_map"; |
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
377 |
Addsimps [set_map]; |
2608 | 378 |
|
4935 | 379 |
Goal "(x : set(filter P xs)) = (x : set xs & P x)"; |
4605 | 380 |
by (induct_tac "xs" 1); |
5129 | 381 |
by (Auto_tac); |
4605 | 382 |
qed "in_set_filter"; |
383 |
Addsimps [in_set_filter]; |
|
384 |
||
1812 | 385 |
|
923 | 386 |
(** list_all **) |
387 |
||
3467 | 388 |
section "list_all"; |
389 |
||
4935 | 390 |
Goal "list_all (%x. True) xs = True"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
391 |
by (induct_tac "xs" 1); |
5129 | 392 |
by (Auto_tac); |
923 | 393 |
qed "list_all_True"; |
2512 | 394 |
Addsimps [list_all_True]; |
923 | 395 |
|
4935 | 396 |
Goal "list_all p (xs@ys) = (list_all p xs & list_all p ys)"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
397 |
by (induct_tac "xs" 1); |
5129 | 398 |
by (Auto_tac); |
2512 | 399 |
qed "list_all_append"; |
400 |
Addsimps [list_all_append]; |
|
923 | 401 |
|
4935 | 402 |
Goal "list_all P xs = (!x. x mem xs --> P(x))"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
403 |
by (induct_tac "xs" 1); |
5129 | 404 |
by (Auto_tac); |
923 | 405 |
qed "list_all_mem_conv"; |
406 |
||
407 |
||
2608 | 408 |
(** filter **) |
923 | 409 |
|
3467 | 410 |
section "filter"; |
411 |
||
4935 | 412 |
Goal "filter P (xs@ys) = filter P xs @ filter P ys"; |
3457 | 413 |
by (induct_tac "xs" 1); |
5129 | 414 |
by (Auto_tac); |
2608 | 415 |
qed "filter_append"; |
416 |
Addsimps [filter_append]; |
|
417 |
||
4935 | 418 |
Goal "filter (%x. True) xs = xs"; |
4605 | 419 |
by (induct_tac "xs" 1); |
5129 | 420 |
by (Auto_tac); |
4605 | 421 |
qed "filter_True"; |
422 |
Addsimps [filter_True]; |
|
423 |
||
4935 | 424 |
Goal "filter (%x. False) xs = []"; |
4605 | 425 |
by (induct_tac "xs" 1); |
5129 | 426 |
by (Auto_tac); |
4605 | 427 |
qed "filter_False"; |
428 |
Addsimps [filter_False]; |
|
429 |
||
4935 | 430 |
Goal "length (filter P xs) <= length xs"; |
3457 | 431 |
by (induct_tac "xs" 1); |
5129 | 432 |
by (Auto_tac); |
4605 | 433 |
qed "length_filter"; |
3383
7707cb7a5054
Corrected statement of filter_append; added filter_size
paulson
parents:
3342
diff
changeset
|
434 |
|
2608 | 435 |
|
436 |
(** concat **) |
|
437 |
||
3467 | 438 |
section "concat"; |
439 |
||
4935 | 440 |
Goal "concat(xs@ys) = concat(xs)@concat(ys)"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
441 |
by (induct_tac "xs" 1); |
5129 | 442 |
by (Auto_tac); |
2608 | 443 |
qed"concat_append"; |
444 |
Addsimps [concat_append]; |
|
2512 | 445 |
|
4935 | 446 |
Goal "(concat xss = []) = (!xs:set xss. xs=[])"; |
4423 | 447 |
by (induct_tac "xss" 1); |
5129 | 448 |
by (Auto_tac); |
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
449 |
qed "concat_eq_Nil_conv"; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
450 |
AddIffs [concat_eq_Nil_conv]; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
451 |
|
4935 | 452 |
Goal "([] = concat xss) = (!xs:set xss. xs=[])"; |
4423 | 453 |
by (induct_tac "xss" 1); |
5129 | 454 |
by (Auto_tac); |
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
455 |
qed "Nil_eq_concat_conv"; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
456 |
AddIffs [Nil_eq_concat_conv]; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
457 |
|
4935 | 458 |
Goal "set(concat xs) = Union(set `` set xs)"; |
3467 | 459 |
by (induct_tac "xs" 1); |
5129 | 460 |
by (Auto_tac); |
3647
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
461 |
qed"set_concat"; |
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
462 |
Addsimps [set_concat]; |
3467 | 463 |
|
4935 | 464 |
Goal "map f (concat xs) = concat (map (map f) xs)"; |
3467 | 465 |
by (induct_tac "xs" 1); |
5129 | 466 |
by (Auto_tac); |
3467 | 467 |
qed "map_concat"; |
468 |
||
4935 | 469 |
Goal "filter p (concat xs) = concat (map (filter p) xs)"; |
3467 | 470 |
by (induct_tac "xs" 1); |
5129 | 471 |
by (Auto_tac); |
3467 | 472 |
qed"filter_concat"; |
473 |
||
4935 | 474 |
Goal "rev(concat xs) = concat (map rev (rev xs))"; |
3467 | 475 |
by (induct_tac "xs" 1); |
5129 | 476 |
by (Auto_tac); |
2608 | 477 |
qed "rev_concat"; |
923 | 478 |
|
479 |
(** nth **) |
|
480 |
||
3467 | 481 |
section "nth"; |
482 |
||
4935 | 483 |
Goal |
4502 | 484 |
"!xs. (xs@ys)!n = (if n < length xs then xs!n else ys!(n - length xs))"; |
5183 | 485 |
by (induct_tac "n" 1); |
3457 | 486 |
by (Asm_simp_tac 1); |
487 |
by (rtac allI 1); |
|
488 |
by (exhaust_tac "xs" 1); |
|
5129 | 489 |
by (Auto_tac); |
2608 | 490 |
qed_spec_mp "nth_append"; |
491 |
||
4935 | 492 |
Goal "!n. n < length xs --> (map f xs)!n = f(xs!n)"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
493 |
by (induct_tac "xs" 1); |
1301 | 494 |
(* case [] *) |
495 |
by (Asm_full_simp_tac 1); |
|
496 |
(* case x#xl *) |
|
497 |
by (rtac allI 1); |
|
5183 | 498 |
by (induct_tac "n" 1); |
5129 | 499 |
by (Auto_tac); |
1485
240cc98b94a7
Added qed_spec_mp to avoid renaming of bound vars in 'th RS spec'
nipkow
parents:
1465
diff
changeset
|
500 |
qed_spec_mp "nth_map"; |
1301 | 501 |
Addsimps [nth_map]; |
502 |
||
4935 | 503 |
Goal "!n. n < length xs --> list_all P xs --> P(xs!n)"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
504 |
by (induct_tac "xs" 1); |
1301 | 505 |
(* case [] *) |
506 |
by (Simp_tac 1); |
|
507 |
(* case x#xl *) |
|
508 |
by (rtac allI 1); |
|
5183 | 509 |
by (induct_tac "n" 1); |
5129 | 510 |
by (Auto_tac); |
1485
240cc98b94a7
Added qed_spec_mp to avoid renaming of bound vars in 'th RS spec'
nipkow
parents:
1465
diff
changeset
|
511 |
qed_spec_mp "list_all_nth"; |
1301 | 512 |
|
4935 | 513 |
Goal "!n. n < length xs --> xs!n mem xs"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
514 |
by (induct_tac "xs" 1); |
1301 | 515 |
(* case [] *) |
516 |
by (Simp_tac 1); |
|
517 |
(* case x#xl *) |
|
518 |
by (rtac allI 1); |
|
5183 | 519 |
by (induct_tac "n" 1); |
1301 | 520 |
(* case 0 *) |
521 |
by (Asm_full_simp_tac 1); |
|
522 |
(* case Suc x *) |
|
4686 | 523 |
by (Asm_full_simp_tac 1); |
1485
240cc98b94a7
Added qed_spec_mp to avoid renaming of bound vars in 'th RS spec'
nipkow
parents:
1465
diff
changeset
|
524 |
qed_spec_mp "nth_mem"; |
1301 | 525 |
Addsimps [nth_mem]; |
526 |
||
5077
71043526295f
* HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents:
5043
diff
changeset
|
527 |
(** list update **) |
71043526295f
* HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents:
5043
diff
changeset
|
528 |
|
71043526295f
* HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents:
5043
diff
changeset
|
529 |
section "list update"; |
71043526295f
* HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents:
5043
diff
changeset
|
530 |
|
71043526295f
* HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents:
5043
diff
changeset
|
531 |
Goal "!i. length(xs[i:=x]) = length xs"; |
71043526295f
* HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents:
5043
diff
changeset
|
532 |
by (induct_tac "xs" 1); |
71043526295f
* HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents:
5043
diff
changeset
|
533 |
by (Simp_tac 1); |
5183 | 534 |
by (asm_full_simp_tac (simpset() addsplits [nat.split]) 1); |
5077
71043526295f
* HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents:
5043
diff
changeset
|
535 |
qed_spec_mp "length_list_update"; |
71043526295f
* HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents:
5043
diff
changeset
|
536 |
Addsimps [length_list_update]; |
71043526295f
* HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents:
5043
diff
changeset
|
537 |
|
71043526295f
* HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents:
5043
diff
changeset
|
538 |
|
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
539 |
(** last & butlast **) |
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
540 |
|
4935 | 541 |
Goal "last(xs@[x]) = x"; |
4423 | 542 |
by (induct_tac "xs" 1); |
5129 | 543 |
by (Auto_tac); |
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
544 |
qed "last_snoc"; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
545 |
Addsimps [last_snoc]; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
546 |
|
4935 | 547 |
Goal "butlast(xs@[x]) = xs"; |
4423 | 548 |
by (induct_tac "xs" 1); |
5129 | 549 |
by (Auto_tac); |
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
550 |
qed "butlast_snoc"; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
551 |
Addsimps [butlast_snoc]; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
552 |
|
4935 | 553 |
Goal "length(butlast xs) = length xs - 1"; |
554 |
by (res_inst_tac [("xs","xs")] rev_induct 1); |
|
5129 | 555 |
by (Auto_tac); |
4643 | 556 |
qed "length_butlast"; |
557 |
Addsimps [length_butlast]; |
|
558 |
||
4935 | 559 |
Goal |
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
560 |
"!ys. butlast (xs@ys) = (if ys=[] then butlast xs else xs@butlast ys)"; |
4423 | 561 |
by (induct_tac "xs" 1); |
5129 | 562 |
by (Auto_tac); |
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
563 |
qed_spec_mp "butlast_append"; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
564 |
|
4935 | 565 |
Goal "x:set(butlast xs) --> x:set xs"; |
4423 | 566 |
by (induct_tac "xs" 1); |
5129 | 567 |
by (Auto_tac); |
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
568 |
qed_spec_mp "in_set_butlastD"; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
569 |
|
5043 | 570 |
Goal "x:set(butlast xs) ==> x:set(butlast(xs@ys))"; |
4686 | 571 |
by (asm_simp_tac (simpset() addsimps [butlast_append]) 1); |
4423 | 572 |
by (blast_tac (claset() addDs [in_set_butlastD]) 1); |
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
573 |
qed "in_set_butlast_appendI1"; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
574 |
|
5043 | 575 |
Goal "x:set(butlast ys) ==> x:set(butlast(xs@ys))"; |
4686 | 576 |
by (asm_simp_tac (simpset() addsimps [butlast_append]) 1); |
4423 | 577 |
by (Clarify_tac 1); |
578 |
by (Full_simp_tac 1); |
|
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
579 |
qed "in_set_butlast_appendI2"; |
3902 | 580 |
|
2608 | 581 |
(** take & drop **) |
582 |
section "take & drop"; |
|
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
583 |
|
4935 | 584 |
Goal "take 0 xs = []"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
585 |
by (induct_tac "xs" 1); |
5129 | 586 |
by (Auto_tac); |
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
587 |
qed "take_0"; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
588 |
|
4935 | 589 |
Goal "drop 0 xs = xs"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
590 |
by (induct_tac "xs" 1); |
5129 | 591 |
by (Auto_tac); |
2608 | 592 |
qed "drop_0"; |
593 |
||
4935 | 594 |
Goal "take (Suc n) (x#xs) = x # take n xs"; |
1552 | 595 |
by (Simp_tac 1); |
1419
a6a034a47a71
defined take/drop by induction over list rather than nat.
nipkow
parents:
1327
diff
changeset
|
596 |
qed "take_Suc_Cons"; |
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
597 |
|
4935 | 598 |
Goal "drop (Suc n) (x#xs) = drop n xs"; |
2608 | 599 |
by (Simp_tac 1); |
600 |
qed "drop_Suc_Cons"; |
|
601 |
||
602 |
Delsimps [take_Cons,drop_Cons]; |
|
603 |
Addsimps [take_0,take_Suc_Cons,drop_0,drop_Suc_Cons]; |
|
604 |
||
4935 | 605 |
Goal "!xs. length(take n xs) = min (length xs) n"; |
5183 | 606 |
by (induct_tac "n" 1); |
5129 | 607 |
by (Auto_tac); |
3457 | 608 |
by (exhaust_tac "xs" 1); |
5129 | 609 |
by (Auto_tac); |
2608 | 610 |
qed_spec_mp "length_take"; |
611 |
Addsimps [length_take]; |
|
923 | 612 |
|
4935 | 613 |
Goal "!xs. length(drop n xs) = (length xs - n)"; |
5183 | 614 |
by (induct_tac "n" 1); |
5129 | 615 |
by (Auto_tac); |
3457 | 616 |
by (exhaust_tac "xs" 1); |
5129 | 617 |
by (Auto_tac); |
2608 | 618 |
qed_spec_mp "length_drop"; |
619 |
Addsimps [length_drop]; |
|
620 |
||
4935 | 621 |
Goal "!xs. length xs <= n --> take n xs = xs"; |
5183 | 622 |
by (induct_tac "n" 1); |
5129 | 623 |
by (Auto_tac); |
3457 | 624 |
by (exhaust_tac "xs" 1); |
5129 | 625 |
by (Auto_tac); |
2608 | 626 |
qed_spec_mp "take_all"; |
923 | 627 |
|
4935 | 628 |
Goal "!xs. length xs <= n --> drop n xs = []"; |
5183 | 629 |
by (induct_tac "n" 1); |
5129 | 630 |
by (Auto_tac); |
3457 | 631 |
by (exhaust_tac "xs" 1); |
5129 | 632 |
by (Auto_tac); |
2608 | 633 |
qed_spec_mp "drop_all"; |
634 |
||
4935 | 635 |
Goal |
2608 | 636 |
"!xs. take n (xs @ ys) = (take n xs @ take (n - length xs) ys)"; |
5183 | 637 |
by (induct_tac "n" 1); |
5129 | 638 |
by (Auto_tac); |
3457 | 639 |
by (exhaust_tac "xs" 1); |
5129 | 640 |
by (Auto_tac); |
2608 | 641 |
qed_spec_mp "take_append"; |
642 |
Addsimps [take_append]; |
|
643 |
||
4935 | 644 |
Goal "!xs. drop n (xs@ys) = drop n xs @ drop (n - length xs) ys"; |
5183 | 645 |
by (induct_tac "n" 1); |
5129 | 646 |
by (Auto_tac); |
3457 | 647 |
by (exhaust_tac "xs" 1); |
5129 | 648 |
by (Auto_tac); |
2608 | 649 |
qed_spec_mp "drop_append"; |
650 |
Addsimps [drop_append]; |
|
651 |
||
4935 | 652 |
Goal "!xs n. take n (take m xs) = take (min n m) xs"; |
5183 | 653 |
by (induct_tac "m" 1); |
5129 | 654 |
by (Auto_tac); |
3457 | 655 |
by (exhaust_tac "xs" 1); |
5129 | 656 |
by (Auto_tac); |
5183 | 657 |
by (exhaust_tac "na" 1); |
5129 | 658 |
by (Auto_tac); |
2608 | 659 |
qed_spec_mp "take_take"; |
660 |
||
4935 | 661 |
Goal "!xs. drop n (drop m xs) = drop (n + m) xs"; |
5183 | 662 |
by (induct_tac "m" 1); |
5129 | 663 |
by (Auto_tac); |
3457 | 664 |
by (exhaust_tac "xs" 1); |
5129 | 665 |
by (Auto_tac); |
2608 | 666 |
qed_spec_mp "drop_drop"; |
923 | 667 |
|
4935 | 668 |
Goal "!xs n. take n (drop m xs) = drop m (take (n + m) xs)"; |
5183 | 669 |
by (induct_tac "m" 1); |
5129 | 670 |
by (Auto_tac); |
3457 | 671 |
by (exhaust_tac "xs" 1); |
5129 | 672 |
by (Auto_tac); |
2608 | 673 |
qed_spec_mp "take_drop"; |
674 |
||
4935 | 675 |
Goal "!xs. take n (map f xs) = map f (take n xs)"; |
5183 | 676 |
by (induct_tac "n" 1); |
5129 | 677 |
by (Auto_tac); |
3457 | 678 |
by (exhaust_tac "xs" 1); |
5129 | 679 |
by (Auto_tac); |
2608 | 680 |
qed_spec_mp "take_map"; |
681 |
||
4935 | 682 |
Goal "!xs. drop n (map f xs) = map f (drop n xs)"; |
5183 | 683 |
by (induct_tac "n" 1); |
5129 | 684 |
by (Auto_tac); |
3457 | 685 |
by (exhaust_tac "xs" 1); |
5129 | 686 |
by (Auto_tac); |
2608 | 687 |
qed_spec_mp "drop_map"; |
688 |
||
4935 | 689 |
Goal "!n i. i < n --> (take n xs)!i = xs!i"; |
3457 | 690 |
by (induct_tac "xs" 1); |
5129 | 691 |
by (Auto_tac); |
3457 | 692 |
by (exhaust_tac "n" 1); |
693 |
by (Blast_tac 1); |
|
694 |
by (exhaust_tac "i" 1); |
|
5129 | 695 |
by (Auto_tac); |
2608 | 696 |
qed_spec_mp "nth_take"; |
697 |
Addsimps [nth_take]; |
|
923 | 698 |
|
4935 | 699 |
Goal "!xs i. n + i <= length xs --> (drop n xs)!i = xs!(n+i)"; |
5183 | 700 |
by (induct_tac "n" 1); |
5129 | 701 |
by (Auto_tac); |
3457 | 702 |
by (exhaust_tac "xs" 1); |
5129 | 703 |
by (Auto_tac); |
2608 | 704 |
qed_spec_mp "nth_drop"; |
705 |
Addsimps [nth_drop]; |
|
706 |
||
707 |
(** takeWhile & dropWhile **) |
|
708 |
||
3467 | 709 |
section "takeWhile & dropWhile"; |
710 |
||
4935 | 711 |
Goal "takeWhile P xs @ dropWhile P xs = xs"; |
3586 | 712 |
by (induct_tac "xs" 1); |
5129 | 713 |
by (Auto_tac); |
3586 | 714 |
qed "takeWhile_dropWhile_id"; |
715 |
Addsimps [takeWhile_dropWhile_id]; |
|
716 |
||
4935 | 717 |
Goal "x:set xs & ~P(x) --> takeWhile P (xs @ ys) = takeWhile P xs"; |
3457 | 718 |
by (induct_tac "xs" 1); |
5129 | 719 |
by (Auto_tac); |
2608 | 720 |
bind_thm("takeWhile_append1", conjI RS (result() RS mp)); |
721 |
Addsimps [takeWhile_append1]; |
|
923 | 722 |
|
4935 | 723 |
Goal "(!x:set xs. P(x)) --> takeWhile P (xs @ ys) = xs @ takeWhile P ys"; |
3457 | 724 |
by (induct_tac "xs" 1); |
5129 | 725 |
by (Auto_tac); |
2608 | 726 |
bind_thm("takeWhile_append2", ballI RS (result() RS mp)); |
727 |
Addsimps [takeWhile_append2]; |
|
1169 | 728 |
|
4935 | 729 |
Goal "x:set xs & ~P(x) --> dropWhile P (xs @ ys) = (dropWhile P xs)@ys"; |
3457 | 730 |
by (induct_tac "xs" 1); |
5129 | 731 |
by (Auto_tac); |
2608 | 732 |
bind_thm("dropWhile_append1", conjI RS (result() RS mp)); |
733 |
Addsimps [dropWhile_append1]; |
|
734 |
||
4935 | 735 |
Goal "(!x:set xs. P(x)) --> dropWhile P (xs @ ys) = dropWhile P ys"; |
3457 | 736 |
by (induct_tac "xs" 1); |
5129 | 737 |
by (Auto_tac); |
2608 | 738 |
bind_thm("dropWhile_append2", ballI RS (result() RS mp)); |
739 |
Addsimps [dropWhile_append2]; |
|
740 |
||
4935 | 741 |
Goal "x:set(takeWhile P xs) --> x:set xs & P x"; |
3457 | 742 |
by (induct_tac "xs" 1); |
5129 | 743 |
by (Auto_tac); |
3647
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
744 |
qed_spec_mp"set_take_whileD"; |
2608 | 745 |
|
4132 | 746 |
qed_goal "zip_Nil_Nil" thy "zip [] [] = []" (K [Simp_tac 1]); |
747 |
qed_goal "zip_Cons_Cons" thy "zip (x#xs) (y#ys) = (x,y)#zip xs ys" |
|
748 |
(K [Simp_tac 1]); |
|
4605 | 749 |
|
750 |
(** nodups & remdups **) |
|
751 |
section "nodups & remdups"; |
|
752 |
||
4935 | 753 |
Goal "set(remdups xs) = set xs"; |
4605 | 754 |
by (induct_tac "xs" 1); |
755 |
by (Simp_tac 1); |
|
4686 | 756 |
by (asm_full_simp_tac (simpset() addsimps [insert_absorb]) 1); |
4605 | 757 |
qed "set_remdups"; |
758 |
Addsimps [set_remdups]; |
|
759 |
||
4935 | 760 |
Goal "nodups(remdups xs)"; |
4605 | 761 |
by (induct_tac "xs" 1); |
5129 | 762 |
by (Auto_tac); |
4605 | 763 |
qed "nodups_remdups"; |
764 |
||
4935 | 765 |
Goal "nodups xs --> nodups (filter P xs)"; |
4605 | 766 |
by (induct_tac "xs" 1); |
5129 | 767 |
by (Auto_tac); |
4605 | 768 |
qed_spec_mp "nodups_filter"; |
769 |
||
3589
244daa75f890
Added function `replicate' and lemmas map_cong and set_replicate.
nipkow
parents:
3586
diff
changeset
|
770 |
(** replicate **) |
244daa75f890
Added function `replicate' and lemmas map_cong and set_replicate.
nipkow
parents:
3586
diff
changeset
|
771 |
section "replicate"; |
244daa75f890
Added function `replicate' and lemmas map_cong and set_replicate.
nipkow
parents:
3586
diff
changeset
|
772 |
|
4935 | 773 |
Goal "set(replicate (Suc n) x) = {x}"; |
4423 | 774 |
by (induct_tac "n" 1); |
5129 | 775 |
by (Auto_tac); |
3589
244daa75f890
Added function `replicate' and lemmas map_cong and set_replicate.
nipkow
parents:
3586
diff
changeset
|
776 |
val lemma = result(); |
244daa75f890
Added function `replicate' and lemmas map_cong and set_replicate.
nipkow
parents:
3586
diff
changeset
|
777 |
|
5043 | 778 |
Goal "n ~= 0 ==> set(replicate n x) = {x}"; |
4423 | 779 |
by (fast_tac (claset() addSDs [not0_implies_Suc] addSIs [lemma]) 1); |
3589
244daa75f890
Added function `replicate' and lemmas map_cong and set_replicate.
nipkow
parents:
3586
diff
changeset
|
780 |
qed "set_replicate"; |
244daa75f890
Added function `replicate' and lemmas map_cong and set_replicate.
nipkow
parents:
3586
diff
changeset
|
781 |
Addsimps [set_replicate]; |
5162 | 782 |
|
783 |
||
784 |
(*** |
|
785 |
Simplification procedure for all list equalities. |
|
786 |
Currently only tries to rearranges @ to see if |
|
787 |
- both lists end in a singleton list, |
|
788 |
- or both lists end in the same list. |
|
789 |
***) |
|
790 |
local |
|
791 |
||
792 |
val list_eq_pattern = |
|
793 |
read_cterm (sign_of List.thy) ("(xs::'a list) = ys",HOLogic.boolT); |
|
794 |
||
5183 | 795 |
fun last (cons as Const("List.list.op #",_) $ _ $ xs) = |
796 |
(case xs of Const("List.list.[]",_) => cons | _ => last xs) |
|
5200 | 797 |
| last (Const("List.op @",_) $ _ $ ys) = last ys |
5162 | 798 |
| last t = t; |
799 |
||
5183 | 800 |
fun list1 (Const("List.list.op #",_) $ _ $ Const("List.list.[]",_)) = true |
5162 | 801 |
| list1 _ = false; |
802 |
||
5183 | 803 |
fun butlast ((cons as Const("List.list.op #",_) $ x) $ xs) = |
804 |
(case xs of Const("List.list.[]",_) => xs | _ => cons $ butlast xs) |
|
5200 | 805 |
| butlast ((app as Const("List.op @",_) $ xs) $ ys) = app $ butlast ys |
5183 | 806 |
| butlast xs = Const("List.list.[]",fastype_of xs); |
5162 | 807 |
|
808 |
val rearr_tac = |
|
809 |
simp_tac (HOL_basic_ss addsimps [append_assoc,append_Nil,append_Cons]); |
|
810 |
||
811 |
fun list_eq sg _ (F as (eq as Const(_,eqT)) $ lhs $ rhs) = |
|
812 |
let |
|
813 |
val lastl = last lhs and lastr = last rhs |
|
814 |
fun rearr conv = |
|
815 |
let val lhs1 = butlast lhs and rhs1 = butlast rhs |
|
816 |
val Type(_,listT::_) = eqT |
|
817 |
val appT = [listT,listT] ---> listT |
|
5200 | 818 |
val app = Const("List.op @",appT) |
5162 | 819 |
val F2 = eq $ (app$lhs1$lastl) $ (app$rhs1$lastr) |
820 |
val ct = cterm_of sg (HOLogic.mk_Trueprop(HOLogic.mk_eq(F,F2))) |
|
821 |
val thm = prove_goalw_cterm [] ct (K [rearr_tac 1]) |
|
822 |
handle ERROR => |
|
823 |
error("The error(s) above occurred while trying to prove " ^ |
|
824 |
string_of_cterm ct) |
|
825 |
in Some((conv RS (thm RS trans)) RS eq_reflection) end |
|
826 |
||
827 |
in if list1 lastl andalso list1 lastr |
|
828 |
then rearr append1_eq_conv |
|
829 |
else |
|
830 |
if lastl aconv lastr |
|
831 |
then rearr append_same_eq |
|
832 |
else None |
|
833 |
end; |
|
834 |
in |
|
835 |
val list_eq_simproc = mk_simproc "list_eq" [list_eq_pattern] list_eq; |
|
836 |
end; |
|
837 |
||
838 |
Addsimprocs [list_eq_simproc]; |