author | wenzelm |
Tue, 24 Aug 1999 11:50:58 +0200 | |
changeset 7333 | 6cb15c6f1d9f |
parent 7246 | 33058867d6eb |
child 7570 | a9391550eea1 |
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 |
||
4935 | 9 |
Goal "!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); |
5316 | 11 |
by Auto_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 |
|
4935 | 16 |
Goal "(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); |
5316 | 18 |
by Auto_tac; |
923 | 19 |
qed "neq_Nil_conv"; |
20 |
||
4830 | 21 |
(* Induction over the length of a list: *) |
4935 | 22 |
val [prem] = Goal |
4911 | 23 |
"(!!xs. (!ys. length ys < length xs --> P ys) ==> P xs) ==> P(xs)"; |
5132 | 24 |
by (rtac measure_induct 1 THEN etac prem 1); |
4911 | 25 |
qed "length_induct"; |
26 |
||
923 | 27 |
|
3468 | 28 |
(** "lists": the list-forming operator over sets **) |
3342
ec3b55fcb165
New operator "lists" for formalizing sets of lists
paulson
parents:
3292
diff
changeset
|
29 |
|
5043 | 30 |
Goalw lists.defs "A<=B ==> lists A <= lists B"; |
3342
ec3b55fcb165
New operator "lists" for formalizing sets of lists
paulson
parents:
3292
diff
changeset
|
31 |
by (rtac lfp_mono 1); |
ec3b55fcb165
New operator "lists" for formalizing sets of lists
paulson
parents:
3292
diff
changeset
|
32 |
by (REPEAT (ares_tac basic_monos 1)); |
ec3b55fcb165
New operator "lists" for formalizing sets of lists
paulson
parents:
3292
diff
changeset
|
33 |
qed "lists_mono"; |
3196 | 34 |
|
6141 | 35 |
val listsE = lists.mk_cases "x#l : lists A"; |
3468 | 36 |
AddSEs [listsE]; |
37 |
AddSIs lists.intrs; |
|
38 |
||
5043 | 39 |
Goal "l: lists A ==> l: lists B --> l: lists (A Int B)"; |
3468 | 40 |
by (etac lists.induct 1); |
41 |
by (ALLGOALS Blast_tac); |
|
42 |
qed_spec_mp "lists_IntI"; |
|
43 |
||
4935 | 44 |
Goal "lists (A Int B) = lists A Int lists B"; |
4423 | 45 |
by (rtac (mono_Int RS equalityI) 1); |
4089 | 46 |
by (simp_tac (simpset() addsimps [mono_def, lists_mono]) 1); |
47 |
by (blast_tac (claset() addSIs [lists_IntI]) 1); |
|
3468 | 48 |
qed "lists_Int_eq"; |
49 |
Addsimps [lists_Int_eq]; |
|
50 |
||
3196 | 51 |
|
4643 | 52 |
(** Case analysis **) |
53 |
section "Case analysis"; |
|
2608 | 54 |
|
4935 | 55 |
val prems = Goal "[| P([]); !!x xs. P(x#xs) |] ==> P(xs)"; |
3457 | 56 |
by (induct_tac "xs" 1); |
57 |
by (REPEAT(resolve_tac prems 1)); |
|
2608 | 58 |
qed "list_cases"; |
59 |
||
4935 | 60 |
Goal "(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
|
61 |
by (induct_tac "xs" 1); |
2891 | 62 |
by (Blast_tac 1); |
63 |
by (Blast_tac 1); |
|
2608 | 64 |
bind_thm("list_eq_cases", |
65 |
impI RSN (2,allI RSN (2,allI RSN (2,impI RS (conjI RS (result() RS mp)))))); |
|
66 |
||
3860 | 67 |
(** length **) |
68 |
(* needs to come before "@" because of thm append_eq_append_conv *) |
|
69 |
||
70 |
section "length"; |
|
71 |
||
4935 | 72 |
Goal "length(xs@ys) = length(xs)+length(ys)"; |
3860 | 73 |
by (induct_tac "xs" 1); |
5316 | 74 |
by Auto_tac; |
3860 | 75 |
qed"length_append"; |
76 |
Addsimps [length_append]; |
|
77 |
||
5129 | 78 |
Goal "length (map f xs) = length xs"; |
79 |
by (induct_tac "xs" 1); |
|
5316 | 80 |
by Auto_tac; |
3860 | 81 |
qed "length_map"; |
82 |
Addsimps [length_map]; |
|
83 |
||
4935 | 84 |
Goal "length(rev xs) = length(xs)"; |
3860 | 85 |
by (induct_tac "xs" 1); |
5316 | 86 |
by Auto_tac; |
3860 | 87 |
qed "length_rev"; |
88 |
Addsimps [length_rev]; |
|
89 |
||
7028 | 90 |
Goal "length(tl xs) = (length xs) - 1"; |
4423 | 91 |
by (exhaust_tac "xs" 1); |
5316 | 92 |
by Auto_tac; |
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
93 |
qed "length_tl"; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
94 |
Addsimps [length_tl]; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
95 |
|
4935 | 96 |
Goal "(length xs = 0) = (xs = [])"; |
3860 | 97 |
by (induct_tac "xs" 1); |
5316 | 98 |
by Auto_tac; |
3860 | 99 |
qed "length_0_conv"; |
100 |
AddIffs [length_0_conv]; |
|
101 |
||
4935 | 102 |
Goal "(0 = length xs) = (xs = [])"; |
3860 | 103 |
by (induct_tac "xs" 1); |
5316 | 104 |
by Auto_tac; |
3860 | 105 |
qed "zero_length_conv"; |
106 |
AddIffs [zero_length_conv]; |
|
107 |
||
4935 | 108 |
Goal "(0 < length xs) = (xs ~= [])"; |
3860 | 109 |
by (induct_tac "xs" 1); |
5316 | 110 |
by Auto_tac; |
3860 | 111 |
qed "length_greater_0_conv"; |
112 |
AddIffs [length_greater_0_conv]; |
|
113 |
||
5296 | 114 |
Goal "(length xs = Suc n) = (? y ys. xs = y#ys & length ys = n)"; |
115 |
by (induct_tac "xs" 1); |
|
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
116 |
by Auto_tac; |
5296 | 117 |
qed "length_Suc_conv"; |
118 |
||
923 | 119 |
(** @ - append **) |
120 |
||
3467 | 121 |
section "@ - append"; |
122 |
||
4935 | 123 |
Goal "(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
|
124 |
by (induct_tac "xs" 1); |
5316 | 125 |
by Auto_tac; |
923 | 126 |
qed "append_assoc"; |
2512 | 127 |
Addsimps [append_assoc]; |
923 | 128 |
|
4935 | 129 |
Goal "xs @ [] = xs"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
130 |
by (induct_tac "xs" 1); |
5316 | 131 |
by Auto_tac; |
923 | 132 |
qed "append_Nil2"; |
2512 | 133 |
Addsimps [append_Nil2]; |
923 | 134 |
|
4935 | 135 |
Goal "(xs@ys = []) = (xs=[] & ys=[])"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
136 |
by (induct_tac "xs" 1); |
5316 | 137 |
by Auto_tac; |
2608 | 138 |
qed "append_is_Nil_conv"; |
139 |
AddIffs [append_is_Nil_conv]; |
|
140 |
||
4935 | 141 |
Goal "([] = xs@ys) = (xs=[] & ys=[])"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
142 |
by (induct_tac "xs" 1); |
5316 | 143 |
by Auto_tac; |
2608 | 144 |
qed "Nil_is_append_conv"; |
145 |
AddIffs [Nil_is_append_conv]; |
|
923 | 146 |
|
4935 | 147 |
Goal "(xs @ ys = xs) = (ys=[])"; |
3574 | 148 |
by (induct_tac "xs" 1); |
5316 | 149 |
by Auto_tac; |
3574 | 150 |
qed "append_self_conv"; |
151 |
||
4935 | 152 |
Goal "(xs = xs @ ys) = (ys=[])"; |
3574 | 153 |
by (induct_tac "xs" 1); |
5316 | 154 |
by Auto_tac; |
3574 | 155 |
qed "self_append_conv"; |
156 |
AddIffs [append_self_conv,self_append_conv]; |
|
157 |
||
4935 | 158 |
Goal "!ys. length xs = length ys | length us = length vs \ |
3860 | 159 |
\ --> (xs@us = ys@vs) = (xs=ys & us=vs)"; |
4423 | 160 |
by (induct_tac "xs" 1); |
161 |
by (rtac allI 1); |
|
162 |
by (exhaust_tac "ys" 1); |
|
163 |
by (Asm_simp_tac 1); |
|
5641 | 164 |
by (Force_tac 1); |
4423 | 165 |
by (rtac allI 1); |
166 |
by (exhaust_tac "ys" 1); |
|
5641 | 167 |
by (Force_tac 1); |
4423 | 168 |
by (Asm_simp_tac 1); |
3860 | 169 |
qed_spec_mp "append_eq_append_conv"; |
170 |
Addsimps [append_eq_append_conv]; |
|
171 |
||
4935 | 172 |
Goal "(xs @ ys = xs @ zs) = (ys=zs)"; |
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
173 |
by (Simp_tac 1); |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
174 |
qed "same_append_eq"; |
3860 | 175 |
|
4935 | 176 |
Goal "(xs @ [x] = ys @ [y]) = (xs = ys & x = y)"; |
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
177 |
by (Simp_tac 1); |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
178 |
qed "append1_eq_conv"; |
2608 | 179 |
|
4935 | 180 |
Goal "(ys @ xs = zs @ xs) = (ys=zs)"; |
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
181 |
by (Simp_tac 1); |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
182 |
qed "append_same_eq"; |
2608 | 183 |
|
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
184 |
AddSIs |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
185 |
[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
|
186 |
AddSDs |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
187 |
[same_append_eq RS iffD1, append1_eq_conv RS iffD1, append_same_eq RS iffD1]; |
3571 | 188 |
|
4935 | 189 |
Goal "(xs @ ys = ys) = (xs=[])"; |
5132 | 190 |
by (cut_inst_tac [("zs","[]")] append_same_eq 1); |
5316 | 191 |
by Auto_tac; |
4647 | 192 |
qed "append_self_conv2"; |
193 |
||
4935 | 194 |
Goal "(ys = xs @ ys) = (xs=[])"; |
5132 | 195 |
by (simp_tac (simpset() addsimps |
4647 | 196 |
[simplify (simpset()) (read_instantiate[("ys","[]")]append_same_eq)]) 1); |
5132 | 197 |
by (Blast_tac 1); |
4647 | 198 |
qed "self_append_conv2"; |
199 |
AddIffs [append_self_conv2,self_append_conv2]; |
|
200 |
||
4935 | 201 |
Goal "xs ~= [] --> hd xs # tl xs = xs"; |
3457 | 202 |
by (induct_tac "xs" 1); |
5316 | 203 |
by Auto_tac; |
2608 | 204 |
qed_spec_mp "hd_Cons_tl"; |
205 |
Addsimps [hd_Cons_tl]; |
|
923 | 206 |
|
4935 | 207 |
Goal "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
|
208 |
by (induct_tac "xs" 1); |
5316 | 209 |
by Auto_tac; |
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
210 |
qed "hd_append"; |
923 | 211 |
|
5043 | 212 |
Goal "xs ~= [] ==> hd(xs @ ys) = hd xs"; |
4089 | 213 |
by (asm_simp_tac (simpset() addsimps [hd_append] |
5183 | 214 |
addsplits [list.split]) 1); |
3571 | 215 |
qed "hd_append2"; |
216 |
Addsimps [hd_append2]; |
|
217 |
||
4935 | 218 |
Goal "tl(xs@ys) = (case xs of [] => tl(ys) | z#zs => zs@ys)"; |
5183 | 219 |
by (simp_tac (simpset() addsplits [list.split]) 1); |
2608 | 220 |
qed "tl_append"; |
221 |
||
5043 | 222 |
Goal "xs ~= [] ==> tl(xs @ ys) = (tl xs) @ ys"; |
4089 | 223 |
by (asm_simp_tac (simpset() addsimps [tl_append] |
5183 | 224 |
addsplits [list.split]) 1); |
3571 | 225 |
qed "tl_append2"; |
226 |
Addsimps [tl_append2]; |
|
227 |
||
5272 | 228 |
(* trivial rules for solving @-equations automatically *) |
229 |
||
230 |
Goal "xs = ys ==> xs = [] @ ys"; |
|
5318 | 231 |
by (Asm_simp_tac 1); |
5272 | 232 |
qed "eq_Nil_appendI"; |
233 |
||
234 |
Goal "[| x#xs1 = ys; xs = xs1 @ zs |] ==> x#xs = ys@zs"; |
|
5318 | 235 |
by (dtac sym 1); |
236 |
by (Asm_simp_tac 1); |
|
5272 | 237 |
qed "Cons_eq_appendI"; |
238 |
||
239 |
Goal "[| xs@xs1 = zs; ys = xs1 @ us |] ==> xs@ys = zs@us"; |
|
5318 | 240 |
by (dtac sym 1); |
241 |
by (Asm_simp_tac 1); |
|
5272 | 242 |
qed "append_eq_appendI"; |
243 |
||
4830 | 244 |
|
5427 | 245 |
(*** |
246 |
Simplification procedure for all list equalities. |
|
247 |
Currently only tries to rearranges @ to see if |
|
248 |
- both lists end in a singleton list, |
|
249 |
- or both lists end in the same list. |
|
250 |
***) |
|
251 |
local |
|
252 |
||
253 |
val list_eq_pattern = |
|
6394 | 254 |
Thm.read_cterm (Theory.sign_of List.thy) ("(xs::'a list) = ys",HOLogic.boolT); |
5427 | 255 |
|
7224 | 256 |
fun last (cons as Const("List.list.Cons",_) $ _ $ xs) = |
257 |
(case xs of Const("List.list.Nil",_) => cons | _ => last xs) |
|
5427 | 258 |
| last (Const("List.op @",_) $ _ $ ys) = last ys |
259 |
| last t = t; |
|
260 |
||
7224 | 261 |
fun list1 (Const("List.list.Cons",_) $ _ $ Const("List.list.Nil",_)) = true |
5427 | 262 |
| list1 _ = false; |
263 |
||
7224 | 264 |
fun butlast ((cons as Const("List.list.Cons",_) $ x) $ xs) = |
265 |
(case xs of Const("List.list.Nil",_) => xs | _ => cons $ butlast xs) |
|
5427 | 266 |
| butlast ((app as Const("List.op @",_) $ xs) $ ys) = app $ butlast ys |
7224 | 267 |
| butlast xs = Const("List.list.Nil",fastype_of xs); |
5427 | 268 |
|
269 |
val rearr_tac = |
|
270 |
simp_tac (HOL_basic_ss addsimps [append_assoc,append_Nil,append_Cons]); |
|
271 |
||
272 |
fun list_eq sg _ (F as (eq as Const(_,eqT)) $ lhs $ rhs) = |
|
273 |
let |
|
274 |
val lastl = last lhs and lastr = last rhs |
|
275 |
fun rearr conv = |
|
276 |
let val lhs1 = butlast lhs and rhs1 = butlast rhs |
|
277 |
val Type(_,listT::_) = eqT |
|
278 |
val appT = [listT,listT] ---> listT |
|
279 |
val app = Const("List.op @",appT) |
|
280 |
val F2 = eq $ (app$lhs1$lastl) $ (app$rhs1$lastr) |
|
281 |
val ct = cterm_of sg (HOLogic.mk_Trueprop(HOLogic.mk_eq(F,F2))) |
|
282 |
val thm = prove_goalw_cterm [] ct (K [rearr_tac 1]) |
|
283 |
handle ERROR => |
|
284 |
error("The error(s) above occurred while trying to prove " ^ |
|
285 |
string_of_cterm ct) |
|
286 |
in Some((conv RS (thm RS trans)) RS eq_reflection) end |
|
287 |
||
288 |
in if list1 lastl andalso list1 lastr |
|
289 |
then rearr append1_eq_conv |
|
290 |
else |
|
291 |
if lastl aconv lastr |
|
292 |
then rearr append_same_eq |
|
293 |
else None |
|
294 |
end; |
|
295 |
in |
|
296 |
val list_eq_simproc = mk_simproc "list_eq" [list_eq_pattern] list_eq; |
|
297 |
end; |
|
298 |
||
299 |
Addsimprocs [list_eq_simproc]; |
|
300 |
||
301 |
||
2608 | 302 |
(** map **) |
303 |
||
3467 | 304 |
section "map"; |
305 |
||
5278 | 306 |
Goal "(!x. x : set xs --> f x = g x) --> map f xs = map g xs"; |
3457 | 307 |
by (induct_tac "xs" 1); |
5316 | 308 |
by Auto_tac; |
2608 | 309 |
bind_thm("map_ext", impI RS (allI RS (result() RS mp))); |
310 |
||
4935 | 311 |
Goal "map (%x. x) = (%xs. xs)"; |
2608 | 312 |
by (rtac ext 1); |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
313 |
by (induct_tac "xs" 1); |
5316 | 314 |
by Auto_tac; |
2608 | 315 |
qed "map_ident"; |
316 |
Addsimps[map_ident]; |
|
317 |
||
4935 | 318 |
Goal "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
|
319 |
by (induct_tac "xs" 1); |
5316 | 320 |
by Auto_tac; |
2608 | 321 |
qed "map_append"; |
322 |
Addsimps[map_append]; |
|
323 |
||
4935 | 324 |
Goalw [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
|
325 |
by (induct_tac "xs" 1); |
5316 | 326 |
by Auto_tac; |
2608 | 327 |
qed "map_compose"; |
328 |
Addsimps[map_compose]; |
|
329 |
||
4935 | 330 |
Goal "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
|
331 |
by (induct_tac "xs" 1); |
5316 | 332 |
by Auto_tac; |
2608 | 333 |
qed "rev_map"; |
334 |
||
3589
244daa75f890
Added function `replicate' and lemmas map_cong and set_replicate.
nipkow
parents:
3586
diff
changeset
|
335 |
(* a congruence rule for map: *) |
6451 | 336 |
Goal "xs=ys ==> (!x. x : set ys --> f x = g x) --> map f xs = map g ys"; |
4423 | 337 |
by (hyp_subst_tac 1); |
338 |
by (induct_tac "ys" 1); |
|
5316 | 339 |
by Auto_tac; |
6451 | 340 |
bind_thm("map_cong", impI RSN (2,allI RSN (2, result() RS mp))); |
3589
244daa75f890
Added function `replicate' and lemmas map_cong and set_replicate.
nipkow
parents:
3586
diff
changeset
|
341 |
|
4935 | 342 |
Goal "(map f xs = []) = (xs = [])"; |
4423 | 343 |
by (induct_tac "xs" 1); |
5316 | 344 |
by Auto_tac; |
3860 | 345 |
qed "map_is_Nil_conv"; |
346 |
AddIffs [map_is_Nil_conv]; |
|
347 |
||
4935 | 348 |
Goal "([] = map f xs) = (xs = [])"; |
4423 | 349 |
by (induct_tac "xs" 1); |
5316 | 350 |
by Auto_tac; |
3860 | 351 |
qed "Nil_is_map_conv"; |
352 |
AddIffs [Nil_is_map_conv]; |
|
353 |
||
354 |
||
1169 | 355 |
(** rev **) |
356 |
||
3467 | 357 |
section "rev"; |
358 |
||
4935 | 359 |
Goal "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
|
360 |
by (induct_tac "xs" 1); |
5316 | 361 |
by Auto_tac; |
1169 | 362 |
qed "rev_append"; |
2512 | 363 |
Addsimps[rev_append]; |
1169 | 364 |
|
4935 | 365 |
Goal "rev(rev l) = l"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
366 |
by (induct_tac "l" 1); |
5316 | 367 |
by Auto_tac; |
1169 | 368 |
qed "rev_rev_ident"; |
2512 | 369 |
Addsimps[rev_rev_ident]; |
1169 | 370 |
|
4935 | 371 |
Goal "(rev xs = []) = (xs = [])"; |
4423 | 372 |
by (induct_tac "xs" 1); |
5316 | 373 |
by Auto_tac; |
3860 | 374 |
qed "rev_is_Nil_conv"; |
375 |
AddIffs [rev_is_Nil_conv]; |
|
376 |
||
4935 | 377 |
Goal "([] = rev xs) = (xs = [])"; |
4423 | 378 |
by (induct_tac "xs" 1); |
5316 | 379 |
by Auto_tac; |
3860 | 380 |
qed "Nil_is_rev_conv"; |
381 |
AddIffs [Nil_is_rev_conv]; |
|
382 |
||
6820 | 383 |
Goal "!ys. (rev xs = rev ys) = (xs = ys)"; |
6831 | 384 |
by (induct_tac "xs" 1); |
6820 | 385 |
by (Force_tac 1); |
6831 | 386 |
by (rtac allI 1); |
387 |
by (exhaust_tac "ys" 1); |
|
6820 | 388 |
by (Asm_simp_tac 1); |
389 |
by (Force_tac 1); |
|
390 |
qed_spec_mp "rev_is_rev_conv"; |
|
391 |
AddIffs [rev_is_rev_conv]; |
|
392 |
||
4935 | 393 |
val prems = Goal "[| P []; !!x xs. P xs ==> P(xs@[x]) |] ==> P xs"; |
5132 | 394 |
by (stac (rev_rev_ident RS sym) 1); |
6162 | 395 |
by (res_inst_tac [("list", "rev xs")] list.induct 1); |
5132 | 396 |
by (ALLGOALS Simp_tac); |
397 |
by (resolve_tac prems 1); |
|
398 |
by (eresolve_tac prems 1); |
|
4935 | 399 |
qed "rev_induct"; |
400 |
||
5272 | 401 |
fun rev_induct_tac xs = res_inst_tac [("xs",xs)] rev_induct; |
402 |
||
4935 | 403 |
Goal "(xs = [] --> P) --> (!ys y. xs = ys@[y] --> P) --> P"; |
5132 | 404 |
by (res_inst_tac [("xs","xs")] rev_induct 1); |
5316 | 405 |
by Auto_tac; |
4935 | 406 |
bind_thm ("rev_exhaust", |
407 |
impI RSN (2,allI RSN (2,allI RSN (2,impI RS (result() RS mp RS mp))))); |
|
408 |
||
2608 | 409 |
|
3465 | 410 |
(** set **) |
1812 | 411 |
|
3467 | 412 |
section "set"; |
413 |
||
7032 | 414 |
Goal "finite (set xs)"; |
415 |
by (induct_tac "xs" 1); |
|
416 |
by Auto_tac; |
|
417 |
qed "finite_set"; |
|
418 |
AddIffs [finite_set]; |
|
5296 | 419 |
|
4935 | 420 |
Goal "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
|
421 |
by (induct_tac "xs" 1); |
5316 | 422 |
by Auto_tac; |
3647
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
423 |
qed "set_append"; |
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
424 |
Addsimps[set_append]; |
1812 | 425 |
|
4935 | 426 |
Goal "set l <= set (x#l)"; |
5316 | 427 |
by Auto_tac; |
3647
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
428 |
qed "set_subset_Cons"; |
1936 | 429 |
|
4935 | 430 |
Goal "(set xs = {}) = (xs = [])"; |
3457 | 431 |
by (induct_tac "xs" 1); |
5316 | 432 |
by Auto_tac; |
3647
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
433 |
qed "set_empty"; |
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
434 |
Addsimps [set_empty]; |
2608 | 435 |
|
4935 | 436 |
Goal "set(rev xs) = set(xs)"; |
3457 | 437 |
by (induct_tac "xs" 1); |
5316 | 438 |
by Auto_tac; |
3647
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
439 |
qed "set_rev"; |
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
440 |
Addsimps [set_rev]; |
2608 | 441 |
|
4935 | 442 |
Goal "set(map f xs) = f``(set xs)"; |
3457 | 443 |
by (induct_tac "xs" 1); |
5316 | 444 |
by Auto_tac; |
3647
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
445 |
qed "set_map"; |
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
446 |
Addsimps [set_map]; |
2608 | 447 |
|
6433 | 448 |
Goal "set(filter P xs) = {x. x : set xs & P x}"; |
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
449 |
by (induct_tac "xs" 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
450 |
by Auto_tac; |
6433 | 451 |
qed "set_filter"; |
452 |
Addsimps [set_filter]; |
|
453 |
(* |
|
5443
e2459d18ff47
changed constants mem and list_all to mere translations
oheimb
parents:
5427
diff
changeset
|
454 |
Goal "(x : set (filter P xs)) = (x : set xs & P x)"; |
4605 | 455 |
by (induct_tac "xs" 1); |
5316 | 456 |
by Auto_tac; |
4605 | 457 |
qed "in_set_filter"; |
458 |
Addsimps [in_set_filter]; |
|
6433 | 459 |
*) |
460 |
Goal "set[i..j(] = {k. i <= k & k < j}"; |
|
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
461 |
by (induct_tac "j" 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
462 |
by Auto_tac; |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
463 |
by (arith_tac 1); |
6433 | 464 |
qed "set_upt"; |
465 |
Addsimps [set_upt]; |
|
466 |
||
467 |
Goal "!i < size xs. set(xs[i := x]) <= insert x (set xs)"; |
|
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
468 |
by (induct_tac "xs" 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
469 |
by (Simp_tac 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
470 |
by (asm_simp_tac (simpset() addsplits [nat.split]) 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
471 |
by (Blast_tac 1); |
6433 | 472 |
qed_spec_mp "set_list_update_subset"; |
4605 | 473 |
|
5272 | 474 |
Goal "(x : set xs) = (? ys zs. xs = ys@x#zs)"; |
5318 | 475 |
by (induct_tac "xs" 1); |
476 |
by (Simp_tac 1); |
|
477 |
by (Asm_simp_tac 1); |
|
478 |
by (rtac iffI 1); |
|
479 |
by (blast_tac (claset() addIs [eq_Nil_appendI,Cons_eq_appendI]) 1); |
|
480 |
by (REPEAT(etac exE 1)); |
|
481 |
by (exhaust_tac "ys" 1); |
|
5316 | 482 |
by Auto_tac; |
5272 | 483 |
qed "in_set_conv_decomp"; |
484 |
||
485 |
(* eliminate `lists' in favour of `set' *) |
|
486 |
||
487 |
Goal "(xs : lists A) = (!x : set xs. x : A)"; |
|
5318 | 488 |
by (induct_tac "xs" 1); |
5316 | 489 |
by Auto_tac; |
5272 | 490 |
qed "in_lists_conv_set"; |
491 |
||
492 |
bind_thm("in_listsD",in_lists_conv_set RS iffD1); |
|
493 |
AddSDs [in_listsD]; |
|
494 |
bind_thm("in_listsI",in_lists_conv_set RS iffD2); |
|
495 |
AddSIs [in_listsI]; |
|
1812 | 496 |
|
5518 | 497 |
(** mem **) |
498 |
||
499 |
section "mem"; |
|
500 |
||
501 |
Goal "(x mem xs) = (x: set xs)"; |
|
502 |
by (induct_tac "xs" 1); |
|
503 |
by Auto_tac; |
|
504 |
qed "set_mem_eq"; |
|
505 |
||
506 |
||
923 | 507 |
(** list_all **) |
508 |
||
3467 | 509 |
section "list_all"; |
510 |
||
5518 | 511 |
Goal "list_all P xs = (!x:set xs. P x)"; |
512 |
by (induct_tac "xs" 1); |
|
513 |
by Auto_tac; |
|
514 |
qed "list_all_conv"; |
|
515 |
||
5443
e2459d18ff47
changed constants mem and list_all to mere translations
oheimb
parents:
5427
diff
changeset
|
516 |
Goal "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
|
517 |
by (induct_tac "xs" 1); |
5316 | 518 |
by Auto_tac; |
2512 | 519 |
qed "list_all_append"; |
520 |
Addsimps [list_all_append]; |
|
923 | 521 |
|
522 |
||
2608 | 523 |
(** filter **) |
923 | 524 |
|
3467 | 525 |
section "filter"; |
526 |
||
4935 | 527 |
Goal "filter P (xs@ys) = filter P xs @ filter P ys"; |
3457 | 528 |
by (induct_tac "xs" 1); |
5316 | 529 |
by Auto_tac; |
2608 | 530 |
qed "filter_append"; |
531 |
Addsimps [filter_append]; |
|
532 |
||
4935 | 533 |
Goal "filter (%x. True) xs = xs"; |
4605 | 534 |
by (induct_tac "xs" 1); |
5316 | 535 |
by Auto_tac; |
4605 | 536 |
qed "filter_True"; |
537 |
Addsimps [filter_True]; |
|
538 |
||
4935 | 539 |
Goal "filter (%x. False) xs = []"; |
4605 | 540 |
by (induct_tac "xs" 1); |
5316 | 541 |
by Auto_tac; |
4605 | 542 |
qed "filter_False"; |
543 |
Addsimps [filter_False]; |
|
544 |
||
4935 | 545 |
Goal "length (filter P xs) <= length xs"; |
3457 | 546 |
by (induct_tac "xs" 1); |
5316 | 547 |
by Auto_tac; |
4605 | 548 |
qed "length_filter"; |
5443
e2459d18ff47
changed constants mem and list_all to mere translations
oheimb
parents:
5427
diff
changeset
|
549 |
Addsimps[length_filter]; |
2608 | 550 |
|
5443
e2459d18ff47
changed constants mem and list_all to mere translations
oheimb
parents:
5427
diff
changeset
|
551 |
Goal "set (filter P xs) <= set xs"; |
e2459d18ff47
changed constants mem and list_all to mere translations
oheimb
parents:
5427
diff
changeset
|
552 |
by Auto_tac; |
e2459d18ff47
changed constants mem and list_all to mere translations
oheimb
parents:
5427
diff
changeset
|
553 |
qed "filter_is_subset"; |
e2459d18ff47
changed constants mem and list_all to mere translations
oheimb
parents:
5427
diff
changeset
|
554 |
Addsimps [filter_is_subset]; |
e2459d18ff47
changed constants mem and list_all to mere translations
oheimb
parents:
5427
diff
changeset
|
555 |
|
2608 | 556 |
|
3467 | 557 |
section "concat"; |
558 |
||
4935 | 559 |
Goal "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
|
560 |
by (induct_tac "xs" 1); |
5316 | 561 |
by Auto_tac; |
2608 | 562 |
qed"concat_append"; |
563 |
Addsimps [concat_append]; |
|
2512 | 564 |
|
4935 | 565 |
Goal "(concat xss = []) = (!xs:set xss. xs=[])"; |
4423 | 566 |
by (induct_tac "xss" 1); |
5316 | 567 |
by Auto_tac; |
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
568 |
qed "concat_eq_Nil_conv"; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
569 |
AddIffs [concat_eq_Nil_conv]; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
570 |
|
4935 | 571 |
Goal "([] = concat xss) = (!xs:set xss. xs=[])"; |
4423 | 572 |
by (induct_tac "xss" 1); |
5316 | 573 |
by Auto_tac; |
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
574 |
qed "Nil_eq_concat_conv"; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
575 |
AddIffs [Nil_eq_concat_conv]; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
576 |
|
4935 | 577 |
Goal "set(concat xs) = Union(set `` set xs)"; |
3467 | 578 |
by (induct_tac "xs" 1); |
5316 | 579 |
by Auto_tac; |
3647
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
580 |
qed"set_concat"; |
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
581 |
Addsimps [set_concat]; |
3467 | 582 |
|
4935 | 583 |
Goal "map f (concat xs) = concat (map (map f) xs)"; |
3467 | 584 |
by (induct_tac "xs" 1); |
5316 | 585 |
by Auto_tac; |
3467 | 586 |
qed "map_concat"; |
587 |
||
4935 | 588 |
Goal "filter p (concat xs) = concat (map (filter p) xs)"; |
3467 | 589 |
by (induct_tac "xs" 1); |
5316 | 590 |
by Auto_tac; |
3467 | 591 |
qed"filter_concat"; |
592 |
||
4935 | 593 |
Goal "rev(concat xs) = concat (map rev (rev xs))"; |
3467 | 594 |
by (induct_tac "xs" 1); |
5316 | 595 |
by Auto_tac; |
2608 | 596 |
qed "rev_concat"; |
923 | 597 |
|
598 |
(** nth **) |
|
599 |
||
3467 | 600 |
section "nth"; |
601 |
||
6408 | 602 |
Goal "(x#xs)!0 = x"; |
603 |
by Auto_tac; |
|
604 |
qed "nth_Cons_0"; |
|
605 |
Addsimps [nth_Cons_0]; |
|
5644 | 606 |
|
6408 | 607 |
Goal "(x#xs)!(Suc n) = xs!n"; |
608 |
by Auto_tac; |
|
609 |
qed "nth_Cons_Suc"; |
|
610 |
Addsimps [nth_Cons_Suc]; |
|
611 |
||
612 |
Delsimps (thms "nth.simps"); |
|
613 |
||
614 |
Goal "!n. (xs@ys)!n = (if n < length xs then xs!n else ys!(n - length xs))"; |
|
615 |
by (induct_tac "xs" 1); |
|
3457 | 616 |
by (Asm_simp_tac 1); |
617 |
by (rtac allI 1); |
|
6408 | 618 |
by (exhaust_tac "n" 1); |
5316 | 619 |
by Auto_tac; |
2608 | 620 |
qed_spec_mp "nth_append"; |
621 |
||
4935 | 622 |
Goal "!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
|
623 |
by (induct_tac "xs" 1); |
1301 | 624 |
(* case [] *) |
625 |
by (Asm_full_simp_tac 1); |
|
626 |
(* case x#xl *) |
|
627 |
by (rtac allI 1); |
|
5183 | 628 |
by (induct_tac "n" 1); |
5316 | 629 |
by Auto_tac; |
1485
240cc98b94a7
Added qed_spec_mp to avoid renaming of bound vars in 'th RS spec'
nipkow
parents:
1465
diff
changeset
|
630 |
qed_spec_mp "nth_map"; |
1301 | 631 |
Addsimps [nth_map]; |
632 |
||
5518 | 633 |
Goal "!n. n < length xs --> Ball (set xs) P --> P(xs!n)"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
634 |
by (induct_tac "xs" 1); |
1301 | 635 |
(* case [] *) |
636 |
by (Simp_tac 1); |
|
637 |
(* case x#xl *) |
|
638 |
by (rtac allI 1); |
|
5183 | 639 |
by (induct_tac "n" 1); |
5316 | 640 |
by Auto_tac; |
5518 | 641 |
qed_spec_mp "list_ball_nth"; |
1301 | 642 |
|
5518 | 643 |
Goal "!n. n < length xs --> xs!n : set xs"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
644 |
by (induct_tac "xs" 1); |
1301 | 645 |
(* case [] *) |
646 |
by (Simp_tac 1); |
|
647 |
(* case x#xl *) |
|
648 |
by (rtac allI 1); |
|
5183 | 649 |
by (induct_tac "n" 1); |
1301 | 650 |
(* case 0 *) |
651 |
by (Asm_full_simp_tac 1); |
|
652 |
(* case Suc x *) |
|
4686 | 653 |
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
|
654 |
qed_spec_mp "nth_mem"; |
1301 | 655 |
Addsimps [nth_mem]; |
656 |
||
5518 | 657 |
|
5077
71043526295f
* HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents:
5043
diff
changeset
|
658 |
(** list update **) |
71043526295f
* HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents:
5043
diff
changeset
|
659 |
|
71043526295f
* HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents:
5043
diff
changeset
|
660 |
section "list update"; |
71043526295f
* HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents:
5043
diff
changeset
|
661 |
|
71043526295f
* HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents:
5043
diff
changeset
|
662 |
Goal "!i. length(xs[i:=x]) = length xs"; |
71043526295f
* HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents:
5043
diff
changeset
|
663 |
by (induct_tac "xs" 1); |
71043526295f
* HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents:
5043
diff
changeset
|
664 |
by (Simp_tac 1); |
5183 | 665 |
by (asm_full_simp_tac (simpset() addsplits [nat.split]) 1); |
5077
71043526295f
* HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents:
5043
diff
changeset
|
666 |
qed_spec_mp "length_list_update"; |
71043526295f
* HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents:
5043
diff
changeset
|
667 |
Addsimps [length_list_update]; |
71043526295f
* HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents:
5043
diff
changeset
|
668 |
|
5644 | 669 |
Goal "!i j. i < length xs --> (xs[i:=x])!j = (if i=j then x else xs!j)"; |
6162 | 670 |
by (induct_tac "xs" 1); |
671 |
by (Simp_tac 1); |
|
672 |
by (auto_tac (claset(), simpset() addsimps [nth_Cons] addsplits [nat.split])); |
|
5644 | 673 |
qed_spec_mp "nth_list_update"; |
674 |
||
6433 | 675 |
Goal "!i. i < size xs --> xs[i:=x, i:=y] = xs[i:=y]"; |
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
676 |
by (induct_tac "xs" 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
677 |
by (Simp_tac 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
678 |
by (asm_simp_tac (simpset() addsplits [nat.split]) 1); |
6433 | 679 |
qed_spec_mp "list_update_overwrite"; |
680 |
Addsimps [list_update_overwrite]; |
|
681 |
||
682 |
Goal "!i < length xs. (xs[i := x] = xs) = (xs!i = x)"; |
|
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
683 |
by (induct_tac "xs" 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
684 |
by (Simp_tac 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
685 |
by (simp_tac (simpset() addsplits [nat.split]) 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
686 |
by (Blast_tac 1); |
6433 | 687 |
qed_spec_mp "list_update_same_conv"; |
688 |
||
5077
71043526295f
* HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents:
5043
diff
changeset
|
689 |
|
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
690 |
(** last & butlast **) |
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
691 |
|
5644 | 692 |
section "last / butlast"; |
693 |
||
4935 | 694 |
Goal "last(xs@[x]) = x"; |
4423 | 695 |
by (induct_tac "xs" 1); |
5316 | 696 |
by Auto_tac; |
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
697 |
qed "last_snoc"; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
698 |
Addsimps [last_snoc]; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
699 |
|
4935 | 700 |
Goal "butlast(xs@[x]) = xs"; |
4423 | 701 |
by (induct_tac "xs" 1); |
5316 | 702 |
by Auto_tac; |
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
703 |
qed "butlast_snoc"; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
704 |
Addsimps [butlast_snoc]; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
705 |
|
4935 | 706 |
Goal "length(butlast xs) = length xs - 1"; |
707 |
by (res_inst_tac [("xs","xs")] rev_induct 1); |
|
5316 | 708 |
by Auto_tac; |
4643 | 709 |
qed "length_butlast"; |
710 |
Addsimps [length_butlast]; |
|
711 |
||
5278 | 712 |
Goal "!ys. butlast (xs@ys) = (if ys=[] then butlast xs else xs@butlast ys)"; |
4423 | 713 |
by (induct_tac "xs" 1); |
5316 | 714 |
by Auto_tac; |
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
715 |
qed_spec_mp "butlast_append"; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
716 |
|
4935 | 717 |
Goal "x:set(butlast xs) --> x:set xs"; |
4423 | 718 |
by (induct_tac "xs" 1); |
5316 | 719 |
by Auto_tac; |
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
720 |
qed_spec_mp "in_set_butlastD"; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
721 |
|
5448
40a09282ba14
in_set_butlast_appendI supersedes in_set_butlast_appendI1,2
paulson
parents:
5443
diff
changeset
|
722 |
Goal "x:set(butlast xs) | x:set(butlast ys) ==> x:set(butlast(xs@ys))"; |
40a09282ba14
in_set_butlast_appendI supersedes in_set_butlast_appendI1,2
paulson
parents:
5443
diff
changeset
|
723 |
by (auto_tac (claset() addDs [in_set_butlastD], |
40a09282ba14
in_set_butlast_appendI supersedes in_set_butlast_appendI1,2
paulson
parents:
5443
diff
changeset
|
724 |
simpset() addsimps [butlast_append])); |
40a09282ba14
in_set_butlast_appendI supersedes in_set_butlast_appendI1,2
paulson
parents:
5443
diff
changeset
|
725 |
qed "in_set_butlast_appendI"; |
3902 | 726 |
|
2608 | 727 |
(** take & drop **) |
728 |
section "take & drop"; |
|
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
729 |
|
4935 | 730 |
Goal "take 0 xs = []"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
731 |
by (induct_tac "xs" 1); |
5316 | 732 |
by Auto_tac; |
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
733 |
qed "take_0"; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
734 |
|
4935 | 735 |
Goal "drop 0 xs = xs"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
736 |
by (induct_tac "xs" 1); |
5316 | 737 |
by Auto_tac; |
2608 | 738 |
qed "drop_0"; |
739 |
||
4935 | 740 |
Goal "take (Suc n) (x#xs) = x # take n xs"; |
1552 | 741 |
by (Simp_tac 1); |
1419
a6a034a47a71
defined take/drop by induction over list rather than nat.
nipkow
parents:
1327
diff
changeset
|
742 |
qed "take_Suc_Cons"; |
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
743 |
|
4935 | 744 |
Goal "drop (Suc n) (x#xs) = drop n xs"; |
2608 | 745 |
by (Simp_tac 1); |
746 |
qed "drop_Suc_Cons"; |
|
747 |
||
748 |
Delsimps [take_Cons,drop_Cons]; |
|
749 |
Addsimps [take_0,take_Suc_Cons,drop_0,drop_Suc_Cons]; |
|
750 |
||
4935 | 751 |
Goal "!xs. length(take n xs) = min (length xs) n"; |
5183 | 752 |
by (induct_tac "n" 1); |
5316 | 753 |
by Auto_tac; |
3457 | 754 |
by (exhaust_tac "xs" 1); |
5316 | 755 |
by Auto_tac; |
2608 | 756 |
qed_spec_mp "length_take"; |
757 |
Addsimps [length_take]; |
|
923 | 758 |
|
4935 | 759 |
Goal "!xs. length(drop n xs) = (length xs - n)"; |
5183 | 760 |
by (induct_tac "n" 1); |
5316 | 761 |
by Auto_tac; |
3457 | 762 |
by (exhaust_tac "xs" 1); |
5316 | 763 |
by Auto_tac; |
2608 | 764 |
qed_spec_mp "length_drop"; |
765 |
Addsimps [length_drop]; |
|
766 |
||
4935 | 767 |
Goal "!xs. length xs <= n --> take n xs = xs"; |
5183 | 768 |
by (induct_tac "n" 1); |
5316 | 769 |
by Auto_tac; |
3457 | 770 |
by (exhaust_tac "xs" 1); |
5316 | 771 |
by Auto_tac; |
2608 | 772 |
qed_spec_mp "take_all"; |
7246 | 773 |
Addsimps [take_all]; |
923 | 774 |
|
4935 | 775 |
Goal "!xs. length xs <= n --> drop n xs = []"; |
5183 | 776 |
by (induct_tac "n" 1); |
5316 | 777 |
by Auto_tac; |
3457 | 778 |
by (exhaust_tac "xs" 1); |
5316 | 779 |
by Auto_tac; |
2608 | 780 |
qed_spec_mp "drop_all"; |
7246 | 781 |
Addsimps [drop_all]; |
2608 | 782 |
|
5278 | 783 |
Goal "!xs. take n (xs @ ys) = (take n xs @ take (n - length xs) ys)"; |
5183 | 784 |
by (induct_tac "n" 1); |
5316 | 785 |
by Auto_tac; |
3457 | 786 |
by (exhaust_tac "xs" 1); |
5316 | 787 |
by Auto_tac; |
2608 | 788 |
qed_spec_mp "take_append"; |
789 |
Addsimps [take_append]; |
|
790 |
||
4935 | 791 |
Goal "!xs. drop n (xs@ys) = drop n xs @ drop (n - length xs) ys"; |
5183 | 792 |
by (induct_tac "n" 1); |
5316 | 793 |
by Auto_tac; |
3457 | 794 |
by (exhaust_tac "xs" 1); |
5316 | 795 |
by Auto_tac; |
2608 | 796 |
qed_spec_mp "drop_append"; |
797 |
Addsimps [drop_append]; |
|
798 |
||
4935 | 799 |
Goal "!xs n. take n (take m xs) = take (min n m) xs"; |
5183 | 800 |
by (induct_tac "m" 1); |
5316 | 801 |
by Auto_tac; |
3457 | 802 |
by (exhaust_tac "xs" 1); |
5316 | 803 |
by Auto_tac; |
5183 | 804 |
by (exhaust_tac "na" 1); |
5316 | 805 |
by Auto_tac; |
2608 | 806 |
qed_spec_mp "take_take"; |
807 |
||
4935 | 808 |
Goal "!xs. drop n (drop m xs) = drop (n + m) xs"; |
5183 | 809 |
by (induct_tac "m" 1); |
5316 | 810 |
by Auto_tac; |
3457 | 811 |
by (exhaust_tac "xs" 1); |
5316 | 812 |
by Auto_tac; |
2608 | 813 |
qed_spec_mp "drop_drop"; |
923 | 814 |
|
4935 | 815 |
Goal "!xs n. take n (drop m xs) = drop m (take (n + m) xs)"; |
5183 | 816 |
by (induct_tac "m" 1); |
5316 | 817 |
by Auto_tac; |
3457 | 818 |
by (exhaust_tac "xs" 1); |
5316 | 819 |
by Auto_tac; |
2608 | 820 |
qed_spec_mp "take_drop"; |
821 |
||
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
822 |
Goal "!xs. take n xs @ drop n xs = xs"; |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
823 |
by (induct_tac "n" 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
824 |
by Auto_tac; |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
825 |
by (exhaust_tac "xs" 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
826 |
by Auto_tac; |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
827 |
qed_spec_mp "append_take_drop_id"; |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
828 |
|
4935 | 829 |
Goal "!xs. take n (map f xs) = map f (take n xs)"; |
5183 | 830 |
by (induct_tac "n" 1); |
5316 | 831 |
by Auto_tac; |
3457 | 832 |
by (exhaust_tac "xs" 1); |
5316 | 833 |
by Auto_tac; |
2608 | 834 |
qed_spec_mp "take_map"; |
835 |
||
4935 | 836 |
Goal "!xs. drop n (map f xs) = map f (drop n xs)"; |
5183 | 837 |
by (induct_tac "n" 1); |
5316 | 838 |
by Auto_tac; |
3457 | 839 |
by (exhaust_tac "xs" 1); |
5316 | 840 |
by Auto_tac; |
2608 | 841 |
qed_spec_mp "drop_map"; |
842 |
||
4935 | 843 |
Goal "!n i. i < n --> (take n xs)!i = xs!i"; |
3457 | 844 |
by (induct_tac "xs" 1); |
5316 | 845 |
by Auto_tac; |
3457 | 846 |
by (exhaust_tac "n" 1); |
847 |
by (Blast_tac 1); |
|
848 |
by (exhaust_tac "i" 1); |
|
5316 | 849 |
by Auto_tac; |
2608 | 850 |
qed_spec_mp "nth_take"; |
851 |
Addsimps [nth_take]; |
|
923 | 852 |
|
4935 | 853 |
Goal "!xs i. n + i <= length xs --> (drop n xs)!i = xs!(n+i)"; |
5183 | 854 |
by (induct_tac "n" 1); |
5316 | 855 |
by Auto_tac; |
3457 | 856 |
by (exhaust_tac "xs" 1); |
5316 | 857 |
by Auto_tac; |
2608 | 858 |
qed_spec_mp "nth_drop"; |
859 |
Addsimps [nth_drop]; |
|
860 |
||
861 |
(** takeWhile & dropWhile **) |
|
862 |
||
3467 | 863 |
section "takeWhile & dropWhile"; |
864 |
||
4935 | 865 |
Goal "takeWhile P xs @ dropWhile P xs = xs"; |
3586 | 866 |
by (induct_tac "xs" 1); |
5316 | 867 |
by Auto_tac; |
3586 | 868 |
qed "takeWhile_dropWhile_id"; |
869 |
Addsimps [takeWhile_dropWhile_id]; |
|
870 |
||
4935 | 871 |
Goal "x:set xs & ~P(x) --> takeWhile P (xs @ ys) = takeWhile P xs"; |
3457 | 872 |
by (induct_tac "xs" 1); |
5316 | 873 |
by Auto_tac; |
2608 | 874 |
bind_thm("takeWhile_append1", conjI RS (result() RS mp)); |
875 |
Addsimps [takeWhile_append1]; |
|
923 | 876 |
|
4935 | 877 |
Goal "(!x:set xs. P(x)) --> takeWhile P (xs @ ys) = xs @ takeWhile P ys"; |
3457 | 878 |
by (induct_tac "xs" 1); |
5316 | 879 |
by Auto_tac; |
2608 | 880 |
bind_thm("takeWhile_append2", ballI RS (result() RS mp)); |
881 |
Addsimps [takeWhile_append2]; |
|
1169 | 882 |
|
4935 | 883 |
Goal "x:set xs & ~P(x) --> dropWhile P (xs @ ys) = (dropWhile P xs)@ys"; |
3457 | 884 |
by (induct_tac "xs" 1); |
5316 | 885 |
by Auto_tac; |
2608 | 886 |
bind_thm("dropWhile_append1", conjI RS (result() RS mp)); |
887 |
Addsimps [dropWhile_append1]; |
|
888 |
||
4935 | 889 |
Goal "(!x:set xs. P(x)) --> dropWhile P (xs @ ys) = dropWhile P ys"; |
3457 | 890 |
by (induct_tac "xs" 1); |
5316 | 891 |
by Auto_tac; |
2608 | 892 |
bind_thm("dropWhile_append2", ballI RS (result() RS mp)); |
893 |
Addsimps [dropWhile_append2]; |
|
894 |
||
4935 | 895 |
Goal "x:set(takeWhile P xs) --> x:set xs & P x"; |
3457 | 896 |
by (induct_tac "xs" 1); |
5316 | 897 |
by Auto_tac; |
3647
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
898 |
qed_spec_mp"set_take_whileD"; |
2608 | 899 |
|
6306 | 900 |
(** zip **) |
901 |
section "zip"; |
|
902 |
||
903 |
Goal "zip [] ys = []"; |
|
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
904 |
by (induct_tac "ys" 1); |
6306 | 905 |
by Auto_tac; |
906 |
qed "zip_Nil"; |
|
907 |
Addsimps [zip_Nil]; |
|
908 |
||
909 |
Goal "zip (x#xs) (y#ys) = (x,y)#zip xs ys"; |
|
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
910 |
by (Simp_tac 1); |
6306 | 911 |
qed "zip_Cons_Cons"; |
912 |
Addsimps [zip_Cons_Cons]; |
|
913 |
||
914 |
Delsimps(tl (thms"zip.simps")); |
|
4605 | 915 |
|
5272 | 916 |
|
917 |
(** foldl **) |
|
918 |
section "foldl"; |
|
919 |
||
920 |
Goal "!a. foldl f a (xs @ ys) = foldl f (foldl f a xs) ys"; |
|
5318 | 921 |
by (induct_tac "xs" 1); |
5316 | 922 |
by Auto_tac; |
5272 | 923 |
qed_spec_mp "foldl_append"; |
924 |
Addsimps [foldl_append]; |
|
925 |
||
926 |
(* Note: `n <= foldl op+ n ns' looks simpler, but is more difficult to use |
|
927 |
because it requires an additional transitivity step |
|
928 |
*) |
|
929 |
Goal "!n::nat. m <= n --> m <= foldl op+ n ns"; |
|
5318 | 930 |
by (induct_tac "ns" 1); |
6058 | 931 |
by Auto_tac; |
5272 | 932 |
qed_spec_mp "start_le_sum"; |
933 |
||
934 |
Goal "n : set ns ==> n <= foldl op+ 0 ns"; |
|
5758
27a2b36efd95
corrected auto_tac (applications of unsafe wrappers)
oheimb
parents:
5644
diff
changeset
|
935 |
by (force_tac (claset() addIs [start_le_sum], |
27a2b36efd95
corrected auto_tac (applications of unsafe wrappers)
oheimb
parents:
5644
diff
changeset
|
936 |
simpset() addsimps [in_set_conv_decomp]) 1); |
5272 | 937 |
qed "elem_le_sum"; |
938 |
||
939 |
Goal "!m. (foldl op+ m ns = 0) = (m=0 & (!n : set ns. n=0))"; |
|
5318 | 940 |
by (induct_tac "ns" 1); |
5316 | 941 |
by Auto_tac; |
5272 | 942 |
qed_spec_mp "sum_eq_0_conv"; |
943 |
AddIffs [sum_eq_0_conv]; |
|
944 |
||
5425 | 945 |
(** upto **) |
946 |
||
5427 | 947 |
(* Does not terminate! *) |
948 |
Goal "[i..j(] = (if i<j then i#[Suc i..j(] else [])"; |
|
6162 | 949 |
by (induct_tac "j" 1); |
5427 | 950 |
by Auto_tac; |
951 |
qed "upt_rec"; |
|
5425 | 952 |
|
5427 | 953 |
Goal "j<=i ==> [i..j(] = []"; |
6162 | 954 |
by (stac upt_rec 1); |
955 |
by (Asm_simp_tac 1); |
|
5427 | 956 |
qed "upt_conv_Nil"; |
957 |
Addsimps [upt_conv_Nil]; |
|
958 |
||
959 |
Goal "i<=j ==> [i..(Suc j)(] = [i..j(]@[j]"; |
|
960 |
by (Asm_simp_tac 1); |
|
961 |
qed "upt_Suc"; |
|
962 |
||
963 |
Goal "i<j ==> [i..j(] = i#[Suc i..j(]"; |
|
6162 | 964 |
by (rtac trans 1); |
965 |
by (stac upt_rec 1); |
|
966 |
by (rtac refl 2); |
|
5427 | 967 |
by (Asm_simp_tac 1); |
968 |
qed "upt_conv_Cons"; |
|
969 |
||
970 |
Goal "length [i..j(] = j-i"; |
|
6162 | 971 |
by (induct_tac "j" 1); |
5427 | 972 |
by (Simp_tac 1); |
6162 | 973 |
by (asm_simp_tac (simpset() addsimps [Suc_diff_le]) 1); |
5427 | 974 |
qed "length_upt"; |
975 |
Addsimps [length_upt]; |
|
5425 | 976 |
|
5427 | 977 |
Goal "i+k < j --> [i..j(] ! k = i+k"; |
6162 | 978 |
by (induct_tac "j" 1); |
979 |
by (Simp_tac 1); |
|
980 |
by (asm_simp_tac (simpset() addsimps [nth_append,less_diff_conv]@add_ac) 1); |
|
981 |
by (Clarify_tac 1); |
|
982 |
by (subgoal_tac "n=i+k" 1); |
|
983 |
by (Asm_simp_tac 2); |
|
984 |
by (Asm_simp_tac 1); |
|
5427 | 985 |
qed_spec_mp "nth_upt"; |
986 |
Addsimps [nth_upt]; |
|
5425 | 987 |
|
6433 | 988 |
Goal "!i. i+m <= n --> take m [i..n(] = [i..i+m(]"; |
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
989 |
by (induct_tac "m" 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
990 |
by (Simp_tac 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
991 |
by (Clarify_tac 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
992 |
by (stac upt_rec 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
993 |
by (rtac sym 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
994 |
by (stac upt_rec 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
995 |
by (asm_simp_tac (simpset() delsimps (thms"upt.simps")) 1); |
6433 | 996 |
qed_spec_mp "take_upt"; |
997 |
Addsimps [take_upt]; |
|
998 |
||
999 |
Goal "!m i. i < n-m --> (map f [m..n(]) ! i = f(m+i)"; |
|
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1000 |
by (induct_tac "n" 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1001 |
by (Simp_tac 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1002 |
by (Clarify_tac 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1003 |
by (subgoal_tac "m < Suc n" 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1004 |
by (arith_tac 2); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1005 |
by (stac upt_rec 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1006 |
by (asm_simp_tac (simpset() delsplits [split_if]) 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1007 |
by (split_tac [split_if] 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1008 |
by (rtac conjI 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1009 |
by (simp_tac (simpset() addsimps [nth_Cons] addsplits [nat.split]) 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1010 |
by (simp_tac (simpset() addsimps [nth_append] addsplits [nat.split]) 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1011 |
by (Clarify_tac 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1012 |
by (rtac conjI 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1013 |
by (Clarify_tac 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1014 |
by (subgoal_tac "Suc(m+nat) < n" 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1015 |
by (arith_tac 2); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1016 |
by (Asm_simp_tac 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1017 |
by (Clarify_tac 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1018 |
by (subgoal_tac "n = Suc(m+nat)" 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1019 |
by (arith_tac 2); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1020 |
by (Asm_simp_tac 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1021 |
by (simp_tac (simpset() addsimps [nth_Cons] addsplits [nat.split]) 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1022 |
by (arith_tac 1); |
6433 | 1023 |
qed_spec_mp "nth_map_upt"; |
1024 |
||
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1025 |
Goal "ALL xs ys. k <= length xs --> k <= length ys --> \ |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1026 |
\ (ALL i. i < k --> xs!i = ys!i) \ |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1027 |
\ --> take k xs = take k ys"; |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1028 |
by (induct_tac "k" 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1029 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [less_Suc_eq_0_disj, |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1030 |
all_conj_distrib]))); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1031 |
by (Clarify_tac 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1032 |
(*Both lists must be non-empty*) |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1033 |
by (exhaust_tac "xs" 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1034 |
by (exhaust_tac "ys" 2); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1035 |
by (ALLGOALS Clarify_tac); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1036 |
(*prenexing's needed, not miniscoping*) |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1037 |
by (ALLGOALS (full_simp_tac (simpset() addsimps (all_simps RL [sym]) |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1038 |
delsimps (all_simps)))); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1039 |
by (Blast_tac 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1040 |
qed_spec_mp "nth_take_lemma"; |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1041 |
|
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1042 |
Goal "[| length xs = length ys; \ |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1043 |
\ ALL i. i < length xs --> xs!i = ys!i |] \ |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1044 |
\ ==> xs = ys"; |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1045 |
by (forward_tac [[le_refl, eq_imp_le] MRS nth_take_lemma] 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1046 |
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [take_all]))); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1047 |
qed_spec_mp "nth_equalityI"; |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1048 |
|
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1049 |
(*The famous take-lemma*) |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1050 |
Goal "(ALL i. take i xs = take i ys) ==> xs = ys"; |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1051 |
by (dres_inst_tac [("x", "max (length xs) (length ys)")] spec 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1052 |
by (full_simp_tac (simpset() addsimps [le_max_iff_disj, take_all]) 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1053 |
qed_spec_mp "take_equalityI"; |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1054 |
|
5272 | 1055 |
|
4605 | 1056 |
(** nodups & remdups **) |
1057 |
section "nodups & remdups"; |
|
1058 |
||
4935 | 1059 |
Goal "set(remdups xs) = set xs"; |
4605 | 1060 |
by (induct_tac "xs" 1); |
1061 |
by (Simp_tac 1); |
|
4686 | 1062 |
by (asm_full_simp_tac (simpset() addsimps [insert_absorb]) 1); |
4605 | 1063 |
qed "set_remdups"; |
1064 |
Addsimps [set_remdups]; |
|
1065 |
||
4935 | 1066 |
Goal "nodups(remdups xs)"; |
4605 | 1067 |
by (induct_tac "xs" 1); |
5316 | 1068 |
by Auto_tac; |
4605 | 1069 |
qed "nodups_remdups"; |
1070 |
||
4935 | 1071 |
Goal "nodups xs --> nodups (filter P xs)"; |
4605 | 1072 |
by (induct_tac "xs" 1); |
5316 | 1073 |
by Auto_tac; |
4605 | 1074 |
qed_spec_mp "nodups_filter"; |
1075 |
||
3589
244daa75f890
Added function `replicate' and lemmas map_cong and set_replicate.
nipkow
parents:
3586
diff
changeset
|
1076 |
(** replicate **) |
244daa75f890
Added function `replicate' and lemmas map_cong and set_replicate.
nipkow
parents:
3586
diff
changeset
|
1077 |
section "replicate"; |
244daa75f890
Added function `replicate' and lemmas map_cong and set_replicate.
nipkow
parents:
3586
diff
changeset
|
1078 |
|
6794 | 1079 |
Goal "length(replicate n x) = n"; |
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1080 |
by (induct_tac "n" 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1081 |
by Auto_tac; |
6794 | 1082 |
qed "length_replicate"; |
1083 |
Addsimps [length_replicate]; |
|
1084 |
||
1085 |
Goal "map f (replicate n x) = replicate n (f x)"; |
|
1086 |
by (induct_tac "n" 1); |
|
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1087 |
by Auto_tac; |
6794 | 1088 |
qed "map_replicate"; |
1089 |
Addsimps [map_replicate]; |
|
1090 |
||
1091 |
Goal "(replicate n x) @ (x#xs) = x # replicate n x @ xs"; |
|
1092 |
by (induct_tac "n" 1); |
|
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1093 |
by Auto_tac; |
6794 | 1094 |
qed "replicate_app_Cons_same"; |
1095 |
||
1096 |
Goal "rev(replicate n x) = replicate n x"; |
|
1097 |
by (induct_tac "n" 1); |
|
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1098 |
by (Simp_tac 1); |
6794 | 1099 |
by (asm_simp_tac (simpset() addsimps [replicate_app_Cons_same]) 1); |
1100 |
qed "rev_replicate"; |
|
1101 |
Addsimps [rev_replicate]; |
|
1102 |
||
1103 |
Goal"n ~= 0 --> hd(replicate n x) = x"; |
|
1104 |
by (induct_tac "n" 1); |
|
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1105 |
by Auto_tac; |
6794 | 1106 |
qed_spec_mp "hd_replicate"; |
1107 |
Addsimps [hd_replicate]; |
|
1108 |
||
1109 |
Goal "n ~= 0 --> tl(replicate n x) = replicate (n-1) x"; |
|
1110 |
by (induct_tac "n" 1); |
|
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1111 |
by Auto_tac; |
6794 | 1112 |
qed_spec_mp "tl_replicate"; |
1113 |
Addsimps [tl_replicate]; |
|
1114 |
||
1115 |
Goal "n ~= 0 --> last(replicate n x) = x"; |
|
1116 |
by (induct_tac "n" 1); |
|
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1117 |
by Auto_tac; |
6794 | 1118 |
qed_spec_mp "last_replicate"; |
1119 |
Addsimps [last_replicate]; |
|
1120 |
||
1121 |
Goal "!i. i<n --> (replicate n x)!i = x"; |
|
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1122 |
by (induct_tac "n" 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1123 |
by (Simp_tac 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1124 |
by (asm_simp_tac (simpset() addsimps [nth_Cons] addsplits [nat.split]) 1); |
6794 | 1125 |
qed_spec_mp "nth_replicate"; |
1126 |
Addsimps [nth_replicate]; |
|
1127 |
||
4935 | 1128 |
Goal "set(replicate (Suc n) x) = {x}"; |
4423 | 1129 |
by (induct_tac "n" 1); |
5316 | 1130 |
by Auto_tac; |
3589
244daa75f890
Added function `replicate' and lemmas map_cong and set_replicate.
nipkow
parents:
3586
diff
changeset
|
1131 |
val lemma = result(); |
244daa75f890
Added function `replicate' and lemmas map_cong and set_replicate.
nipkow
parents:
3586
diff
changeset
|
1132 |
|
5043 | 1133 |
Goal "n ~= 0 ==> set(replicate n x) = {x}"; |
4423 | 1134 |
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
|
1135 |
qed "set_replicate"; |
244daa75f890
Added function `replicate' and lemmas map_cong and set_replicate.
nipkow
parents:
3586
diff
changeset
|
1136 |
Addsimps [set_replicate]; |
5162 | 1137 |
|
6794 | 1138 |
Goal "replicate (n+m) x = replicate n x @ replicate m x"; |
1139 |
by (induct_tac "n" 1); |
|
1140 |
by Auto_tac; |
|
1141 |
qed "replicate_add"; |
|
5162 | 1142 |
|
5281 | 1143 |
(*** Lexcicographic orderings on lists ***) |
1144 |
section"Lexcicographic orderings on lists"; |
|
1145 |
||
1146 |
Goal "wf r ==> wf(lexn r n)"; |
|
5318 | 1147 |
by (induct_tac "n" 1); |
1148 |
by (Simp_tac 1); |
|
1149 |
by (Simp_tac 1); |
|
1150 |
by (rtac wf_subset 1); |
|
1151 |
by (rtac Int_lower1 2); |
|
1152 |
by (rtac wf_prod_fun_image 1); |
|
1153 |
by (rtac injI 2); |
|
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1154 |
by Auto_tac; |
5281 | 1155 |
qed "wf_lexn"; |
1156 |
||
1157 |
Goal "!xs ys. (xs,ys) : lexn r n --> length xs = n & length ys = n"; |
|
5318 | 1158 |
by (induct_tac "n" 1); |
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1159 |
by Auto_tac; |
5281 | 1160 |
qed_spec_mp "lexn_length"; |
1161 |
||
1162 |
Goalw [lex_def] "wf r ==> wf(lex r)"; |
|
5318 | 1163 |
by (rtac wf_UN 1); |
1164 |
by (blast_tac (claset() addIs [wf_lexn]) 1); |
|
1165 |
by (Clarify_tac 1); |
|
1166 |
by (rename_tac "m n" 1); |
|
1167 |
by (subgoal_tac "m ~= n" 1); |
|
1168 |
by (Blast_tac 2); |
|
1169 |
by (blast_tac (claset() addDs [lexn_length,not_sym]) 1); |
|
5281 | 1170 |
qed "wf_lex"; |
1171 |
AddSIs [wf_lex]; |
|
1172 |
||
1173 |
Goal |
|
1174 |
"lexn r n = \ |
|
1175 |
\ {(xs,ys). length xs = n & length ys = n & \ |
|
1176 |
\ (? xys x y xs' ys'. xs= xys @ x#xs' & ys= xys @ y#ys' & (x,y):r)}"; |
|
5318 | 1177 |
by (induct_tac "n" 1); |
1178 |
by (Simp_tac 1); |
|
1179 |
by (Blast_tac 1); |
|
5641 | 1180 |
by (asm_full_simp_tac (simpset() |
5296 | 1181 |
addsimps [lex_prod_def]) 1); |
5641 | 1182 |
by (auto_tac (claset(), simpset())); |
5318 | 1183 |
by (Blast_tac 1); |
1184 |
by (rename_tac "a xys x xs' y ys'" 1); |
|
1185 |
by (res_inst_tac [("x","a#xys")] exI 1); |
|
1186 |
by (Simp_tac 1); |
|
1187 |
by (exhaust_tac "xys" 1); |
|
5641 | 1188 |
by (ALLGOALS (asm_full_simp_tac (simpset()))); |
5318 | 1189 |
by (Blast_tac 1); |
5281 | 1190 |
qed "lexn_conv"; |
1191 |
||
1192 |
Goalw [lex_def] |
|
1193 |
"lex r = \ |
|
1194 |
\ {(xs,ys). length xs = length ys & \ |
|
1195 |
\ (? xys x y xs' ys'. xs= xys @ x#xs' & ys= xys @ y#ys' & (x,y):r)}"; |
|
5641 | 1196 |
by (force_tac (claset(), simpset() addsimps [lexn_conv]) 1); |
5281 | 1197 |
qed "lex_conv"; |
1198 |
||
1199 |
Goalw [lexico_def] "wf r ==> wf(lexico r)"; |
|
5318 | 1200 |
by (Blast_tac 1); |
5281 | 1201 |
qed "wf_lexico"; |
1202 |
AddSIs [wf_lexico]; |
|
1203 |
||
1204 |
Goalw |
|
1205 |
[lexico_def,diag_def,lex_prod_def,measure_def,inv_image_def] |
|
1206 |
"lexico r = {(xs,ys). length xs < length ys | \ |
|
1207 |
\ length xs = length ys & (xs,ys) : lex r}"; |
|
5318 | 1208 |
by (Simp_tac 1); |
5281 | 1209 |
qed "lexico_conv"; |
1210 |
||
5283 | 1211 |
Goal "([],ys) ~: lex r"; |
5318 | 1212 |
by (simp_tac (simpset() addsimps [lex_conv]) 1); |
5283 | 1213 |
qed "Nil_notin_lex"; |
1214 |
||
1215 |
Goal "(xs,[]) ~: lex r"; |
|
5318 | 1216 |
by (simp_tac (simpset() addsimps [lex_conv]) 1); |
5283 | 1217 |
qed "Nil2_notin_lex"; |
1218 |
||
1219 |
AddIffs [Nil_notin_lex,Nil2_notin_lex]; |
|
1220 |
||
1221 |
Goal "((x#xs,y#ys) : lex r) = \ |
|
1222 |
\ ((x,y) : r & length xs = length ys | x=y & (xs,ys) : lex r)"; |
|
5318 | 1223 |
by (simp_tac (simpset() addsimps [lex_conv]) 1); |
1224 |
by (rtac iffI 1); |
|
1225 |
by (blast_tac (claset() addIs [Cons_eq_appendI]) 2); |
|
1226 |
by (REPEAT(eresolve_tac [conjE, exE] 1)); |
|
1227 |
by (exhaust_tac "xys" 1); |
|
1228 |
by (Asm_full_simp_tac 1); |
|
1229 |
by (Asm_full_simp_tac 1); |
|
1230 |
by (Blast_tac 1); |
|
5283 | 1231 |
qed "Cons_in_lex"; |
1232 |
AddIffs [Cons_in_lex]; |
|
7032 | 1233 |
|
1234 |
||
1235 |
(*** Versions of some theorems above using binary numerals ***) |
|
1236 |
||
1237 |
AddIffs (map (rename_numerals thy) |
|
1238 |
[length_0_conv, zero_length_conv, length_greater_0_conv, |
|
1239 |
sum_eq_0_conv]); |
|
1240 |
||
1241 |
Goal "take n (x#xs) = (if n = #0 then [] else x # take (n-#1) xs)"; |
|
1242 |
by (exhaust_tac "n" 1); |
|
1243 |
by (ALLGOALS |
|
1244 |
(asm_simp_tac (simpset() addsimps [numeral_0_eq_0, numeral_1_eq_1]))); |
|
1245 |
qed "take_Cons'"; |
|
1246 |
||
1247 |
Goal "drop n (x#xs) = (if n = #0 then x#xs else drop (n-#1) xs)"; |
|
1248 |
by (exhaust_tac "n" 1); |
|
1249 |
by (ALLGOALS |
|
1250 |
(asm_simp_tac (simpset() addsimps [numeral_0_eq_0, numeral_1_eq_1]))); |
|
1251 |
qed "drop_Cons'"; |
|
1252 |
||
1253 |
Goal "(x#xs)!n = (if n = #0 then x else xs!(n-#1))"; |
|
1254 |
by (exhaust_tac "n" 1); |
|
1255 |
by (ALLGOALS |
|
1256 |
(asm_simp_tac (simpset() addsimps [numeral_0_eq_0, numeral_1_eq_1]))); |
|
1257 |
qed "nth_Cons'"; |
|
1258 |
||
1259 |
Addsimps (map (inst "n" "number_of ?v") [take_Cons', drop_Cons', nth_Cons']); |
|
1260 |