author | nipkow |
Wed, 12 Feb 1997 18:53:59 +0100 | |
changeset 2608 | 450c9b682a92 |
parent 2512 | 0231e4f467f2 |
child 2739 | 5481b1c73d84 |
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 |
||
9 |
open List; |
|
10 |
||
1985
84cf16192e03
Tidied many proofs, using AddIffs to let equivalences take
paulson
parents:
1936
diff
changeset
|
11 |
AddIffs list.distinct; |
84cf16192e03
Tidied many proofs, using AddIffs to let equivalences take
paulson
parents:
1936
diff
changeset
|
12 |
AddIffs list.inject; |
923 | 13 |
|
14 |
bind_thm("Cons_inject", (hd list.inject) RS iffD1 RS conjE); |
|
15 |
||
16 |
goal List.thy "!x. xs ~= x#xs"; |
|
17 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
18 |
by (ALLGOALS Asm_simp_tac); |
2608 | 19 |
qed_spec_mp "not_Cons_self"; |
2512 | 20 |
Addsimps [not_Cons_self]; |
923 | 21 |
|
22 |
goal List.thy "(xs ~= []) = (? y ys. xs = y#ys)"; |
|
23 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
24 |
by (Simp_tac 1); |
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
25 |
by (Asm_simp_tac 1); |
1169 | 26 |
by (REPEAT(resolve_tac [exI,refl,conjI] 1)); |
923 | 27 |
qed "neq_Nil_conv"; |
28 |
||
29 |
||
2608 | 30 |
(** list_case **) |
31 |
||
32 |
goal List.thy |
|
33 |
"P(list_case a f xs) = ((xs=[] --> P(a)) & \ |
|
34 |
\ (!y ys. xs=y#ys --> P(f y ys)))"; |
|
35 |
by (list.induct_tac "xs" 1); |
|
36 |
by (ALLGOALS Asm_simp_tac); |
|
37 |
by (Fast_tac 1); |
|
38 |
qed "expand_list_case"; |
|
39 |
||
40 |
val prems = goal List.thy "[| P([]); !!x xs. P(x#xs) |] ==> P(xs)"; |
|
41 |
by(list.induct_tac "xs" 1); |
|
42 |
by(REPEAT(resolve_tac prems 1)); |
|
43 |
qed "list_cases"; |
|
44 |
||
45 |
goal List.thy "(xs=[] --> P([])) & (!y ys. xs=y#ys --> P(y#ys)) --> P(xs)"; |
|
46 |
by (list.induct_tac "xs" 1); |
|
47 |
by (Fast_tac 1); |
|
48 |
by (Fast_tac 1); |
|
49 |
bind_thm("list_eq_cases", |
|
50 |
impI RSN (2,allI RSN (2,allI RSN (2,impI RS (conjI RS (result() RS mp)))))); |
|
51 |
||
52 |
||
923 | 53 |
(** @ - append **) |
54 |
||
55 |
goal List.thy "(xs@ys)@zs = xs@(ys@zs)"; |
|
56 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
57 |
by (ALLGOALS Asm_simp_tac); |
923 | 58 |
qed "append_assoc"; |
2512 | 59 |
Addsimps [append_assoc]; |
923 | 60 |
|
61 |
goal List.thy "xs @ [] = xs"; |
|
62 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
63 |
by (ALLGOALS Asm_simp_tac); |
923 | 64 |
qed "append_Nil2"; |
2512 | 65 |
Addsimps [append_Nil2]; |
923 | 66 |
|
67 |
goal List.thy "(xs@ys = []) = (xs=[] & ys=[])"; |
|
68 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
69 |
by (ALLGOALS Asm_simp_tac); |
2608 | 70 |
qed "append_is_Nil_conv"; |
71 |
AddIffs [append_is_Nil_conv]; |
|
72 |
||
73 |
goal List.thy "([] = xs@ys) = (xs=[] & ys=[])"; |
|
74 |
by (list.induct_tac "xs" 1); |
|
75 |
by (ALLGOALS Asm_simp_tac); |
|
76 |
by(Fast_tac 1); |
|
77 |
qed "Nil_is_append_conv"; |
|
78 |
AddIffs [Nil_is_append_conv]; |
|
923 | 79 |
|
80 |
goal List.thy "(xs @ ys = xs @ zs) = (ys=zs)"; |
|
81 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
82 |
by (ALLGOALS Asm_simp_tac); |
923 | 83 |
qed "same_append_eq"; |
2608 | 84 |
AddIffs [same_append_eq]; |
85 |
||
86 |
goal List.thy "!ys. (xs @ [x] = ys @ [y]) = (xs = ys & x = y)"; |
|
87 |
by(list.induct_tac "xs" 1); |
|
88 |
br allI 1; |
|
89 |
by(list.induct_tac "ys" 1); |
|
90 |
by(ALLGOALS Asm_simp_tac); |
|
91 |
br allI 1; |
|
92 |
by(list.induct_tac "ys" 1); |
|
93 |
by(ALLGOALS Asm_simp_tac); |
|
94 |
qed_spec_mp "append1_eq_conv"; |
|
95 |
AddIffs [append1_eq_conv]; |
|
96 |
||
97 |
goal List.thy "xs ~= [] --> hd xs # tl xs = xs"; |
|
98 |
by(list.induct_tac "xs" 1); |
|
99 |
by(ALLGOALS Asm_simp_tac); |
|
100 |
qed_spec_mp "hd_Cons_tl"; |
|
101 |
Addsimps [hd_Cons_tl]; |
|
923 | 102 |
|
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
103 |
goal List.thy "hd(xs@ys) = (if xs=[] then hd ys else hd xs)"; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
104 |
by (list.induct_tac "xs" 1); |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
105 |
by (ALLGOALS Asm_simp_tac); |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
106 |
qed "hd_append"; |
923 | 107 |
|
2608 | 108 |
goal List.thy "tl(xs@ys) = (case xs of [] => tl(ys) | z#zs => zs@ys)"; |
109 |
by(simp_tac (!simpset setloop(split_tac[expand_list_case])) 1); |
|
110 |
qed "tl_append"; |
|
111 |
||
112 |
(** map **) |
|
113 |
||
114 |
goal List.thy |
|
115 |
"(!x. x : set_of_list xs --> f x = g x) --> map f xs = map g xs"; |
|
116 |
by(list.induct_tac "xs" 1); |
|
117 |
by(ALLGOALS Asm_simp_tac); |
|
118 |
bind_thm("map_ext", impI RS (allI RS (result() RS mp))); |
|
119 |
||
120 |
goal List.thy "map (%x.x) = (%xs.xs)"; |
|
121 |
by (rtac ext 1); |
|
122 |
by (list.induct_tac "xs" 1); |
|
123 |
by (ALLGOALS Asm_simp_tac); |
|
124 |
qed "map_ident"; |
|
125 |
Addsimps[map_ident]; |
|
126 |
||
127 |
goal List.thy "map f (xs@ys) = map f xs @ map f ys"; |
|
128 |
by (list.induct_tac "xs" 1); |
|
129 |
by (ALLGOALS Asm_simp_tac); |
|
130 |
qed "map_append"; |
|
131 |
Addsimps[map_append]; |
|
132 |
||
133 |
goalw List.thy [o_def] "map (f o g) xs = map f (map g xs)"; |
|
134 |
by (list.induct_tac "xs" 1); |
|
135 |
by (ALLGOALS Asm_simp_tac); |
|
136 |
qed "map_compose"; |
|
137 |
Addsimps[map_compose]; |
|
138 |
||
139 |
goal List.thy "rev(map f xs) = map f (rev xs)"; |
|
140 |
by (list.induct_tac "xs" 1); |
|
141 |
by (ALLGOALS Asm_simp_tac); |
|
142 |
qed "rev_map"; |
|
143 |
||
1169 | 144 |
(** rev **) |
145 |
||
146 |
goal List.thy "rev(xs@ys) = rev(ys) @ rev(xs)"; |
|
147 |
by (list.induct_tac "xs" 1); |
|
2512 | 148 |
by (ALLGOALS Asm_simp_tac); |
1169 | 149 |
qed "rev_append"; |
2512 | 150 |
Addsimps[rev_append]; |
1169 | 151 |
|
152 |
goal List.thy "rev(rev l) = l"; |
|
153 |
by (list.induct_tac "l" 1); |
|
2512 | 154 |
by (ALLGOALS Asm_simp_tac); |
1169 | 155 |
qed "rev_rev_ident"; |
2512 | 156 |
Addsimps[rev_rev_ident]; |
1169 | 157 |
|
2608 | 158 |
|
923 | 159 |
(** mem **) |
160 |
||
161 |
goal List.thy "x mem (xs@ys) = (x mem xs | x mem ys)"; |
|
162 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
163 |
by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if])))); |
923 | 164 |
qed "mem_append"; |
2512 | 165 |
Addsimps[mem_append]; |
923 | 166 |
|
167 |
goal List.thy "x mem [x:xs.P(x)] = (x mem xs & P(x))"; |
|
168 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
169 |
by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if])))); |
923 | 170 |
qed "mem_filter"; |
2512 | 171 |
Addsimps[mem_filter]; |
923 | 172 |
|
1908 | 173 |
(** set_of_list **) |
1812 | 174 |
|
1908 | 175 |
goal thy "set_of_list (xs@ys) = (set_of_list xs Un set_of_list ys)"; |
1812 | 176 |
by (list.induct_tac "xs" 1); |
177 |
by (ALLGOALS Asm_simp_tac); |
|
178 |
by (Fast_tac 1); |
|
1908 | 179 |
qed "set_of_list_append"; |
2512 | 180 |
Addsimps[set_of_list_append]; |
1812 | 181 |
|
1908 | 182 |
goal thy "(x mem xs) = (x: set_of_list xs)"; |
1812 | 183 |
by (list.induct_tac "xs" 1); |
184 |
by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if])))); |
|
185 |
by (Fast_tac 1); |
|
1908 | 186 |
qed "set_of_list_mem_eq"; |
1812 | 187 |
|
1936 | 188 |
goal List.thy "set_of_list l <= set_of_list (x#l)"; |
189 |
by (Simp_tac 1); |
|
190 |
by (Fast_tac 1); |
|
191 |
qed "set_of_list_subset_Cons"; |
|
192 |
||
2608 | 193 |
goal List.thy "(set_of_list xs = {}) = (xs = [])"; |
194 |
by(list.induct_tac "xs" 1); |
|
195 |
by(ALLGOALS Asm_simp_tac); |
|
196 |
qed "set_of_list_empty"; |
|
197 |
Addsimps [set_of_list_empty]; |
|
198 |
||
199 |
goal List.thy "set_of_list(rev xs) = set_of_list(xs)"; |
|
200 |
by(list.induct_tac "xs" 1); |
|
201 |
by(ALLGOALS Asm_simp_tac); |
|
202 |
by(Fast_tac 1); |
|
203 |
qed "set_of_list_rev"; |
|
204 |
Addsimps [set_of_list_rev]; |
|
205 |
||
206 |
goal List.thy "set_of_list(map f xs) = f``(set_of_list xs)"; |
|
207 |
by(list.induct_tac "xs" 1); |
|
208 |
by(ALLGOALS Asm_simp_tac); |
|
209 |
qed "set_of_list_map"; |
|
210 |
Addsimps [set_of_list_map]; |
|
211 |
||
1812 | 212 |
|
923 | 213 |
(** list_all **) |
214 |
||
2512 | 215 |
goal List.thy "list_all (%x.True) xs = True"; |
923 | 216 |
by (list.induct_tac "xs" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
217 |
by (ALLGOALS Asm_simp_tac); |
923 | 218 |
qed "list_all_True"; |
2512 | 219 |
Addsimps [list_all_True]; |
923 | 220 |
|
221 |
goal List.thy "list_all p (xs@ys) = (list_all p xs & list_all p ys)"; |
|
222 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
223 |
by (ALLGOALS Asm_simp_tac); |
2512 | 224 |
qed "list_all_append"; |
225 |
Addsimps [list_all_append]; |
|
923 | 226 |
|
2512 | 227 |
goal List.thy "list_all P xs = (!x. x mem xs --> P(x))"; |
923 | 228 |
by (list.induct_tac "xs" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
229 |
by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if])))); |
1760
6f41a494f3b1
Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents:
1552
diff
changeset
|
230 |
by (Fast_tac 1); |
923 | 231 |
qed "list_all_mem_conv"; |
232 |
||
233 |
||
2608 | 234 |
(** filter **) |
923 | 235 |
|
2608 | 236 |
goal List.thy "[x:xs@ys . P] = [x:xs . P] @ [y:ys . P]"; |
237 |
by(list.induct_tac "xs" 1); |
|
238 |
by(ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if])))); |
|
239 |
qed "filter_append"; |
|
240 |
Addsimps [filter_append]; |
|
241 |
||
242 |
||
243 |
(** concat **) |
|
244 |
||
245 |
goal List.thy "concat(xs@ys) = concat(xs)@concat(ys)"; |
|
923 | 246 |
by (list.induct_tac "xs" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
247 |
by (ALLGOALS Asm_simp_tac); |
2608 | 248 |
qed"concat_append"; |
249 |
Addsimps [concat_append]; |
|
2512 | 250 |
|
2608 | 251 |
goal List.thy "rev(concat ls) = concat (map rev (rev ls))"; |
252 |
by (list.induct_tac "ls" 1); |
|
2512 | 253 |
by (ALLGOALS Asm_simp_tac); |
2608 | 254 |
qed "rev_concat"; |
923 | 255 |
|
962 | 256 |
(** length **) |
257 |
||
258 |
goal List.thy "length(xs@ys) = length(xs)+length(ys)"; |
|
259 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
260 |
by (ALLGOALS Asm_simp_tac); |
962 | 261 |
qed"length_append"; |
1301 | 262 |
Addsimps [length_append]; |
263 |
||
264 |
goal List.thy "length (map f l) = length l"; |
|
265 |
by (list.induct_tac "l" 1); |
|
266 |
by (ALLGOALS Simp_tac); |
|
267 |
qed "length_map"; |
|
268 |
Addsimps [length_map]; |
|
962 | 269 |
|
1169 | 270 |
goal List.thy "length(rev xs) = length(xs)"; |
271 |
by (list.induct_tac "xs" 1); |
|
1301 | 272 |
by (ALLGOALS Asm_simp_tac); |
1169 | 273 |
qed "length_rev"; |
1301 | 274 |
Addsimps [length_rev]; |
1169 | 275 |
|
2608 | 276 |
goal List.thy "(length xs = 0) = (xs = [])"; |
277 |
by(list.induct_tac "xs" 1); |
|
278 |
by(ALLGOALS Asm_simp_tac); |
|
279 |
qed "length_0_conv"; |
|
280 |
AddIffs [length_0_conv]; |
|
281 |
||
282 |
goal List.thy "(0 < length xs) = (xs ~= [])"; |
|
283 |
by(list.induct_tac "xs" 1); |
|
284 |
by(ALLGOALS Asm_simp_tac); |
|
285 |
qed "length_greater_0_conv"; |
|
286 |
AddIffs [length_greater_0_conv]; |
|
287 |
||
288 |
||
923 | 289 |
(** nth **) |
290 |
||
291 |
val [nth_0,nth_Suc] = nat_recs nth_def; |
|
292 |
store_thm("nth_0",nth_0); |
|
293 |
store_thm("nth_Suc",nth_Suc); |
|
1301 | 294 |
Addsimps [nth_0,nth_Suc]; |
295 |
||
2608 | 296 |
goal List.thy |
297 |
"!xs. nth n (xs@ys) = \ |
|
298 |
\ (if n < length xs then nth n xs else nth (n - length xs) ys)"; |
|
299 |
by(nat_ind_tac "n" 1); |
|
300 |
by(Asm_simp_tac 1); |
|
301 |
br allI 1; |
|
302 |
by(res_inst_tac [("xs","xs")]list_cases 1); |
|
303 |
by(ALLGOALS Asm_simp_tac); |
|
304 |
br allI 1; |
|
305 |
by(res_inst_tac [("xs","xs")]list_cases 1); |
|
306 |
by(ALLGOALS Asm_simp_tac); |
|
307 |
qed_spec_mp "nth_append"; |
|
308 |
||
1301 | 309 |
goal List.thy "!n. n < length xs --> nth n (map f xs) = f (nth n xs)"; |
310 |
by (list.induct_tac "xs" 1); |
|
311 |
(* case [] *) |
|
312 |
by (Asm_full_simp_tac 1); |
|
313 |
(* case x#xl *) |
|
314 |
by (rtac allI 1); |
|
315 |
by (nat_ind_tac "n" 1); |
|
316 |
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
|
317 |
qed_spec_mp "nth_map"; |
1301 | 318 |
Addsimps [nth_map]; |
319 |
||
320 |
goal List.thy "!n. n < length xs --> list_all P xs --> P(nth n xs)"; |
|
321 |
by (list.induct_tac "xs" 1); |
|
322 |
(* case [] *) |
|
323 |
by (Simp_tac 1); |
|
324 |
(* case x#xl *) |
|
325 |
by (rtac allI 1); |
|
326 |
by (nat_ind_tac "n" 1); |
|
327 |
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
|
328 |
qed_spec_mp "list_all_nth"; |
1301 | 329 |
|
330 |
goal List.thy "!n. n < length xs --> (nth n xs) mem xs"; |
|
331 |
by (list.induct_tac "xs" 1); |
|
332 |
(* case [] *) |
|
333 |
by (Simp_tac 1); |
|
334 |
(* case x#xl *) |
|
335 |
by (rtac allI 1); |
|
336 |
by (nat_ind_tac "n" 1); |
|
337 |
(* case 0 *) |
|
338 |
by (Asm_full_simp_tac 1); |
|
339 |
(* case Suc x *) |
|
340 |
by (asm_full_simp_tac (!simpset setloop (split_tac [expand_if])) 1); |
|
1485
240cc98b94a7
Added qed_spec_mp to avoid renaming of bound vars in 'th RS spec'
nipkow
parents:
1465
diff
changeset
|
341 |
qed_spec_mp "nth_mem"; |
1301 | 342 |
Addsimps [nth_mem]; |
343 |
||
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
344 |
|
2608 | 345 |
(** take & drop **) |
346 |
section "take & drop"; |
|
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
347 |
|
1419
a6a034a47a71
defined take/drop by induction over list rather than nat.
nipkow
parents:
1327
diff
changeset
|
348 |
goal thy "take 0 xs = []"; |
a6a034a47a71
defined take/drop by induction over list rather than nat.
nipkow
parents:
1327
diff
changeset
|
349 |
by (list.induct_tac "xs" 1); |
a6a034a47a71
defined take/drop by induction over list rather than nat.
nipkow
parents:
1327
diff
changeset
|
350 |
by (ALLGOALS Asm_simp_tac); |
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
351 |
qed "take_0"; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
352 |
|
2608 | 353 |
goal thy "drop 0 xs = xs"; |
354 |
by (list.induct_tac "xs" 1); |
|
355 |
by (ALLGOALS Asm_simp_tac); |
|
356 |
qed "drop_0"; |
|
357 |
||
1419
a6a034a47a71
defined take/drop by induction over list rather than nat.
nipkow
parents:
1327
diff
changeset
|
358 |
goal thy "take (Suc n) (x#xs) = x # take n xs"; |
1552 | 359 |
by (Simp_tac 1); |
1419
a6a034a47a71
defined take/drop by induction over list rather than nat.
nipkow
parents:
1327
diff
changeset
|
360 |
qed "take_Suc_Cons"; |
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
361 |
|
2608 | 362 |
goal thy "drop (Suc n) (x#xs) = drop n xs"; |
363 |
by (Simp_tac 1); |
|
364 |
qed "drop_Suc_Cons"; |
|
365 |
||
366 |
Delsimps [take_Cons,drop_Cons]; |
|
367 |
Addsimps [take_0,take_Suc_Cons,drop_0,drop_Suc_Cons]; |
|
368 |
||
369 |
goal List.thy "!xs. length(take n xs) = min (length xs) n"; |
|
370 |
by(nat_ind_tac "n" 1); |
|
371 |
by(ALLGOALS Asm_simp_tac); |
|
372 |
br allI 1; |
|
373 |
by(res_inst_tac [("xs","xs")]list_cases 1); |
|
374 |
by(ALLGOALS Asm_simp_tac); |
|
375 |
qed_spec_mp "length_take"; |
|
376 |
Addsimps [length_take]; |
|
923 | 377 |
|
2608 | 378 |
goal List.thy "!xs. length(drop n xs) = (length xs - n)"; |
379 |
by(nat_ind_tac "n" 1); |
|
380 |
by(ALLGOALS Asm_simp_tac); |
|
381 |
br allI 1; |
|
382 |
by(res_inst_tac [("xs","xs")]list_cases 1); |
|
383 |
by(ALLGOALS Asm_simp_tac); |
|
384 |
qed_spec_mp "length_drop"; |
|
385 |
Addsimps [length_drop]; |
|
386 |
||
387 |
goal List.thy "!xs. length xs <= n --> take n xs = xs"; |
|
388 |
by(nat_ind_tac "n" 1); |
|
389 |
by(ALLGOALS Asm_simp_tac); |
|
390 |
br allI 1; |
|
391 |
by(res_inst_tac [("xs","xs")]list_cases 1); |
|
392 |
by(ALLGOALS Asm_simp_tac); |
|
393 |
qed_spec_mp "take_all"; |
|
923 | 394 |
|
2608 | 395 |
goal List.thy "!xs. length xs <= n --> drop n xs = []"; |
396 |
by(nat_ind_tac "n" 1); |
|
397 |
by(ALLGOALS Asm_simp_tac); |
|
398 |
br allI 1; |
|
399 |
by(res_inst_tac [("xs","xs")]list_cases 1); |
|
400 |
by(ALLGOALS Asm_simp_tac); |
|
401 |
qed_spec_mp "drop_all"; |
|
402 |
||
403 |
goal List.thy |
|
404 |
"!xs. take n (xs @ ys) = (take n xs @ take (n - length xs) ys)"; |
|
405 |
by(nat_ind_tac "n" 1); |
|
406 |
by(ALLGOALS Asm_simp_tac); |
|
407 |
br allI 1; |
|
408 |
by(res_inst_tac [("xs","xs")]list_cases 1); |
|
409 |
by(ALLGOALS Asm_simp_tac); |
|
410 |
qed_spec_mp "take_append"; |
|
411 |
Addsimps [take_append]; |
|
412 |
||
413 |
goal List.thy "!xs. drop n (xs@ys) = drop n xs @ drop (n - length xs) ys"; |
|
414 |
by(nat_ind_tac "n" 1); |
|
415 |
by(ALLGOALS Asm_simp_tac); |
|
416 |
br allI 1; |
|
417 |
by(res_inst_tac [("xs","xs")]list_cases 1); |
|
418 |
by(ALLGOALS Asm_simp_tac); |
|
419 |
qed_spec_mp "drop_append"; |
|
420 |
Addsimps [drop_append]; |
|
421 |
||
422 |
goal List.thy "!xs n. take n (take m xs) = take (min n m) xs"; |
|
423 |
by(nat_ind_tac "m" 1); |
|
424 |
by(ALLGOALS Asm_simp_tac); |
|
425 |
br allI 1; |
|
426 |
by(res_inst_tac [("xs","xs")]list_cases 1); |
|
427 |
by(ALLGOALS Asm_simp_tac); |
|
428 |
br allI 1; |
|
429 |
by(res_inst_tac [("n","n")]natE 1); |
|
430 |
by(ALLGOALS Asm_simp_tac); |
|
431 |
qed_spec_mp "take_take"; |
|
432 |
||
433 |
goal List.thy "!xs. drop n (drop m xs) = drop (n + m) xs"; |
|
434 |
by(nat_ind_tac "m" 1); |
|
435 |
by(ALLGOALS Asm_simp_tac); |
|
436 |
br allI 1; |
|
437 |
by(res_inst_tac [("xs","xs")]list_cases 1); |
|
438 |
by(ALLGOALS Asm_simp_tac); |
|
439 |
qed_spec_mp "drop_drop"; |
|
923 | 440 |
|
2608 | 441 |
goal List.thy "!xs n. take n (drop m xs) = drop m (take (n + m) xs)"; |
442 |
by(nat_ind_tac "m" 1); |
|
443 |
by(ALLGOALS Asm_simp_tac); |
|
444 |
br allI 1; |
|
445 |
by(res_inst_tac [("xs","xs")]list_cases 1); |
|
446 |
by(ALLGOALS Asm_simp_tac); |
|
447 |
qed_spec_mp "take_drop"; |
|
448 |
||
449 |
goal List.thy "!xs. take n (map f xs) = map f (take n xs)"; |
|
450 |
by(nat_ind_tac "n" 1); |
|
451 |
by(ALLGOALS Asm_simp_tac); |
|
452 |
br allI 1; |
|
453 |
by(res_inst_tac [("xs","xs")]list_cases 1); |
|
454 |
by(ALLGOALS Asm_simp_tac); |
|
455 |
qed_spec_mp "take_map"; |
|
456 |
||
457 |
goal List.thy "!xs. drop n (map f xs) = map f (drop n xs)"; |
|
458 |
by(nat_ind_tac "n" 1); |
|
459 |
by(ALLGOALS Asm_simp_tac); |
|
460 |
br allI 1; |
|
461 |
by(res_inst_tac [("xs","xs")]list_cases 1); |
|
462 |
by(ALLGOALS Asm_simp_tac); |
|
463 |
qed_spec_mp "drop_map"; |
|
464 |
||
465 |
goal List.thy |
|
466 |
"!n i. i < n --> nth i (take n xs) = nth i xs"; |
|
467 |
by(list.induct_tac "xs" 1); |
|
468 |
by(ALLGOALS Asm_simp_tac); |
|
469 |
by(strip_tac 1); |
|
470 |
by(res_inst_tac [("n","n")] natE 1); |
|
471 |
by(Fast_tac 1); |
|
472 |
by(res_inst_tac [("n","i")] natE 1); |
|
473 |
by(ALLGOALS (hyp_subst_tac THEN' Asm_full_simp_tac)); |
|
474 |
qed_spec_mp "nth_take"; |
|
475 |
Addsimps [nth_take]; |
|
923 | 476 |
|
2608 | 477 |
goal List.thy |
478 |
"!xs i. n + i < length xs --> nth i (drop n xs) = nth (n + i) xs"; |
|
479 |
by(nat_ind_tac "n" 1); |
|
480 |
by(ALLGOALS Asm_simp_tac); |
|
481 |
br allI 1; |
|
482 |
by(res_inst_tac [("xs","xs")]list_cases 1); |
|
483 |
by(ALLGOALS Asm_simp_tac); |
|
484 |
qed_spec_mp "nth_drop"; |
|
485 |
Addsimps [nth_drop]; |
|
486 |
||
487 |
(** takeWhile & dropWhile **) |
|
488 |
||
489 |
goal List.thy |
|
490 |
"x:set_of_list xs & ~P(x) --> takeWhile P (xs @ ys) = takeWhile P xs"; |
|
491 |
by(list.induct_tac "xs" 1); |
|
492 |
by(Simp_tac 1); |
|
493 |
by(asm_full_simp_tac (!simpset setloop (split_tac[expand_if])) 1); |
|
494 |
by(Fast_tac 1); |
|
495 |
bind_thm("takeWhile_append1", conjI RS (result() RS mp)); |
|
496 |
Addsimps [takeWhile_append1]; |
|
923 | 497 |
|
2608 | 498 |
goal List.thy |
499 |
"(!x:set_of_list xs.P(x)) --> takeWhile P (xs @ ys) = xs @ takeWhile P ys"; |
|
500 |
by(list.induct_tac "xs" 1); |
|
501 |
by(Simp_tac 1); |
|
502 |
by(asm_full_simp_tac (!simpset setloop (split_tac[expand_if])) 1); |
|
503 |
bind_thm("takeWhile_append2", ballI RS (result() RS mp)); |
|
504 |
Addsimps [takeWhile_append2]; |
|
1169 | 505 |
|
2608 | 506 |
goal List.thy |
507 |
"x:set_of_list xs & ~P(x) --> dropWhile P (xs @ ys) = (dropWhile P xs)@ys"; |
|
508 |
by(list.induct_tac "xs" 1); |
|
509 |
by(Simp_tac 1); |
|
510 |
by(asm_full_simp_tac (!simpset setloop (split_tac[expand_if])) 1); |
|
511 |
by(Fast_tac 1); |
|
512 |
bind_thm("dropWhile_append1", conjI RS (result() RS mp)); |
|
513 |
Addsimps [dropWhile_append1]; |
|
514 |
||
515 |
goal List.thy |
|
516 |
"(!x:set_of_list xs.P(x)) --> dropWhile P (xs @ ys) = dropWhile P ys"; |
|
517 |
by(list.induct_tac "xs" 1); |
|
518 |
by(Simp_tac 1); |
|
519 |
by(asm_full_simp_tac (!simpset setloop (split_tac[expand_if])) 1); |
|
520 |
bind_thm("dropWhile_append2", ballI RS (result() RS mp)); |
|
521 |
Addsimps [dropWhile_append2]; |
|
522 |
||
523 |
goal List.thy "x:set_of_list(takeWhile P xs) --> x:set_of_list xs & P x"; |
|
524 |
by(list.induct_tac "xs" 1); |
|
525 |
by(Simp_tac 1); |
|
526 |
by(asm_full_simp_tac (!simpset setloop (split_tac[expand_if])) 1); |
|
527 |
qed_spec_mp"set_of_list_take_whileD"; |
|
528 |