author | paulson |
Tue, 01 Oct 1996 15:49:29 +0200 | |
changeset 2048 | bb54fbba0071 |
parent 1985 | 84cf16192e03 |
child 2512 | 0231e4f467f2 |
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); |
923 | 19 |
qed "not_Cons_self"; |
20 |
||
21 |
goal List.thy "(xs ~= []) = (? y ys. xs = y#ys)"; |
|
22 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
23 |
by (Simp_tac 1); |
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
24 |
by (Asm_simp_tac 1); |
1169 | 25 |
by (REPEAT(resolve_tac [exI,refl,conjI] 1)); |
923 | 26 |
qed "neq_Nil_conv"; |
27 |
||
28 |
||
29 |
(** @ - append **) |
|
30 |
||
31 |
goal List.thy "(xs@ys)@zs = xs@(ys@zs)"; |
|
32 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
33 |
by (ALLGOALS Asm_simp_tac); |
923 | 34 |
qed "append_assoc"; |
35 |
||
36 |
goal List.thy "xs @ [] = xs"; |
|
37 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
38 |
by (ALLGOALS Asm_simp_tac); |
923 | 39 |
qed "append_Nil2"; |
40 |
||
41 |
goal List.thy "(xs@ys = []) = (xs=[] & ys=[])"; |
|
42 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
43 |
by (ALLGOALS Asm_simp_tac); |
923 | 44 |
qed "append_is_Nil"; |
45 |
||
46 |
goal List.thy "(xs @ ys = xs @ zs) = (ys=zs)"; |
|
47 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
48 |
by (ALLGOALS Asm_simp_tac); |
923 | 49 |
qed "same_append_eq"; |
50 |
||
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
51 |
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
|
52 |
by (list.induct_tac "xs" 1); |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
53 |
by (ALLGOALS Asm_simp_tac); |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
54 |
qed "hd_append"; |
923 | 55 |
|
1169 | 56 |
(** rev **) |
57 |
||
58 |
goal List.thy "rev(xs@ys) = rev(ys) @ rev(xs)"; |
|
59 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
60 |
by (ALLGOALS (asm_simp_tac (!simpset addsimps [append_Nil2,append_assoc]))); |
1169 | 61 |
qed "rev_append"; |
62 |
||
63 |
goal List.thy "rev(rev l) = l"; |
|
64 |
by (list.induct_tac "l" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
65 |
by (ALLGOALS (asm_simp_tac (!simpset addsimps [rev_append]))); |
1169 | 66 |
qed "rev_rev_ident"; |
67 |
||
68 |
||
923 | 69 |
(** mem **) |
70 |
||
71 |
goal List.thy "x mem (xs@ys) = (x mem xs | x mem ys)"; |
|
72 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
73 |
by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if])))); |
923 | 74 |
qed "mem_append"; |
75 |
||
76 |
goal List.thy "x mem [x:xs.P(x)] = (x mem xs & P(x))"; |
|
77 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
78 |
by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if])))); |
923 | 79 |
qed "mem_filter"; |
80 |
||
1908 | 81 |
(** set_of_list **) |
1812 | 82 |
|
1908 | 83 |
goal thy "set_of_list (xs@ys) = (set_of_list xs Un set_of_list ys)"; |
1812 | 84 |
by (list.induct_tac "xs" 1); |
85 |
by (ALLGOALS Asm_simp_tac); |
|
86 |
by (Fast_tac 1); |
|
1908 | 87 |
qed "set_of_list_append"; |
1812 | 88 |
|
1908 | 89 |
goal thy "(x mem xs) = (x: set_of_list xs)"; |
1812 | 90 |
by (list.induct_tac "xs" 1); |
91 |
by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if])))); |
|
92 |
by (Fast_tac 1); |
|
1908 | 93 |
qed "set_of_list_mem_eq"; |
1812 | 94 |
|
1936 | 95 |
goal List.thy "set_of_list l <= set_of_list (x#l)"; |
96 |
by (Simp_tac 1); |
|
97 |
by (Fast_tac 1); |
|
98 |
qed "set_of_list_subset_Cons"; |
|
99 |
||
1812 | 100 |
|
923 | 101 |
(** list_all **) |
102 |
||
103 |
goal List.thy "(Alls x:xs.True) = True"; |
|
104 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
105 |
by (ALLGOALS Asm_simp_tac); |
923 | 106 |
qed "list_all_True"; |
107 |
||
108 |
goal List.thy "list_all p (xs@ys) = (list_all p xs & list_all p ys)"; |
|
109 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
110 |
by (ALLGOALS Asm_simp_tac); |
923 | 111 |
qed "list_all_conj"; |
112 |
||
113 |
goal List.thy "(Alls x:xs.P(x)) = (!x. x mem xs --> P(x))"; |
|
114 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
115 |
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
|
116 |
by (Fast_tac 1); |
923 | 117 |
qed "list_all_mem_conv"; |
118 |
||
119 |
||
120 |
(** list_case **) |
|
121 |
||
122 |
goal List.thy |
|
123 |
"P(list_case a f xs) = ((xs=[] --> P(a)) & \ |
|
124 |
\ (!y ys. xs=y#ys --> P(f y ys)))"; |
|
125 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
126 |
by (ALLGOALS Asm_simp_tac); |
1760
6f41a494f3b1
Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents:
1552
diff
changeset
|
127 |
by (Fast_tac 1); |
923 | 128 |
qed "expand_list_case"; |
129 |
||
130 |
goal List.thy "(xs=[] --> P([])) & (!y ys. xs=y#ys --> P(y#ys)) --> P(xs)"; |
|
1169 | 131 |
by (list.induct_tac "xs" 1); |
1760
6f41a494f3b1
Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents:
1552
diff
changeset
|
132 |
by (Fast_tac 1); |
6f41a494f3b1
Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents:
1552
diff
changeset
|
133 |
by (Fast_tac 1); |
923 | 134 |
bind_thm("list_eq_cases", |
135 |
impI RSN (2,allI RSN (2,allI RSN (2,impI RS (conjI RS (result() RS mp)))))); |
|
136 |
||
137 |
(** flat **) |
|
138 |
||
139 |
goal List.thy "flat(xs@ys) = flat(xs)@flat(ys)"; |
|
140 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
141 |
by (ALLGOALS (asm_simp_tac (!simpset addsimps [append_assoc]))); |
923 | 142 |
qed"flat_append"; |
143 |
||
962 | 144 |
(** length **) |
145 |
||
146 |
goal List.thy "length(xs@ys) = length(xs)+length(ys)"; |
|
147 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
148 |
by (ALLGOALS Asm_simp_tac); |
962 | 149 |
qed"length_append"; |
1301 | 150 |
Addsimps [length_append]; |
151 |
||
152 |
goal List.thy "length (map f l) = length l"; |
|
153 |
by (list.induct_tac "l" 1); |
|
154 |
by (ALLGOALS Simp_tac); |
|
155 |
qed "length_map"; |
|
156 |
Addsimps [length_map]; |
|
962 | 157 |
|
1169 | 158 |
goal List.thy "length(rev xs) = length(xs)"; |
159 |
by (list.induct_tac "xs" 1); |
|
1301 | 160 |
by (ALLGOALS Asm_simp_tac); |
1169 | 161 |
qed "length_rev"; |
1301 | 162 |
Addsimps [length_rev]; |
1169 | 163 |
|
923 | 164 |
(** nth **) |
165 |
||
166 |
val [nth_0,nth_Suc] = nat_recs nth_def; |
|
167 |
store_thm("nth_0",nth_0); |
|
168 |
store_thm("nth_Suc",nth_Suc); |
|
1301 | 169 |
Addsimps [nth_0,nth_Suc]; |
170 |
||
171 |
goal List.thy "!n. n < length xs --> nth n (map f xs) = f (nth n xs)"; |
|
172 |
by (list.induct_tac "xs" 1); |
|
173 |
(* case [] *) |
|
174 |
by (Asm_full_simp_tac 1); |
|
175 |
(* case x#xl *) |
|
176 |
by (rtac allI 1); |
|
177 |
by (nat_ind_tac "n" 1); |
|
178 |
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
|
179 |
qed_spec_mp "nth_map"; |
1301 | 180 |
Addsimps [nth_map]; |
181 |
||
182 |
goal List.thy "!n. n < length xs --> list_all P xs --> P(nth n xs)"; |
|
183 |
by (list.induct_tac "xs" 1); |
|
184 |
(* case [] *) |
|
185 |
by (Simp_tac 1); |
|
186 |
(* case x#xl *) |
|
187 |
by (rtac allI 1); |
|
188 |
by (nat_ind_tac "n" 1); |
|
189 |
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
|
190 |
qed_spec_mp "list_all_nth"; |
1301 | 191 |
|
192 |
goal List.thy "!n. n < length xs --> (nth n xs) mem xs"; |
|
193 |
by (list.induct_tac "xs" 1); |
|
194 |
(* case [] *) |
|
195 |
by (Simp_tac 1); |
|
196 |
(* case x#xl *) |
|
197 |
by (rtac allI 1); |
|
198 |
by (nat_ind_tac "n" 1); |
|
199 |
(* case 0 *) |
|
200 |
by (Asm_full_simp_tac 1); |
|
201 |
(* case Suc x *) |
|
202 |
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
|
203 |
qed_spec_mp "nth_mem"; |
1301 | 204 |
Addsimps [nth_mem]; |
205 |
||
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
206 |
(** drop **) |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
207 |
|
1419
a6a034a47a71
defined take/drop by induction over list rather than nat.
nipkow
parents:
1327
diff
changeset
|
208 |
goal thy "drop 0 xs = xs"; |
a6a034a47a71
defined take/drop by induction over list rather than nat.
nipkow
parents:
1327
diff
changeset
|
209 |
by (list.induct_tac "xs" 1); |
a6a034a47a71
defined take/drop by induction over list rather than nat.
nipkow
parents:
1327
diff
changeset
|
210 |
by (ALLGOALS Asm_simp_tac); |
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
211 |
qed "drop_0"; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
212 |
|
1419
a6a034a47a71
defined take/drop by induction over list rather than nat.
nipkow
parents:
1327
diff
changeset
|
213 |
goal thy "drop (Suc n) (x#xs) = drop n xs"; |
1552 | 214 |
by (Simp_tac 1); |
1419
a6a034a47a71
defined take/drop by induction over list rather than nat.
nipkow
parents:
1327
diff
changeset
|
215 |
qed "drop_Suc_Cons"; |
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
216 |
|
1419
a6a034a47a71
defined take/drop by induction over list rather than nat.
nipkow
parents:
1327
diff
changeset
|
217 |
Delsimps [drop_Cons]; |
a6a034a47a71
defined take/drop by induction over list rather than nat.
nipkow
parents:
1327
diff
changeset
|
218 |
Addsimps [drop_0,drop_Suc_Cons]; |
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
219 |
|
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
220 |
(** take **) |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
221 |
|
1419
a6a034a47a71
defined take/drop by induction over list rather than nat.
nipkow
parents:
1327
diff
changeset
|
222 |
goal thy "take 0 xs = []"; |
a6a034a47a71
defined take/drop by induction over list rather than nat.
nipkow
parents:
1327
diff
changeset
|
223 |
by (list.induct_tac "xs" 1); |
a6a034a47a71
defined take/drop by induction over list rather than nat.
nipkow
parents:
1327
diff
changeset
|
224 |
by (ALLGOALS Asm_simp_tac); |
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
225 |
qed "take_0"; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
226 |
|
1419
a6a034a47a71
defined take/drop by induction over list rather than nat.
nipkow
parents:
1327
diff
changeset
|
227 |
goal thy "take (Suc n) (x#xs) = x # take n xs"; |
1552 | 228 |
by (Simp_tac 1); |
1419
a6a034a47a71
defined take/drop by induction over list rather than nat.
nipkow
parents:
1327
diff
changeset
|
229 |
qed "take_Suc_Cons"; |
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
230 |
|
1419
a6a034a47a71
defined take/drop by induction over list rather than nat.
nipkow
parents:
1327
diff
changeset
|
231 |
Delsimps [take_Cons]; |
a6a034a47a71
defined take/drop by induction over list rather than nat.
nipkow
parents:
1327
diff
changeset
|
232 |
Addsimps [take_0,take_Suc_Cons]; |
923 | 233 |
|
234 |
(** Additional mapping lemmas **) |
|
235 |
||
995
95c148a7b9c4
generalized map (%x.x) xs = xs to map (%x.x) = (%xs.xs)
nipkow
parents:
974
diff
changeset
|
236 |
goal List.thy "map (%x.x) = (%xs.xs)"; |
95c148a7b9c4
generalized map (%x.x) xs = xs to map (%x.x) = (%xs.xs)
nipkow
parents:
974
diff
changeset
|
237 |
by (rtac ext 1); |
923 | 238 |
by (list.induct_tac "xs" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
239 |
by (ALLGOALS Asm_simp_tac); |
923 | 240 |
qed "map_ident"; |
241 |
||
242 |
goal List.thy "map f (xs@ys) = map f xs @ map f ys"; |
|
243 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
244 |
by (ALLGOALS Asm_simp_tac); |
923 | 245 |
qed "map_append"; |
246 |
||
247 |
goalw List.thy [o_def] "map (f o g) xs = map f (map g xs)"; |
|
248 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
249 |
by (ALLGOALS Asm_simp_tac); |
923 | 250 |
qed "map_compose"; |
251 |
||
1169 | 252 |
goal List.thy "rev(map f l) = map f (rev l)"; |
253 |
by (list.induct_tac "l" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
254 |
by (ALLGOALS (asm_simp_tac (!simpset addsimps [map_append]))); |
1169 | 255 |
qed "rev_map_distrib"; |
256 |
||
257 |
goal List.thy "rev(flat ls) = flat (map rev (rev ls))"; |
|
258 |
by (list.induct_tac "ls" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
259 |
by (ALLGOALS (asm_simp_tac (!simpset addsimps |
1169 | 260 |
[map_append, flat_append, rev_append, append_Nil2]))); |
261 |
qed "rev_flat"; |
|
262 |
||
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
263 |
Addsimps |
923 | 264 |
[not_Cons_self, append_assoc, append_Nil2, append_is_Nil, same_append_eq, |
265 |
mem_append, mem_filter, |
|
1202 | 266 |
rev_append, rev_rev_ident, |
923 | 267 |
map_ident, map_append, map_compose, |
1301 | 268 |
flat_append, list_all_True, list_all_conj]; |
923 | 269 |