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