author | clasohm |
Wed, 29 Nov 1995 16:44:59 +0100 | |
changeset 1370 | 7361ac9b024d |
parent 1327 | 6c29cfab679c |
child 1419 | a6a034a47a71 |
permissions | -rw-r--r-- |
923 | 1 |
(* Title: HOL/List |
2 |
ID: $Id$ |
|
3 |
Author: Tobias Nipkow |
|
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 |
||
83 |
(** list_all **) |
|
84 |
||
85 |
goal List.thy "(Alls x:xs.True) = True"; |
|
86 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
87 |
by (ALLGOALS Asm_simp_tac); |
923 | 88 |
qed "list_all_True"; |
89 |
||
90 |
goal List.thy "list_all p (xs@ys) = (list_all p xs & list_all p ys)"; |
|
91 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
92 |
by (ALLGOALS Asm_simp_tac); |
923 | 93 |
qed "list_all_conj"; |
94 |
||
95 |
goal List.thy "(Alls x:xs.P(x)) = (!x. x mem xs --> P(x))"; |
|
96 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
97 |
by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if])))); |
1169 | 98 |
by (fast_tac HOL_cs 1); |
923 | 99 |
qed "list_all_mem_conv"; |
100 |
||
101 |
||
102 |
(** list_case **) |
|
103 |
||
104 |
goal List.thy |
|
105 |
"P(list_case a f xs) = ((xs=[] --> P(a)) & \ |
|
106 |
\ (!y ys. xs=y#ys --> P(f y ys)))"; |
|
107 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
108 |
by (ALLGOALS Asm_simp_tac); |
1169 | 109 |
by (fast_tac HOL_cs 1); |
923 | 110 |
qed "expand_list_case"; |
111 |
||
112 |
goal List.thy "(xs=[] --> P([])) & (!y ys. xs=y#ys --> P(y#ys)) --> P(xs)"; |
|
1169 | 113 |
by (list.induct_tac "xs" 1); |
114 |
by (fast_tac HOL_cs 1); |
|
115 |
by (fast_tac HOL_cs 1); |
|
923 | 116 |
bind_thm("list_eq_cases", |
117 |
impI RSN (2,allI RSN (2,allI RSN (2,impI RS (conjI RS (result() RS mp)))))); |
|
118 |
||
119 |
(** flat **) |
|
120 |
||
121 |
goal List.thy "flat(xs@ys) = flat(xs)@flat(ys)"; |
|
122 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
123 |
by (ALLGOALS (asm_simp_tac (!simpset addsimps [append_assoc]))); |
923 | 124 |
qed"flat_append"; |
125 |
||
962 | 126 |
(** length **) |
127 |
||
128 |
goal List.thy "length(xs@ys) = length(xs)+length(ys)"; |
|
129 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
130 |
by (ALLGOALS Asm_simp_tac); |
962 | 131 |
qed"length_append"; |
1301 | 132 |
Addsimps [length_append]; |
133 |
||
134 |
goal List.thy "length (map f l) = length l"; |
|
135 |
by (list.induct_tac "l" 1); |
|
136 |
by (ALLGOALS Simp_tac); |
|
137 |
qed "length_map"; |
|
138 |
Addsimps [length_map]; |
|
962 | 139 |
|
1169 | 140 |
goal List.thy "length(rev xs) = length(xs)"; |
141 |
by (list.induct_tac "xs" 1); |
|
1301 | 142 |
by (ALLGOALS Asm_simp_tac); |
1169 | 143 |
qed "length_rev"; |
1301 | 144 |
Addsimps [length_rev]; |
1169 | 145 |
|
923 | 146 |
(** nth **) |
147 |
||
148 |
val [nth_0,nth_Suc] = nat_recs nth_def; |
|
149 |
store_thm("nth_0",nth_0); |
|
150 |
store_thm("nth_Suc",nth_Suc); |
|
1301 | 151 |
Addsimps [nth_0,nth_Suc]; |
152 |
||
153 |
goal List.thy "!n. n < length xs --> nth n (map f xs) = f (nth n xs)"; |
|
154 |
by (list.induct_tac "xs" 1); |
|
155 |
(* case [] *) |
|
156 |
by (Asm_full_simp_tac 1); |
|
157 |
(* case x#xl *) |
|
158 |
by (rtac allI 1); |
|
159 |
by (nat_ind_tac "n" 1); |
|
160 |
by (ALLGOALS Asm_full_simp_tac); |
|
161 |
bind_thm("nth_map", result() RS spec RS mp); |
|
162 |
Addsimps [nth_map]; |
|
163 |
||
164 |
goal List.thy "!n. n < length xs --> list_all P xs --> P(nth n xs)"; |
|
165 |
by (list.induct_tac "xs" 1); |
|
166 |
(* case [] *) |
|
167 |
by (Simp_tac 1); |
|
168 |
(* case x#xl *) |
|
169 |
by (rtac allI 1); |
|
170 |
by (nat_ind_tac "n" 1); |
|
171 |
by (ALLGOALS Asm_full_simp_tac); |
|
172 |
bind_thm("list_all_nth", result() RS spec RS mp RS mp); |
|
173 |
||
174 |
goal List.thy "!n. n < length xs --> (nth n xs) mem xs"; |
|
175 |
by (list.induct_tac "xs" 1); |
|
176 |
(* case [] *) |
|
177 |
by (Simp_tac 1); |
|
178 |
(* case x#xl *) |
|
179 |
by (rtac allI 1); |
|
180 |
by (nat_ind_tac "n" 1); |
|
181 |
(* case 0 *) |
|
182 |
by (Asm_full_simp_tac 1); |
|
183 |
(* case Suc x *) |
|
184 |
by (asm_full_simp_tac (!simpset setloop (split_tac [expand_if])) 1); |
|
185 |
bind_thm ("nth_mem",result() RS spec RS mp); |
|
186 |
Addsimps [nth_mem]; |
|
187 |
||
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
188 |
(** drop **) |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
189 |
|
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
190 |
goalw thy [drop_def] "drop 0 xs = xs"; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
191 |
by(Simp_tac 1); |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
192 |
qed "drop_0"; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
193 |
|
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
194 |
goalw thy [drop_def] "drop (Suc n) (x#xs) = drop n xs"; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
195 |
by(Simp_tac 1); |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
196 |
qed "drop_Suc"; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
197 |
|
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
198 |
goalw thy [drop_def] "drop n [] = []"; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
199 |
by (nat_ind_tac "n" 1); |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
200 |
by (ALLGOALS Asm_simp_tac); |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
201 |
qed "drop_Nil"; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
202 |
|
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
203 |
Addsimps [drop_0,drop_Suc,drop_Nil]; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
204 |
|
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
205 |
(** take **) |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
206 |
|
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
207 |
goalw thy [take_def] "take 0 xs = []"; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
208 |
by(Simp_tac 1); |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
209 |
qed "take_0"; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
210 |
|
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
211 |
goalw thy [take_def] "take (Suc n) (x#xs) = x # take n xs"; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
212 |
by(Simp_tac 1); |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
213 |
qed "take_Suc"; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
214 |
|
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
215 |
goalw thy [take_def] "take n [] = []"; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
216 |
by (nat_ind_tac "n" 1); |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
217 |
by (ALLGOALS Asm_simp_tac); |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
218 |
qed "take_Nil"; |
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 |
Addsimps [take_0,take_Suc,take_Nil]; |
923 | 221 |
|
222 |
(** Additional mapping lemmas **) |
|
223 |
||
995
95c148a7b9c4
generalized map (%x.x) xs = xs to map (%x.x) = (%xs.xs)
nipkow
parents:
974
diff
changeset
|
224 |
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
|
225 |
by (rtac ext 1); |
923 | 226 |
by (list.induct_tac "xs" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
227 |
by (ALLGOALS Asm_simp_tac); |
923 | 228 |
qed "map_ident"; |
229 |
||
230 |
goal List.thy "map f (xs@ys) = map f xs @ map f ys"; |
|
231 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
232 |
by (ALLGOALS Asm_simp_tac); |
923 | 233 |
qed "map_append"; |
234 |
||
235 |
goalw List.thy [o_def] "map (f o g) xs = map f (map g xs)"; |
|
236 |
by (list.induct_tac "xs" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
237 |
by (ALLGOALS Asm_simp_tac); |
923 | 238 |
qed "map_compose"; |
239 |
||
1169 | 240 |
goal List.thy "rev(map f l) = map f (rev l)"; |
241 |
by (list.induct_tac "l" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
242 |
by (ALLGOALS (asm_simp_tac (!simpset addsimps [map_append]))); |
1169 | 243 |
qed "rev_map_distrib"; |
244 |
||
245 |
goal List.thy "rev(flat ls) = flat (map rev (rev ls))"; |
|
246 |
by (list.induct_tac "ls" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
247 |
by (ALLGOALS (asm_simp_tac (!simpset addsimps |
1169 | 248 |
[map_append, flat_append, rev_append, append_Nil2]))); |
249 |
qed "rev_flat"; |
|
250 |
||
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1202
diff
changeset
|
251 |
Addsimps |
923 | 252 |
[not_Cons_self, append_assoc, append_Nil2, append_is_Nil, same_append_eq, |
253 |
mem_append, mem_filter, |
|
1202 | 254 |
rev_append, rev_rev_ident, |
923 | 255 |
map_ident, map_append, map_compose, |
1301 | 256 |
flat_append, list_all_True, list_all_conj]; |
923 | 257 |