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