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