author | wenzelm |
Sat, 02 Sep 2000 21:56:24 +0200 | |
changeset 9811 | 39ffdb8cab03 |
parent 9763 | 252c690690b0 |
child 9853 | 5c6425d83501 |
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 |
|
9108 | 35 |
bind_thm ("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 |
||
9268 | 51 |
Goal "(xs@ys : lists A) = (xs : lists A & ys : lists A)"; |
52 |
by(induct_tac "xs" 1); |
|
53 |
by(Auto_tac); |
|
54 |
qed "append_in_lists_conv"; |
|
55 |
AddIffs [append_in_lists_conv]; |
|
2608 | 56 |
|
3860 | 57 |
(** length **) |
58 |
(* needs to come before "@" because of thm append_eq_append_conv *) |
|
59 |
||
60 |
section "length"; |
|
61 |
||
4935 | 62 |
Goal "length(xs@ys) = length(xs)+length(ys)"; |
3860 | 63 |
by (induct_tac "xs" 1); |
5316 | 64 |
by Auto_tac; |
3860 | 65 |
qed"length_append"; |
66 |
Addsimps [length_append]; |
|
67 |
||
5129 | 68 |
Goal "length (map f xs) = length xs"; |
69 |
by (induct_tac "xs" 1); |
|
5316 | 70 |
by Auto_tac; |
3860 | 71 |
qed "length_map"; |
72 |
Addsimps [length_map]; |
|
73 |
||
4935 | 74 |
Goal "length(rev xs) = length(xs)"; |
3860 | 75 |
by (induct_tac "xs" 1); |
5316 | 76 |
by Auto_tac; |
3860 | 77 |
qed "length_rev"; |
78 |
Addsimps [length_rev]; |
|
79 |
||
7028 | 80 |
Goal "length(tl xs) = (length xs) - 1"; |
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
81 |
by (case_tac "xs" 1); |
5316 | 82 |
by Auto_tac; |
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
83 |
qed "length_tl"; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
84 |
Addsimps [length_tl]; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
85 |
|
4935 | 86 |
Goal "(length xs = 0) = (xs = [])"; |
3860 | 87 |
by (induct_tac "xs" 1); |
5316 | 88 |
by Auto_tac; |
3860 | 89 |
qed "length_0_conv"; |
90 |
AddIffs [length_0_conv]; |
|
91 |
||
4935 | 92 |
Goal "(0 = length xs) = (xs = [])"; |
3860 | 93 |
by (induct_tac "xs" 1); |
5316 | 94 |
by Auto_tac; |
3860 | 95 |
qed "zero_length_conv"; |
96 |
AddIffs [zero_length_conv]; |
|
97 |
||
4935 | 98 |
Goal "(0 < length xs) = (xs ~= [])"; |
3860 | 99 |
by (induct_tac "xs" 1); |
5316 | 100 |
by Auto_tac; |
3860 | 101 |
qed "length_greater_0_conv"; |
102 |
AddIffs [length_greater_0_conv]; |
|
103 |
||
5296 | 104 |
Goal "(length xs = Suc n) = (? y ys. xs = y#ys & length ys = n)"; |
105 |
by (induct_tac "xs" 1); |
|
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
106 |
by Auto_tac; |
5296 | 107 |
qed "length_Suc_conv"; |
108 |
||
923 | 109 |
(** @ - append **) |
110 |
||
3467 | 111 |
section "@ - append"; |
112 |
||
4935 | 113 |
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
|
114 |
by (induct_tac "xs" 1); |
5316 | 115 |
by Auto_tac; |
923 | 116 |
qed "append_assoc"; |
2512 | 117 |
Addsimps [append_assoc]; |
923 | 118 |
|
4935 | 119 |
Goal "xs @ [] = xs"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
120 |
by (induct_tac "xs" 1); |
5316 | 121 |
by Auto_tac; |
923 | 122 |
qed "append_Nil2"; |
2512 | 123 |
Addsimps [append_Nil2]; |
923 | 124 |
|
4935 | 125 |
Goal "(xs@ys = []) = (xs=[] & ys=[])"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
126 |
by (induct_tac "xs" 1); |
5316 | 127 |
by Auto_tac; |
2608 | 128 |
qed "append_is_Nil_conv"; |
129 |
AddIffs [append_is_Nil_conv]; |
|
130 |
||
4935 | 131 |
Goal "([] = xs@ys) = (xs=[] & ys=[])"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
132 |
by (induct_tac "xs" 1); |
5316 | 133 |
by Auto_tac; |
2608 | 134 |
qed "Nil_is_append_conv"; |
135 |
AddIffs [Nil_is_append_conv]; |
|
923 | 136 |
|
4935 | 137 |
Goal "(xs @ ys = xs) = (ys=[])"; |
3574 | 138 |
by (induct_tac "xs" 1); |
5316 | 139 |
by Auto_tac; |
3574 | 140 |
qed "append_self_conv"; |
141 |
||
4935 | 142 |
Goal "(xs = xs @ ys) = (ys=[])"; |
3574 | 143 |
by (induct_tac "xs" 1); |
5316 | 144 |
by Auto_tac; |
3574 | 145 |
qed "self_append_conv"; |
146 |
AddIffs [append_self_conv,self_append_conv]; |
|
147 |
||
4935 | 148 |
Goal "!ys. length xs = length ys | length us = length vs \ |
3860 | 149 |
\ --> (xs@us = ys@vs) = (xs=ys & us=vs)"; |
4423 | 150 |
by (induct_tac "xs" 1); |
151 |
by (rtac allI 1); |
|
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
152 |
by (case_tac "ys" 1); |
4423 | 153 |
by (Asm_simp_tac 1); |
5641 | 154 |
by (Force_tac 1); |
4423 | 155 |
by (rtac allI 1); |
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
156 |
by (case_tac "ys" 1); |
5641 | 157 |
by (Force_tac 1); |
4423 | 158 |
by (Asm_simp_tac 1); |
3860 | 159 |
qed_spec_mp "append_eq_append_conv"; |
160 |
Addsimps [append_eq_append_conv]; |
|
161 |
||
4935 | 162 |
Goal "(xs @ ys = xs @ zs) = (ys=zs)"; |
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
163 |
by (Simp_tac 1); |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
164 |
qed "same_append_eq"; |
3860 | 165 |
|
4935 | 166 |
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
|
167 |
by (Simp_tac 1); |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
168 |
qed "append1_eq_conv"; |
2608 | 169 |
|
4935 | 170 |
Goal "(ys @ xs = zs @ xs) = (ys=zs)"; |
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
171 |
by (Simp_tac 1); |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
172 |
qed "append_same_eq"; |
2608 | 173 |
|
9003 | 174 |
AddIffs [same_append_eq, append1_eq_conv, append_same_eq]; |
3571 | 175 |
|
4935 | 176 |
Goal "(xs @ ys = ys) = (xs=[])"; |
5132 | 177 |
by (cut_inst_tac [("zs","[]")] append_same_eq 1); |
5316 | 178 |
by Auto_tac; |
4647 | 179 |
qed "append_self_conv2"; |
180 |
||
4935 | 181 |
Goal "(ys = xs @ ys) = (xs=[])"; |
5132 | 182 |
by (simp_tac (simpset() addsimps |
4647 | 183 |
[simplify (simpset()) (read_instantiate[("ys","[]")]append_same_eq)]) 1); |
5132 | 184 |
by (Blast_tac 1); |
4647 | 185 |
qed "self_append_conv2"; |
186 |
AddIffs [append_self_conv2,self_append_conv2]; |
|
187 |
||
4935 | 188 |
Goal "xs ~= [] --> hd xs # tl xs = xs"; |
3457 | 189 |
by (induct_tac "xs" 1); |
5316 | 190 |
by Auto_tac; |
2608 | 191 |
qed_spec_mp "hd_Cons_tl"; |
192 |
Addsimps [hd_Cons_tl]; |
|
923 | 193 |
|
4935 | 194 |
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
|
195 |
by (induct_tac "xs" 1); |
5316 | 196 |
by Auto_tac; |
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
197 |
qed "hd_append"; |
923 | 198 |
|
5043 | 199 |
Goal "xs ~= [] ==> hd(xs @ ys) = hd xs"; |
4089 | 200 |
by (asm_simp_tac (simpset() addsimps [hd_append] |
5183 | 201 |
addsplits [list.split]) 1); |
3571 | 202 |
qed "hd_append2"; |
203 |
Addsimps [hd_append2]; |
|
204 |
||
4935 | 205 |
Goal "tl(xs@ys) = (case xs of [] => tl(ys) | z#zs => zs@ys)"; |
5183 | 206 |
by (simp_tac (simpset() addsplits [list.split]) 1); |
2608 | 207 |
qed "tl_append"; |
208 |
||
5043 | 209 |
Goal "xs ~= [] ==> tl(xs @ ys) = (tl xs) @ ys"; |
4089 | 210 |
by (asm_simp_tac (simpset() addsimps [tl_append] |
5183 | 211 |
addsplits [list.split]) 1); |
3571 | 212 |
qed "tl_append2"; |
213 |
Addsimps [tl_append2]; |
|
214 |
||
5272 | 215 |
(* trivial rules for solving @-equations automatically *) |
216 |
||
217 |
Goal "xs = ys ==> xs = [] @ ys"; |
|
5318 | 218 |
by (Asm_simp_tac 1); |
5272 | 219 |
qed "eq_Nil_appendI"; |
220 |
||
221 |
Goal "[| x#xs1 = ys; xs = xs1 @ zs |] ==> x#xs = ys@zs"; |
|
5318 | 222 |
by (dtac sym 1); |
223 |
by (Asm_simp_tac 1); |
|
5272 | 224 |
qed "Cons_eq_appendI"; |
225 |
||
226 |
Goal "[| xs@xs1 = zs; ys = xs1 @ us |] ==> xs@ys = zs@us"; |
|
5318 | 227 |
by (dtac sym 1); |
228 |
by (Asm_simp_tac 1); |
|
5272 | 229 |
qed "append_eq_appendI"; |
230 |
||
4830 | 231 |
|
5427 | 232 |
(*** |
233 |
Simplification procedure for all list equalities. |
|
234 |
Currently only tries to rearranges @ to see if |
|
235 |
- both lists end in a singleton list, |
|
236 |
- or both lists end in the same list. |
|
237 |
***) |
|
238 |
local |
|
239 |
||
240 |
val list_eq_pattern = |
|
9423 | 241 |
Thm.read_cterm (Theory.sign_of (the_context ())) ("(xs::'a list) = ys",HOLogic.boolT); |
5427 | 242 |
|
7224 | 243 |
fun last (cons as Const("List.list.Cons",_) $ _ $ xs) = |
244 |
(case xs of Const("List.list.Nil",_) => cons | _ => last xs) |
|
5427 | 245 |
| last (Const("List.op @",_) $ _ $ ys) = last ys |
246 |
| last t = t; |
|
247 |
||
7224 | 248 |
fun list1 (Const("List.list.Cons",_) $ _ $ Const("List.list.Nil",_)) = true |
5427 | 249 |
| list1 _ = false; |
250 |
||
7224 | 251 |
fun butlast ((cons as Const("List.list.Cons",_) $ x) $ xs) = |
252 |
(case xs of Const("List.list.Nil",_) => xs | _ => cons $ butlast xs) |
|
5427 | 253 |
| butlast ((app as Const("List.op @",_) $ xs) $ ys) = app $ butlast ys |
7224 | 254 |
| butlast xs = Const("List.list.Nil",fastype_of xs); |
5427 | 255 |
|
256 |
val rearr_tac = |
|
257 |
simp_tac (HOL_basic_ss addsimps [append_assoc,append_Nil,append_Cons]); |
|
258 |
||
259 |
fun list_eq sg _ (F as (eq as Const(_,eqT)) $ lhs $ rhs) = |
|
260 |
let |
|
261 |
val lastl = last lhs and lastr = last rhs |
|
262 |
fun rearr conv = |
|
263 |
let val lhs1 = butlast lhs and rhs1 = butlast rhs |
|
264 |
val Type(_,listT::_) = eqT |
|
265 |
val appT = [listT,listT] ---> listT |
|
266 |
val app = Const("List.op @",appT) |
|
267 |
val F2 = eq $ (app$lhs1$lastl) $ (app$rhs1$lastr) |
|
268 |
val ct = cterm_of sg (HOLogic.mk_Trueprop(HOLogic.mk_eq(F,F2))) |
|
269 |
val thm = prove_goalw_cterm [] ct (K [rearr_tac 1]) |
|
270 |
handle ERROR => |
|
271 |
error("The error(s) above occurred while trying to prove " ^ |
|
272 |
string_of_cterm ct) |
|
273 |
in Some((conv RS (thm RS trans)) RS eq_reflection) end |
|
274 |
||
275 |
in if list1 lastl andalso list1 lastr |
|
276 |
then rearr append1_eq_conv |
|
277 |
else |
|
278 |
if lastl aconv lastr |
|
279 |
then rearr append_same_eq |
|
280 |
else None |
|
281 |
end; |
|
282 |
in |
|
283 |
val list_eq_simproc = mk_simproc "list_eq" [list_eq_pattern] list_eq; |
|
284 |
end; |
|
285 |
||
286 |
Addsimprocs [list_eq_simproc]; |
|
287 |
||
288 |
||
2608 | 289 |
(** map **) |
290 |
||
3467 | 291 |
section "map"; |
292 |
||
5278 | 293 |
Goal "(!x. x : set xs --> f x = g x) --> map f xs = map g xs"; |
3457 | 294 |
by (induct_tac "xs" 1); |
5316 | 295 |
by Auto_tac; |
2608 | 296 |
bind_thm("map_ext", impI RS (allI RS (result() RS mp))); |
297 |
||
4935 | 298 |
Goal "map (%x. x) = (%xs. xs)"; |
2608 | 299 |
by (rtac ext 1); |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
300 |
by (induct_tac "xs" 1); |
5316 | 301 |
by Auto_tac; |
2608 | 302 |
qed "map_ident"; |
303 |
Addsimps[map_ident]; |
|
304 |
||
4935 | 305 |
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
|
306 |
by (induct_tac "xs" 1); |
5316 | 307 |
by Auto_tac; |
2608 | 308 |
qed "map_append"; |
309 |
Addsimps[map_append]; |
|
310 |
||
4935 | 311 |
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
|
312 |
by (induct_tac "xs" 1); |
5316 | 313 |
by Auto_tac; |
2608 | 314 |
qed "map_compose"; |
9700 | 315 |
(*Addsimps[map_compose];*) |
2608 | 316 |
|
4935 | 317 |
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
|
318 |
by (induct_tac "xs" 1); |
5316 | 319 |
by Auto_tac; |
2608 | 320 |
qed "rev_map"; |
321 |
||
3589
244daa75f890
Added function `replicate' and lemmas map_cong and set_replicate.
nipkow
parents:
3586
diff
changeset
|
322 |
(* a congruence rule for map: *) |
6451 | 323 |
Goal "xs=ys ==> (!x. x : set ys --> f x = g x) --> map f xs = map g ys"; |
4423 | 324 |
by (hyp_subst_tac 1); |
325 |
by (induct_tac "ys" 1); |
|
5316 | 326 |
by Auto_tac; |
6451 | 327 |
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
|
328 |
|
9763 | 329 |
Add_recdef_congs [map_cong]; |
9639 | 330 |
|
4935 | 331 |
Goal "(map f xs = []) = (xs = [])"; |
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
332 |
by (case_tac "xs" 1); |
5316 | 333 |
by Auto_tac; |
3860 | 334 |
qed "map_is_Nil_conv"; |
335 |
AddIffs [map_is_Nil_conv]; |
|
336 |
||
4935 | 337 |
Goal "([] = map f xs) = (xs = [])"; |
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
338 |
by (case_tac "xs" 1); |
5316 | 339 |
by Auto_tac; |
3860 | 340 |
qed "Nil_is_map_conv"; |
341 |
AddIffs [Nil_is_map_conv]; |
|
342 |
||
8009 | 343 |
Goal "(map f xs = y#ys) = (? x xs'. xs = x#xs' & f x = y & map f xs' = ys)"; |
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
344 |
by (case_tac "xs" 1); |
8009 | 345 |
by (ALLGOALS Asm_simp_tac); |
346 |
qed "map_eq_Cons"; |
|
347 |
||
348 |
Goal "!xs. map f xs = map f ys --> (!x y. f x = f y --> x=y) --> xs=ys"; |
|
349 |
by (induct_tac "ys" 1); |
|
350 |
by (Asm_simp_tac 1); |
|
351 |
by (fast_tac (claset() addss (simpset() addsimps [map_eq_Cons])) 1); |
|
352 |
qed_spec_mp "map_injective"; |
|
353 |
||
354 |
Goal "inj f ==> inj (map f)"; |
|
8064 | 355 |
by (blast_tac (claset() addDs [map_injective,injD] addIs [injI]) 1); |
8009 | 356 |
qed "inj_mapI"; |
357 |
||
358 |
Goalw [inj_on_def] "inj (map f) ==> inj f"; |
|
8064 | 359 |
by (Clarify_tac 1); |
360 |
by (eres_inst_tac [("x","[x]")] ballE 1); |
|
361 |
by (eres_inst_tac [("x","[y]")] ballE 1); |
|
362 |
by (Asm_full_simp_tac 1); |
|
363 |
by (Blast_tac 1); |
|
364 |
by (Blast_tac 1); |
|
8009 | 365 |
qed "inj_mapD"; |
366 |
||
367 |
Goal "inj (map f) = inj f"; |
|
8064 | 368 |
by (blast_tac (claset() addDs [inj_mapD] addIs [inj_mapI]) 1); |
8009 | 369 |
qed "inj_map"; |
3860 | 370 |
|
1169 | 371 |
(** rev **) |
372 |
||
3467 | 373 |
section "rev"; |
374 |
||
4935 | 375 |
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
|
376 |
by (induct_tac "xs" 1); |
5316 | 377 |
by Auto_tac; |
1169 | 378 |
qed "rev_append"; |
2512 | 379 |
Addsimps[rev_append]; |
1169 | 380 |
|
4935 | 381 |
Goal "rev(rev l) = l"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
382 |
by (induct_tac "l" 1); |
5316 | 383 |
by Auto_tac; |
1169 | 384 |
qed "rev_rev_ident"; |
2512 | 385 |
Addsimps[rev_rev_ident]; |
1169 | 386 |
|
4935 | 387 |
Goal "(rev xs = []) = (xs = [])"; |
4423 | 388 |
by (induct_tac "xs" 1); |
5316 | 389 |
by Auto_tac; |
3860 | 390 |
qed "rev_is_Nil_conv"; |
391 |
AddIffs [rev_is_Nil_conv]; |
|
392 |
||
4935 | 393 |
Goal "([] = rev xs) = (xs = [])"; |
4423 | 394 |
by (induct_tac "xs" 1); |
5316 | 395 |
by Auto_tac; |
3860 | 396 |
qed "Nil_is_rev_conv"; |
397 |
AddIffs [Nil_is_rev_conv]; |
|
398 |
||
6820 | 399 |
Goal "!ys. (rev xs = rev ys) = (xs = ys)"; |
6831 | 400 |
by (induct_tac "xs" 1); |
6820 | 401 |
by (Force_tac 1); |
6831 | 402 |
by (rtac allI 1); |
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
403 |
by (case_tac "ys" 1); |
6820 | 404 |
by (Asm_simp_tac 1); |
405 |
by (Force_tac 1); |
|
406 |
qed_spec_mp "rev_is_rev_conv"; |
|
407 |
AddIffs [rev_is_rev_conv]; |
|
408 |
||
4935 | 409 |
val prems = Goal "[| P []; !!x xs. P xs ==> P(xs@[x]) |] ==> P xs"; |
5132 | 410 |
by (stac (rev_rev_ident RS sym) 1); |
6162 | 411 |
by (res_inst_tac [("list", "rev xs")] list.induct 1); |
5132 | 412 |
by (ALLGOALS Simp_tac); |
413 |
by (resolve_tac prems 1); |
|
414 |
by (eresolve_tac prems 1); |
|
4935 | 415 |
qed "rev_induct"; |
416 |
||
9747 | 417 |
val rev_induct_tac = induct_thm_tac rev_induct; |
5272 | 418 |
|
4935 | 419 |
Goal "(xs = [] --> P) --> (!ys y. xs = ys@[y] --> P) --> P"; |
9747 | 420 |
by (rev_induct_tac "xs" 1); |
5316 | 421 |
by Auto_tac; |
4935 | 422 |
bind_thm ("rev_exhaust", |
423 |
impI RSN (2,allI RSN (2,allI RSN (2,impI RS (result() RS mp RS mp))))); |
|
424 |
||
2608 | 425 |
|
3465 | 426 |
(** set **) |
1812 | 427 |
|
3467 | 428 |
section "set"; |
429 |
||
7032 | 430 |
Goal "finite (set xs)"; |
431 |
by (induct_tac "xs" 1); |
|
432 |
by Auto_tac; |
|
433 |
qed "finite_set"; |
|
434 |
AddIffs [finite_set]; |
|
5296 | 435 |
|
4935 | 436 |
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
|
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_append"; |
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
440 |
Addsimps[set_append]; |
1812 | 441 |
|
4935 | 442 |
Goal "set l <= set (x#l)"; |
5316 | 443 |
by Auto_tac; |
3647
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
444 |
qed "set_subset_Cons"; |
1936 | 445 |
|
4935 | 446 |
Goal "(set xs = {}) = (xs = [])"; |
3457 | 447 |
by (induct_tac "xs" 1); |
5316 | 448 |
by Auto_tac; |
3647
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
449 |
qed "set_empty"; |
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
450 |
Addsimps [set_empty]; |
2608 | 451 |
|
4935 | 452 |
Goal "set(rev xs) = set(xs)"; |
3457 | 453 |
by (induct_tac "xs" 1); |
5316 | 454 |
by Auto_tac; |
3647
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
455 |
qed "set_rev"; |
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
456 |
Addsimps [set_rev]; |
2608 | 457 |
|
4935 | 458 |
Goal "set(map f xs) = f``(set xs)"; |
3457 | 459 |
by (induct_tac "xs" 1); |
5316 | 460 |
by Auto_tac; |
3647
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
461 |
qed "set_map"; |
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
462 |
Addsimps [set_map]; |
2608 | 463 |
|
6433 | 464 |
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
|
465 |
by (induct_tac "xs" 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
466 |
by Auto_tac; |
6433 | 467 |
qed "set_filter"; |
468 |
Addsimps [set_filter]; |
|
8009 | 469 |
|
6433 | 470 |
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
|
471 |
by (induct_tac "j" 1); |
9187
68ecc04785f1
fixed proof to cope with the default of equalityCE instead of equalityE
paulson
parents:
9108
diff
changeset
|
472 |
by (ALLGOALS Asm_simp_tac); |
68ecc04785f1
fixed proof to cope with the default of equalityCE instead of equalityE
paulson
parents:
9108
diff
changeset
|
473 |
by (etac ssubst 1); |
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
474 |
by Auto_tac; |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
475 |
by (arith_tac 1); |
6433 | 476 |
qed "set_upt"; |
477 |
Addsimps [set_upt]; |
|
478 |
||
5272 | 479 |
Goal "(x : set xs) = (? ys zs. xs = ys@x#zs)"; |
5318 | 480 |
by (induct_tac "xs" 1); |
481 |
by (Simp_tac 1); |
|
482 |
by (Asm_simp_tac 1); |
|
483 |
by (rtac iffI 1); |
|
484 |
by (blast_tac (claset() addIs [eq_Nil_appendI,Cons_eq_appendI]) 1); |
|
485 |
by (REPEAT(etac exE 1)); |
|
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
486 |
by (case_tac "ys" 1); |
5316 | 487 |
by Auto_tac; |
5272 | 488 |
qed "in_set_conv_decomp"; |
489 |
||
8009 | 490 |
|
5272 | 491 |
(* eliminate `lists' in favour of `set' *) |
492 |
||
493 |
Goal "(xs : lists A) = (!x : set xs. x : A)"; |
|
5318 | 494 |
by (induct_tac "xs" 1); |
5316 | 495 |
by Auto_tac; |
5272 | 496 |
qed "in_lists_conv_set"; |
497 |
||
498 |
bind_thm("in_listsD",in_lists_conv_set RS iffD1); |
|
499 |
AddSDs [in_listsD]; |
|
500 |
bind_thm("in_listsI",in_lists_conv_set RS iffD2); |
|
501 |
AddSIs [in_listsI]; |
|
1812 | 502 |
|
5518 | 503 |
(** mem **) |
504 |
||
505 |
section "mem"; |
|
506 |
||
507 |
Goal "(x mem xs) = (x: set xs)"; |
|
508 |
by (induct_tac "xs" 1); |
|
509 |
by Auto_tac; |
|
510 |
qed "set_mem_eq"; |
|
511 |
||
512 |
||
923 | 513 |
(** list_all **) |
514 |
||
3467 | 515 |
section "list_all"; |
516 |
||
5518 | 517 |
Goal "list_all P xs = (!x:set xs. P x)"; |
518 |
by (induct_tac "xs" 1); |
|
519 |
by Auto_tac; |
|
520 |
qed "list_all_conv"; |
|
521 |
||
5443
e2459d18ff47
changed constants mem and list_all to mere translations
oheimb
parents:
5427
diff
changeset
|
522 |
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
|
523 |
by (induct_tac "xs" 1); |
5316 | 524 |
by Auto_tac; |
2512 | 525 |
qed "list_all_append"; |
526 |
Addsimps [list_all_append]; |
|
923 | 527 |
|
528 |
||
2608 | 529 |
(** filter **) |
923 | 530 |
|
3467 | 531 |
section "filter"; |
532 |
||
4935 | 533 |
Goal "filter P (xs@ys) = filter P xs @ filter P ys"; |
3457 | 534 |
by (induct_tac "xs" 1); |
5316 | 535 |
by Auto_tac; |
2608 | 536 |
qed "filter_append"; |
537 |
Addsimps [filter_append]; |
|
538 |
||
4935 | 539 |
Goal "filter (%x. True) xs = xs"; |
4605 | 540 |
by (induct_tac "xs" 1); |
5316 | 541 |
by Auto_tac; |
4605 | 542 |
qed "filter_True"; |
543 |
Addsimps [filter_True]; |
|
544 |
||
4935 | 545 |
Goal "filter (%x. False) xs = []"; |
4605 | 546 |
by (induct_tac "xs" 1); |
5316 | 547 |
by Auto_tac; |
4605 | 548 |
qed "filter_False"; |
549 |
Addsimps [filter_False]; |
|
550 |
||
4935 | 551 |
Goal "length (filter P xs) <= length xs"; |
3457 | 552 |
by (induct_tac "xs" 1); |
5316 | 553 |
by Auto_tac; |
8741
61bc5ed22b62
removal of less_SucI, le_SucI from default simpset
paulson
parents:
8442
diff
changeset
|
554 |
by (asm_simp_tac (simpset() addsimps [le_SucI]) 1); |
4605 | 555 |
qed "length_filter"; |
5443
e2459d18ff47
changed constants mem and list_all to mere translations
oheimb
parents:
5427
diff
changeset
|
556 |
Addsimps[length_filter]; |
2608 | 557 |
|
5443
e2459d18ff47
changed constants mem and list_all to mere translations
oheimb
parents:
5427
diff
changeset
|
558 |
Goal "set (filter P xs) <= set xs"; |
e2459d18ff47
changed constants mem and list_all to mere translations
oheimb
parents:
5427
diff
changeset
|
559 |
by Auto_tac; |
e2459d18ff47
changed constants mem and list_all to mere translations
oheimb
parents:
5427
diff
changeset
|
560 |
qed "filter_is_subset"; |
e2459d18ff47
changed constants mem and list_all to mere translations
oheimb
parents:
5427
diff
changeset
|
561 |
Addsimps [filter_is_subset]; |
e2459d18ff47
changed constants mem and list_all to mere translations
oheimb
parents:
5427
diff
changeset
|
562 |
|
2608 | 563 |
|
3467 | 564 |
section "concat"; |
565 |
||
4935 | 566 |
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
|
567 |
by (induct_tac "xs" 1); |
5316 | 568 |
by Auto_tac; |
2608 | 569 |
qed"concat_append"; |
570 |
Addsimps [concat_append]; |
|
2512 | 571 |
|
4935 | 572 |
Goal "(concat xss = []) = (!xs:set xss. xs=[])"; |
4423 | 573 |
by (induct_tac "xss" 1); |
5316 | 574 |
by Auto_tac; |
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
575 |
qed "concat_eq_Nil_conv"; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
576 |
AddIffs [concat_eq_Nil_conv]; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
577 |
|
4935 | 578 |
Goal "([] = concat xss) = (!xs:set xss. xs=[])"; |
4423 | 579 |
by (induct_tac "xss" 1); |
5316 | 580 |
by Auto_tac; |
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
581 |
qed "Nil_eq_concat_conv"; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
582 |
AddIffs [Nil_eq_concat_conv]; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
583 |
|
4935 | 584 |
Goal "set(concat xs) = Union(set `` set xs)"; |
3467 | 585 |
by (induct_tac "xs" 1); |
5316 | 586 |
by Auto_tac; |
3647
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
587 |
qed"set_concat"; |
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
588 |
Addsimps [set_concat]; |
3467 | 589 |
|
4935 | 590 |
Goal "map f (concat xs) = concat (map (map f) xs)"; |
3467 | 591 |
by (induct_tac "xs" 1); |
5316 | 592 |
by Auto_tac; |
3467 | 593 |
qed "map_concat"; |
594 |
||
4935 | 595 |
Goal "filter p (concat xs) = concat (map (filter p) xs)"; |
3467 | 596 |
by (induct_tac "xs" 1); |
5316 | 597 |
by Auto_tac; |
3467 | 598 |
qed"filter_concat"; |
599 |
||
4935 | 600 |
Goal "rev(concat xs) = concat (map rev (rev xs))"; |
3467 | 601 |
by (induct_tac "xs" 1); |
5316 | 602 |
by Auto_tac; |
2608 | 603 |
qed "rev_concat"; |
923 | 604 |
|
605 |
(** nth **) |
|
606 |
||
3467 | 607 |
section "nth"; |
608 |
||
6408 | 609 |
Goal "(x#xs)!0 = x"; |
610 |
by Auto_tac; |
|
611 |
qed "nth_Cons_0"; |
|
612 |
Addsimps [nth_Cons_0]; |
|
5644 | 613 |
|
6408 | 614 |
Goal "(x#xs)!(Suc n) = xs!n"; |
615 |
by Auto_tac; |
|
616 |
qed "nth_Cons_Suc"; |
|
617 |
Addsimps [nth_Cons_Suc]; |
|
618 |
||
619 |
Delsimps (thms "nth.simps"); |
|
620 |
||
621 |
Goal "!n. (xs@ys)!n = (if n < length xs then xs!n else ys!(n - length xs))"; |
|
622 |
by (induct_tac "xs" 1); |
|
3457 | 623 |
by (Asm_simp_tac 1); |
624 |
by (rtac allI 1); |
|
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
625 |
by (case_tac "n" 1); |
5316 | 626 |
by Auto_tac; |
2608 | 627 |
qed_spec_mp "nth_append"; |
628 |
||
4935 | 629 |
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
|
630 |
by (induct_tac "xs" 1); |
8118 | 631 |
by (Asm_full_simp_tac 1); |
1301 | 632 |
by (rtac allI 1); |
5183 | 633 |
by (induct_tac "n" 1); |
5316 | 634 |
by Auto_tac; |
1485
240cc98b94a7
Added qed_spec_mp to avoid renaming of bound vars in 'th RS spec'
nipkow
parents:
1465
diff
changeset
|
635 |
qed_spec_mp "nth_map"; |
1301 | 636 |
Addsimps [nth_map]; |
637 |
||
8118 | 638 |
Goal "set xs = {xs!i |i. i < length xs}"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
639 |
by (induct_tac "xs" 1); |
8118 | 640 |
by (Simp_tac 1); |
8254 | 641 |
by (Asm_simp_tac 1); |
642 |
by Safe_tac; |
|
643 |
by (res_inst_tac [("x","0")] exI 1); |
|
8118 | 644 |
by (Simp_tac 1); |
8254 | 645 |
by (res_inst_tac [("x","Suc i")] exI 1); |
646 |
by (Asm_simp_tac 1); |
|
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
647 |
by (case_tac "i" 1); |
8254 | 648 |
by (Asm_full_simp_tac 1); |
649 |
by (rename_tac "j" 1); |
|
650 |
by (res_inst_tac [("x","j")] exI 1); |
|
651 |
by (Asm_simp_tac 1); |
|
8118 | 652 |
qed "set_conv_nth"; |
653 |
||
654 |
Goal "n < length xs ==> Ball (set xs) P --> P(xs!n)"; |
|
655 |
by (simp_tac (simpset() addsimps [set_conv_nth]) 1); |
|
8254 | 656 |
by (Blast_tac 1); |
5518 | 657 |
qed_spec_mp "list_ball_nth"; |
1301 | 658 |
|
8118 | 659 |
Goal "n < length xs ==> xs!n : set xs"; |
660 |
by (simp_tac (simpset() addsimps [set_conv_nth]) 1); |
|
8254 | 661 |
by (Blast_tac 1); |
1485
240cc98b94a7
Added qed_spec_mp to avoid renaming of bound vars in 'th RS spec'
nipkow
parents:
1465
diff
changeset
|
662 |
qed_spec_mp "nth_mem"; |
1301 | 663 |
Addsimps [nth_mem]; |
664 |
||
8009 | 665 |
Goal "(!i. i < length xs --> P(xs!i)) --> (!x : set xs. P x)"; |
8118 | 666 |
by (simp_tac (simpset() addsimps [set_conv_nth]) 1); |
8254 | 667 |
by (Blast_tac 1); |
8009 | 668 |
qed_spec_mp "all_nth_imp_all_set"; |
669 |
||
670 |
Goal "(!x : set xs. P x) = (!i. i<length xs --> P (xs ! i))"; |
|
8118 | 671 |
by (simp_tac (simpset() addsimps [set_conv_nth]) 1); |
8254 | 672 |
by (Blast_tac 1); |
8009 | 673 |
qed_spec_mp "all_set_conv_all_nth"; |
674 |
||
675 |
||
5077
71043526295f
* HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents:
5043
diff
changeset
|
676 |
(** list update **) |
71043526295f
* HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents:
5043
diff
changeset
|
677 |
|
71043526295f
* HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents:
5043
diff
changeset
|
678 |
section "list update"; |
71043526295f
* HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents:
5043
diff
changeset
|
679 |
|
71043526295f
* HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents:
5043
diff
changeset
|
680 |
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
|
681 |
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
|
682 |
by (Simp_tac 1); |
5183 | 683 |
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
|
684 |
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
|
685 |
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
|
686 |
|
5644 | 687 |
Goal "!i j. i < length xs --> (xs[i:=x])!j = (if i=j then x else xs!j)"; |
6162 | 688 |
by (induct_tac "xs" 1); |
689 |
by (Simp_tac 1); |
|
690 |
by (auto_tac (claset(), simpset() addsimps [nth_Cons] addsplits [nat.split])); |
|
5644 | 691 |
qed_spec_mp "nth_list_update"; |
692 |
||
8144 | 693 |
Goal "i < length xs ==> (xs[i:=x])!i = x"; |
694 |
by (asm_simp_tac (simpset() addsimps [nth_list_update]) 1); |
|
695 |
qed "nth_list_update_eq"; |
|
696 |
Addsimps [nth_list_update_eq]; |
|
697 |
||
698 |
Goal "!i j. i ~= j --> xs[i:=x]!j = xs!j"; |
|
699 |
by (induct_tac "xs" 1); |
|
700 |
by (Simp_tac 1); |
|
701 |
by (auto_tac (claset(), simpset() addsimps [nth_Cons] addsplits [nat.split])); |
|
702 |
qed_spec_mp "nth_list_update_neq"; |
|
703 |
Addsimps [nth_list_update_neq]; |
|
704 |
||
6433 | 705 |
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
|
706 |
by (induct_tac "xs" 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
707 |
by (Simp_tac 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
708 |
by (asm_simp_tac (simpset() addsplits [nat.split]) 1); |
6433 | 709 |
qed_spec_mp "list_update_overwrite"; |
710 |
Addsimps [list_update_overwrite]; |
|
711 |
||
712 |
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
|
713 |
by (induct_tac "xs" 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
714 |
by (Simp_tac 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
715 |
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
|
716 |
by (Blast_tac 1); |
6433 | 717 |
qed_spec_mp "list_update_same_conv"; |
718 |
||
8009 | 719 |
Goal "!i xy xs. length xs = length ys --> \ |
720 |
\ (zip xs ys)[i:=xy] = zip (xs[i:=fst xy]) (ys[i:=snd xy])"; |
|
721 |
by (induct_tac "ys" 1); |
|
722 |
by Auto_tac; |
|
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
723 |
by (case_tac "xs" 1); |
8009 | 724 |
by (auto_tac (claset(), simpset() addsplits [nat.split])); |
725 |
qed_spec_mp "update_zip"; |
|
726 |
||
727 |
Goal "!i. set(xs[i:=x]) <= insert x (set xs)"; |
|
728 |
by (induct_tac "xs" 1); |
|
729 |
by (asm_full_simp_tac (simpset() addsimps []) 1); |
|
730 |
by (asm_full_simp_tac (simpset() addsplits [nat.split]) 1); |
|
731 |
by (Fast_tac 1); |
|
8287 | 732 |
qed_spec_mp "set_update_subset_insert"; |
8009 | 733 |
|
8287 | 734 |
Goal "[| set xs <= A; x:A |] ==> set(xs[i := x]) <= A"; |
735 |
by(fast_tac (claset() addSDs [set_update_subset_insert RS subsetD]) 1); |
|
736 |
qed "set_update_subsetI"; |
|
5077
71043526295f
* HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents:
5043
diff
changeset
|
737 |
|
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
738 |
(** last & butlast **) |
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
739 |
|
5644 | 740 |
section "last / butlast"; |
741 |
||
4935 | 742 |
Goal "last(xs@[x]) = x"; |
4423 | 743 |
by (induct_tac "xs" 1); |
5316 | 744 |
by Auto_tac; |
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
745 |
qed "last_snoc"; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
746 |
Addsimps [last_snoc]; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
747 |
|
4935 | 748 |
Goal "butlast(xs@[x]) = xs"; |
4423 | 749 |
by (induct_tac "xs" 1); |
5316 | 750 |
by Auto_tac; |
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
751 |
qed "butlast_snoc"; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
752 |
Addsimps [butlast_snoc]; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
753 |
|
4935 | 754 |
Goal "length(butlast xs) = length xs - 1"; |
9747 | 755 |
by (rev_induct_tac "xs" 1); |
5316 | 756 |
by Auto_tac; |
4643 | 757 |
qed "length_butlast"; |
758 |
Addsimps [length_butlast]; |
|
759 |
||
5278 | 760 |
Goal "!ys. butlast (xs@ys) = (if ys=[] then butlast xs else xs@butlast ys)"; |
4423 | 761 |
by (induct_tac "xs" 1); |
5316 | 762 |
by Auto_tac; |
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
763 |
qed_spec_mp "butlast_append"; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
764 |
|
8118 | 765 |
Goal "xs ~= [] --> butlast xs @ [last xs] = xs"; |
8254 | 766 |
by (induct_tac "xs" 1); |
767 |
by (ALLGOALS Asm_simp_tac); |
|
8118 | 768 |
qed_spec_mp "append_butlast_last_id"; |
769 |
Addsimps [append_butlast_last_id]; |
|
770 |
||
4935 | 771 |
Goal "x:set(butlast xs) --> x:set xs"; |
4423 | 772 |
by (induct_tac "xs" 1); |
5316 | 773 |
by Auto_tac; |
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
774 |
qed_spec_mp "in_set_butlastD"; |
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3860
diff
changeset
|
775 |
|
5448
40a09282ba14
in_set_butlast_appendI supersedes in_set_butlast_appendI1,2
paulson
parents:
5443
diff
changeset
|
776 |
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
|
777 |
by (auto_tac (claset() addDs [in_set_butlastD], |
40a09282ba14
in_set_butlast_appendI supersedes in_set_butlast_appendI1,2
paulson
parents:
5443
diff
changeset
|
778 |
simpset() addsimps [butlast_append])); |
40a09282ba14
in_set_butlast_appendI supersedes in_set_butlast_appendI1,2
paulson
parents:
5443
diff
changeset
|
779 |
qed "in_set_butlast_appendI"; |
3902 | 780 |
|
2608 | 781 |
(** take & drop **) |
782 |
section "take & drop"; |
|
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
783 |
|
4935 | 784 |
Goal "take 0 xs = []"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
785 |
by (induct_tac "xs" 1); |
5316 | 786 |
by Auto_tac; |
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
787 |
qed "take_0"; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
788 |
|
4935 | 789 |
Goal "drop 0 xs = xs"; |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3011
diff
changeset
|
790 |
by (induct_tac "xs" 1); |
5316 | 791 |
by Auto_tac; |
2608 | 792 |
qed "drop_0"; |
793 |
||
4935 | 794 |
Goal "take (Suc n) (x#xs) = x # take n xs"; |
1552 | 795 |
by (Simp_tac 1); |
1419
a6a034a47a71
defined take/drop by induction over list rather than nat.
nipkow
parents:
1327
diff
changeset
|
796 |
qed "take_Suc_Cons"; |
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
797 |
|
4935 | 798 |
Goal "drop (Suc n) (x#xs) = drop n xs"; |
2608 | 799 |
by (Simp_tac 1); |
800 |
qed "drop_Suc_Cons"; |
|
801 |
||
802 |
Delsimps [take_Cons,drop_Cons]; |
|
803 |
Addsimps [take_0,take_Suc_Cons,drop_0,drop_Suc_Cons]; |
|
804 |
||
4935 | 805 |
Goal "!xs. length(take n xs) = min (length xs) n"; |
5183 | 806 |
by (induct_tac "n" 1); |
5316 | 807 |
by Auto_tac; |
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
808 |
by (case_tac "xs" 1); |
5316 | 809 |
by Auto_tac; |
2608 | 810 |
qed_spec_mp "length_take"; |
811 |
Addsimps [length_take]; |
|
923 | 812 |
|
4935 | 813 |
Goal "!xs. length(drop n xs) = (length xs - n)"; |
5183 | 814 |
by (induct_tac "n" 1); |
5316 | 815 |
by Auto_tac; |
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
816 |
by (case_tac "xs" 1); |
5316 | 817 |
by Auto_tac; |
2608 | 818 |
qed_spec_mp "length_drop"; |
819 |
Addsimps [length_drop]; |
|
820 |
||
4935 | 821 |
Goal "!xs. length xs <= n --> take n xs = xs"; |
5183 | 822 |
by (induct_tac "n" 1); |
5316 | 823 |
by Auto_tac; |
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
824 |
by (case_tac "xs" 1); |
5316 | 825 |
by Auto_tac; |
2608 | 826 |
qed_spec_mp "take_all"; |
7246 | 827 |
Addsimps [take_all]; |
923 | 828 |
|
4935 | 829 |
Goal "!xs. length xs <= n --> drop n xs = []"; |
5183 | 830 |
by (induct_tac "n" 1); |
5316 | 831 |
by Auto_tac; |
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
832 |
by (case_tac "xs" 1); |
5316 | 833 |
by Auto_tac; |
2608 | 834 |
qed_spec_mp "drop_all"; |
7246 | 835 |
Addsimps [drop_all]; |
2608 | 836 |
|
5278 | 837 |
Goal "!xs. take n (xs @ ys) = (take n xs @ take (n - length xs) ys)"; |
5183 | 838 |
by (induct_tac "n" 1); |
5316 | 839 |
by Auto_tac; |
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
840 |
by (case_tac "xs" 1); |
5316 | 841 |
by Auto_tac; |
2608 | 842 |
qed_spec_mp "take_append"; |
843 |
Addsimps [take_append]; |
|
844 |
||
4935 | 845 |
Goal "!xs. drop n (xs@ys) = drop n xs @ drop (n - length xs) ys"; |
5183 | 846 |
by (induct_tac "n" 1); |
5316 | 847 |
by Auto_tac; |
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
848 |
by (case_tac "xs" 1); |
5316 | 849 |
by Auto_tac; |
2608 | 850 |
qed_spec_mp "drop_append"; |
851 |
Addsimps [drop_append]; |
|
852 |
||
4935 | 853 |
Goal "!xs n. take n (take m xs) = take (min n m) xs"; |
5183 | 854 |
by (induct_tac "m" 1); |
5316 | 855 |
by Auto_tac; |
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
856 |
by (case_tac "xs" 1); |
5316 | 857 |
by Auto_tac; |
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
858 |
by (case_tac "na" 1); |
5316 | 859 |
by Auto_tac; |
2608 | 860 |
qed_spec_mp "take_take"; |
7570 | 861 |
Addsimps [take_take]; |
2608 | 862 |
|
4935 | 863 |
Goal "!xs. drop n (drop m xs) = drop (n + m) xs"; |
5183 | 864 |
by (induct_tac "m" 1); |
5316 | 865 |
by Auto_tac; |
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
866 |
by (case_tac "xs" 1); |
5316 | 867 |
by Auto_tac; |
2608 | 868 |
qed_spec_mp "drop_drop"; |
7570 | 869 |
Addsimps [drop_drop]; |
923 | 870 |
|
4935 | 871 |
Goal "!xs n. take n (drop m xs) = drop m (take (n + m) xs)"; |
5183 | 872 |
by (induct_tac "m" 1); |
5316 | 873 |
by Auto_tac; |
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
874 |
by (case_tac "xs" 1); |
5316 | 875 |
by Auto_tac; |
2608 | 876 |
qed_spec_mp "take_drop"; |
877 |
||
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
878 |
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
|
879 |
by (induct_tac "n" 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
880 |
by Auto_tac; |
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
881 |
by (case_tac "xs" 1); |
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
882 |
by Auto_tac; |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
883 |
qed_spec_mp "append_take_drop_id"; |
8118 | 884 |
Addsimps [append_take_drop_id]; |
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
885 |
|
4935 | 886 |
Goal "!xs. take n (map f xs) = map f (take n xs)"; |
5183 | 887 |
by (induct_tac "n" 1); |
5316 | 888 |
by Auto_tac; |
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
889 |
by (case_tac "xs" 1); |
5316 | 890 |
by Auto_tac; |
2608 | 891 |
qed_spec_mp "take_map"; |
892 |
||
4935 | 893 |
Goal "!xs. drop n (map f xs) = map f (drop n xs)"; |
5183 | 894 |
by (induct_tac "n" 1); |
5316 | 895 |
by Auto_tac; |
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
896 |
by (case_tac "xs" 1); |
5316 | 897 |
by Auto_tac; |
2608 | 898 |
qed_spec_mp "drop_map"; |
899 |
||
4935 | 900 |
Goal "!n i. i < n --> (take n xs)!i = xs!i"; |
3457 | 901 |
by (induct_tac "xs" 1); |
5316 | 902 |
by Auto_tac; |
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
903 |
by (case_tac "n" 1); |
3457 | 904 |
by (Blast_tac 1); |
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
905 |
by (case_tac "i" 1); |
5316 | 906 |
by Auto_tac; |
2608 | 907 |
qed_spec_mp "nth_take"; |
908 |
Addsimps [nth_take]; |
|
923 | 909 |
|
4935 | 910 |
Goal "!xs i. n + i <= length xs --> (drop n xs)!i = xs!(n+i)"; |
5183 | 911 |
by (induct_tac "n" 1); |
5316 | 912 |
by Auto_tac; |
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
913 |
by (case_tac "xs" 1); |
5316 | 914 |
by Auto_tac; |
2608 | 915 |
qed_spec_mp "nth_drop"; |
916 |
Addsimps [nth_drop]; |
|
917 |
||
8118 | 918 |
|
919 |
Goal |
|
920 |
"!zs. (xs@ys = zs) = (xs = take (length xs) zs & ys = drop (length xs) zs)"; |
|
8254 | 921 |
by (induct_tac "xs" 1); |
922 |
by (Simp_tac 1); |
|
923 |
by (Asm_full_simp_tac 1); |
|
924 |
by (Clarify_tac 1); |
|
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
925 |
by (case_tac "zs" 1); |
8254 | 926 |
by (Auto_tac); |
8118 | 927 |
qed_spec_mp "append_eq_conv_conj"; |
928 |
||
2608 | 929 |
(** takeWhile & dropWhile **) |
930 |
||
3467 | 931 |
section "takeWhile & dropWhile"; |
932 |
||
4935 | 933 |
Goal "takeWhile P xs @ dropWhile P xs = xs"; |
3586 | 934 |
by (induct_tac "xs" 1); |
5316 | 935 |
by Auto_tac; |
3586 | 936 |
qed "takeWhile_dropWhile_id"; |
937 |
Addsimps [takeWhile_dropWhile_id]; |
|
938 |
||
4935 | 939 |
Goal "x:set xs & ~P(x) --> takeWhile P (xs @ ys) = takeWhile P xs"; |
3457 | 940 |
by (induct_tac "xs" 1); |
5316 | 941 |
by Auto_tac; |
2608 | 942 |
bind_thm("takeWhile_append1", conjI RS (result() RS mp)); |
943 |
Addsimps [takeWhile_append1]; |
|
923 | 944 |
|
4935 | 945 |
Goal "(!x:set xs. P(x)) --> takeWhile P (xs @ ys) = xs @ takeWhile P ys"; |
3457 | 946 |
by (induct_tac "xs" 1); |
5316 | 947 |
by Auto_tac; |
2608 | 948 |
bind_thm("takeWhile_append2", ballI RS (result() RS mp)); |
949 |
Addsimps [takeWhile_append2]; |
|
1169 | 950 |
|
4935 | 951 |
Goal "x:set xs & ~P(x) --> dropWhile P (xs @ ys) = (dropWhile P xs)@ys"; |
3457 | 952 |
by (induct_tac "xs" 1); |
5316 | 953 |
by Auto_tac; |
2608 | 954 |
bind_thm("dropWhile_append1", conjI RS (result() RS mp)); |
955 |
Addsimps [dropWhile_append1]; |
|
956 |
||
4935 | 957 |
Goal "(!x:set xs. P(x)) --> dropWhile P (xs @ ys) = dropWhile P ys"; |
3457 | 958 |
by (induct_tac "xs" 1); |
5316 | 959 |
by Auto_tac; |
2608 | 960 |
bind_thm("dropWhile_append2", ballI RS (result() RS mp)); |
961 |
Addsimps [dropWhile_append2]; |
|
962 |
||
4935 | 963 |
Goal "x:set(takeWhile P xs) --> x:set xs & P x"; |
3457 | 964 |
by (induct_tac "xs" 1); |
5316 | 965 |
by Auto_tac; |
3647
a64c8fbcd98f
Renamed theorems of the form set_of_list_XXX to set_XXX
paulson
parents:
3589
diff
changeset
|
966 |
qed_spec_mp"set_take_whileD"; |
2608 | 967 |
|
6306 | 968 |
(** zip **) |
969 |
section "zip"; |
|
970 |
||
971 |
Goal "zip [] ys = []"; |
|
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
972 |
by (induct_tac "ys" 1); |
6306 | 973 |
by Auto_tac; |
974 |
qed "zip_Nil"; |
|
975 |
Addsimps [zip_Nil]; |
|
976 |
||
977 |
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
|
978 |
by (Simp_tac 1); |
6306 | 979 |
qed "zip_Cons_Cons"; |
980 |
Addsimps [zip_Cons_Cons]; |
|
981 |
||
982 |
Delsimps(tl (thms"zip.simps")); |
|
4605 | 983 |
|
8118 | 984 |
Goal "!xs. length (zip xs ys) = min (length xs) (length ys)"; |
8009 | 985 |
by (induct_tac "ys" 1); |
986 |
by (Simp_tac 1); |
|
987 |
by (Clarify_tac 1); |
|
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
988 |
by (case_tac "xs" 1); |
8064 | 989 |
by (Auto_tac); |
8009 | 990 |
qed_spec_mp "length_zip"; |
991 |
Addsimps [length_zip]; |
|
992 |
||
993 |
Goal |
|
8118 | 994 |
"!xs. zip (xs@ys) zs = \ |
995 |
\ zip xs (take (length xs) zs) @ zip ys (drop (length xs) zs)"; |
|
8254 | 996 |
by (induct_tac "zs" 1); |
997 |
by (Simp_tac 1); |
|
8064 | 998 |
by (Clarify_tac 1); |
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
999 |
by (case_tac "xs" 1); |
8254 | 1000 |
by (Asm_simp_tac 1); |
1001 |
by (Asm_simp_tac 1); |
|
8118 | 1002 |
qed_spec_mp "zip_append1"; |
1003 |
||
1004 |
Goal |
|
1005 |
"!ys. zip xs (ys@zs) = \ |
|
1006 |
\ zip (take (length ys) xs) ys @ zip (drop (length ys) xs) zs"; |
|
8254 | 1007 |
by (induct_tac "xs" 1); |
1008 |
by (Simp_tac 1); |
|
8118 | 1009 |
by (Clarify_tac 1); |
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
1010 |
by (case_tac "ys" 1); |
8254 | 1011 |
by (Asm_simp_tac 1); |
1012 |
by (Asm_simp_tac 1); |
|
8118 | 1013 |
qed_spec_mp "zip_append2"; |
1014 |
||
1015 |
Goal |
|
1016 |
"[| length xs = length us; length ys = length vs |] ==> \ |
|
1017 |
\ zip (xs@ys) (us@vs) = zip xs us @ zip ys vs"; |
|
8254 | 1018 |
by (asm_simp_tac (simpset() addsimps [zip_append1]) 1); |
8009 | 1019 |
qed_spec_mp "zip_append"; |
8118 | 1020 |
Addsimps [zip_append]; |
8009 | 1021 |
|
1022 |
Goal "!xs. length xs = length ys --> zip (rev xs) (rev ys) = rev (zip xs ys)"; |
|
8064 | 1023 |
by (induct_tac "ys" 1); |
1024 |
by (Asm_full_simp_tac 1); |
|
1025 |
by (Asm_full_simp_tac 1); |
|
1026 |
by (Clarify_tac 1); |
|
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
1027 |
by (case_tac "xs" 1); |
8064 | 1028 |
by (Auto_tac); |
8009 | 1029 |
qed_spec_mp "zip_rev"; |
1030 |
||
8115 | 1031 |
|
1032 |
Goal |
|
8009 | 1033 |
"!i xs. i < length xs --> i < length ys --> (zip xs ys)!i = (xs!i, ys!i)"; |
1034 |
by (induct_tac "ys" 1); |
|
1035 |
by (Simp_tac 1); |
|
1036 |
by (Clarify_tac 1); |
|
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
1037 |
by (case_tac "xs" 1); |
8064 | 1038 |
by (Auto_tac); |
8009 | 1039 |
by (asm_full_simp_tac (simpset() addsimps (thms"nth.simps") addsplits [nat.split]) 1); |
1040 |
qed_spec_mp "nth_zip"; |
|
1041 |
Addsimps [nth_zip]; |
|
1042 |
||
8118 | 1043 |
Goal "set(zip xs ys) = {(xs!i,ys!i) |i. i < min (length xs) (length ys)}"; |
1044 |
by (simp_tac (simpset() addsimps [set_conv_nth]addcongs [rev_conj_cong]) 1); |
|
1045 |
qed_spec_mp "set_zip"; |
|
1046 |
||
8009 | 1047 |
Goal |
1048 |
"length xs = length ys ==> zip (xs[i:=x]) (ys[i:=y]) = (zip xs ys)[i:=(x,y)]"; |
|
8064 | 1049 |
by (rtac sym 1); |
1050 |
by (asm_simp_tac (simpset() addsimps [update_zip]) 1); |
|
8009 | 1051 |
qed_spec_mp "zip_update"; |
1052 |
||
1053 |
Goal "!j. zip (replicate i x) (replicate j y) = replicate (min i j) (x,y)"; |
|
1054 |
by (induct_tac "i" 1); |
|
8064 | 1055 |
by (Auto_tac); |
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
1056 |
by (case_tac "j" 1); |
8064 | 1057 |
by (Auto_tac); |
8009 | 1058 |
qed "zip_replicate"; |
1059 |
Addsimps [zip_replicate]; |
|
1060 |
||
8115 | 1061 |
(** list_all2 **) |
1062 |
section "list_all2"; |
|
1063 |
||
1064 |
Goalw [list_all2_def] "list_all2 P xs ys ==> length xs = length ys"; |
|
8254 | 1065 |
by (Asm_simp_tac 1); |
8115 | 1066 |
qed "list_all2_lengthD"; |
1067 |
||
1068 |
Goalw [list_all2_def] "list_all2 P [] ys = (ys=[])"; |
|
1069 |
by (Simp_tac 1); |
|
1070 |
qed "list_all2_Nil"; |
|
1071 |
AddIffs [list_all2_Nil]; |
|
1072 |
||
1073 |
Goalw [list_all2_def] "list_all2 P xs [] = (xs=[])"; |
|
1074 |
by (Simp_tac 1); |
|
1075 |
qed "list_all2_Nil2"; |
|
1076 |
AddIffs [list_all2_Nil2]; |
|
1077 |
||
1078 |
Goalw [list_all2_def] |
|
1079 |
"list_all2 P (x#xs) (y#ys) = (P x y & list_all2 P xs ys)"; |
|
1080 |
by (Auto_tac); |
|
1081 |
qed "list_all2_Cons"; |
|
1082 |
AddIffs[list_all2_Cons]; |
|
1083 |
||
1084 |
Goalw [list_all2_def] |
|
8118 | 1085 |
"list_all2 P (x#xs) ys = (? z zs. ys = z#zs & P x z & list_all2 P xs zs)"; |
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
1086 |
by (case_tac "ys" 1); |
8254 | 1087 |
by (Auto_tac); |
8118 | 1088 |
qed "list_all2_Cons1"; |
1089 |
||
1090 |
Goalw [list_all2_def] |
|
1091 |
"list_all2 P xs (y#ys) = (? z zs. xs = z#zs & P z y & list_all2 P zs ys)"; |
|
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
1092 |
by (case_tac "xs" 1); |
8254 | 1093 |
by (Auto_tac); |
8118 | 1094 |
qed "list_all2_Cons2"; |
1095 |
||
1096 |
Goalw [list_all2_def] |
|
1097 |
"list_all2 P (xs@ys) zs = \ |
|
1098 |
\ (EX us vs. zs = us@vs & length us = length xs & length vs = length ys & \ |
|
1099 |
\ list_all2 P xs us & list_all2 P ys vs)"; |
|
8254 | 1100 |
by (simp_tac (simpset() addsimps [zip_append1]) 1); |
1101 |
by (rtac iffI 1); |
|
1102 |
by (res_inst_tac [("x","take (length xs) zs")] exI 1); |
|
1103 |
by (res_inst_tac [("x","drop (length xs) zs")] exI 1); |
|
1104 |
by (asm_full_simp_tac (simpset() addsimps [min_def,eq_sym_conv]) 1); |
|
8118 | 1105 |
by (Clarify_tac 1); |
8254 | 1106 |
by (asm_full_simp_tac (simpset() addsimps [ball_Un]) 1); |
8118 | 1107 |
qed "list_all2_append1"; |
1108 |
||
1109 |
Goalw [list_all2_def] |
|
1110 |
"list_all2 P xs (ys@zs) = \ |
|
1111 |
\ (EX us vs. xs = us@vs & length us = length ys & length vs = length zs & \ |
|
1112 |
\ list_all2 P us ys & list_all2 P vs zs)"; |
|
8254 | 1113 |
by (simp_tac (simpset() addsimps [zip_append2]) 1); |
1114 |
by (rtac iffI 1); |
|
1115 |
by (res_inst_tac [("x","take (length ys) xs")] exI 1); |
|
1116 |
by (res_inst_tac [("x","drop (length ys) xs")] exI 1); |
|
1117 |
by (asm_full_simp_tac (simpset() addsimps [min_def,eq_sym_conv]) 1); |
|
8118 | 1118 |
by (Clarify_tac 1); |
8254 | 1119 |
by (asm_full_simp_tac (simpset() addsimps [ball_Un]) 1); |
8118 | 1120 |
qed "list_all2_append2"; |
1121 |
||
1122 |
Goalw [list_all2_def] |
|
8115 | 1123 |
"list_all2 P xs ys = \ |
1124 |
\ (length xs = length ys & (!i<length xs. P (xs!i) (ys!i)))"; |
|
8254 | 1125 |
by (force_tac (claset(), simpset() addsimps [set_zip]) 1); |
8115 | 1126 |
qed "list_all2_conv_all_nth"; |
5272 | 1127 |
|
1128 |
(** foldl **) |
|
1129 |
section "foldl"; |
|
1130 |
||
1131 |
Goal "!a. foldl f a (xs @ ys) = foldl f (foldl f a xs) ys"; |
|
5318 | 1132 |
by (induct_tac "xs" 1); |
5316 | 1133 |
by Auto_tac; |
5272 | 1134 |
qed_spec_mp "foldl_append"; |
1135 |
Addsimps [foldl_append]; |
|
1136 |
||
1137 |
(* Note: `n <= foldl op+ n ns' looks simpler, but is more difficult to use |
|
1138 |
because it requires an additional transitivity step |
|
1139 |
*) |
|
1140 |
Goal "!n::nat. m <= n --> m <= foldl op+ n ns"; |
|
5318 | 1141 |
by (induct_tac "ns" 1); |
6058 | 1142 |
by Auto_tac; |
5272 | 1143 |
qed_spec_mp "start_le_sum"; |
1144 |
||
8935
548901d05a0e
added type constraint ::nat because 0 is now overloaded
paulson
parents:
8741
diff
changeset
|
1145 |
Goal "!!n::nat. n : set ns ==> n <= foldl op+ 0 ns"; |
5758
27a2b36efd95
corrected auto_tac (applications of unsafe wrappers)
oheimb
parents:
5644
diff
changeset
|
1146 |
by (force_tac (claset() addIs [start_le_sum], |
27a2b36efd95
corrected auto_tac (applications of unsafe wrappers)
oheimb
parents:
5644
diff
changeset
|
1147 |
simpset() addsimps [in_set_conv_decomp]) 1); |
5272 | 1148 |
qed "elem_le_sum"; |
1149 |
||
8935
548901d05a0e
added type constraint ::nat because 0 is now overloaded
paulson
parents:
8741
diff
changeset
|
1150 |
Goal "!m::nat. (foldl op+ m ns = 0) = (m=0 & (!n : set ns. n=0))"; |
5318 | 1151 |
by (induct_tac "ns" 1); |
5316 | 1152 |
by Auto_tac; |
5272 | 1153 |
qed_spec_mp "sum_eq_0_conv"; |
1154 |
AddIffs [sum_eq_0_conv]; |
|
1155 |
||
5425 | 1156 |
(** upto **) |
1157 |
||
5427 | 1158 |
(* Does not terminate! *) |
1159 |
Goal "[i..j(] = (if i<j then i#[Suc i..j(] else [])"; |
|
6162 | 1160 |
by (induct_tac "j" 1); |
5427 | 1161 |
by Auto_tac; |
1162 |
qed "upt_rec"; |
|
5425 | 1163 |
|
5427 | 1164 |
Goal "j<=i ==> [i..j(] = []"; |
6162 | 1165 |
by (stac upt_rec 1); |
1166 |
by (Asm_simp_tac 1); |
|
5427 | 1167 |
qed "upt_conv_Nil"; |
1168 |
Addsimps [upt_conv_Nil]; |
|
1169 |
||
8982
4cb682fc083d
renamed upt_Suc, since that name is needed for its primrec rule
paulson
parents:
8935
diff
changeset
|
1170 |
(*Only needed if upt_Suc is deleted from the simpset*) |
5427 | 1171 |
Goal "i<=j ==> [i..(Suc j)(] = [i..j(]@[j]"; |
1172 |
by (Asm_simp_tac 1); |
|
8982
4cb682fc083d
renamed upt_Suc, since that name is needed for its primrec rule
paulson
parents:
8935
diff
changeset
|
1173 |
qed "upt_Suc_append"; |
5427 | 1174 |
|
1175 |
Goal "i<j ==> [i..j(] = i#[Suc i..j(]"; |
|
6162 | 1176 |
by (rtac trans 1); |
1177 |
by (stac upt_rec 1); |
|
1178 |
by (rtac refl 2); |
|
5427 | 1179 |
by (Asm_simp_tac 1); |
1180 |
qed "upt_conv_Cons"; |
|
1181 |
||
9003 | 1182 |
(*LOOPS as a simprule, since j<=j*) |
1183 |
Goal "i<=j ==> [i..j+k(] = [i..j(]@[j..j+k(]"; |
|
1184 |
by (induct_tac "k" 1); |
|
1185 |
by Auto_tac; |
|
1186 |
qed "upt_add_eq_append"; |
|
1187 |
||
5427 | 1188 |
Goal "length [i..j(] = j-i"; |
6162 | 1189 |
by (induct_tac "j" 1); |
5427 | 1190 |
by (Simp_tac 1); |
6162 | 1191 |
by (asm_simp_tac (simpset() addsimps [Suc_diff_le]) 1); |
5427 | 1192 |
qed "length_upt"; |
1193 |
Addsimps [length_upt]; |
|
5425 | 1194 |
|
5427 | 1195 |
Goal "i+k < j --> [i..j(] ! k = i+k"; |
6162 | 1196 |
by (induct_tac "j" 1); |
9014 | 1197 |
by (asm_simp_tac (simpset() addsimps [less_Suc_eq, nth_append] |
1198 |
addsplits [nat_diff_split]) 2); |
|
1199 |
by (Simp_tac 1); |
|
5427 | 1200 |
qed_spec_mp "nth_upt"; |
1201 |
Addsimps [nth_upt]; |
|
5425 | 1202 |
|
6433 | 1203 |
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
|
1204 |
by (induct_tac "m" 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1205 |
by (Simp_tac 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1206 |
by (Clarify_tac 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1207 |
by (stac upt_rec 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1208 |
by (rtac sym 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1209 |
by (stac upt_rec 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1210 |
by (asm_simp_tac (simpset() delsimps (thms"upt.simps")) 1); |
6433 | 1211 |
qed_spec_mp "take_upt"; |
1212 |
Addsimps [take_upt]; |
|
1213 |
||
9003 | 1214 |
Goal "map Suc [m..n(] = [Suc m..n]"; |
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1215 |
by (induct_tac "n" 1); |
9003 | 1216 |
by Auto_tac; |
1217 |
qed "map_Suc_upt"; |
|
1218 |
||
1219 |
Goal "ALL i. i < n-m --> (map f [m..n(]) ! i = f(m+i)"; |
|
9747 | 1220 |
by (induct_thm_tac diff_induct "n m" 1); |
9003 | 1221 |
by (stac (map_Suc_upt RS sym) 3); |
1222 |
by (auto_tac (claset(), simpset() addsimps [less_diff_conv, nth_upt])); |
|
6433 | 1223 |
qed_spec_mp "nth_map_upt"; |
1224 |
||
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1225 |
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
|
1226 |
\ (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
|
1227 |
\ --> take k xs = take k ys"; |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1228 |
by (induct_tac "k" 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1229 |
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
|
1230 |
all_conj_distrib]))); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1231 |
by (Clarify_tac 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1232 |
(*Both lists must be non-empty*) |
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
1233 |
by (case_tac "xs" 1); |
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
1234 |
by (case_tac "ys" 2); |
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1235 |
by (ALLGOALS Clarify_tac); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1236 |
(*prenexing's needed, not miniscoping*) |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1237 |
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
|
1238 |
delsimps (all_simps)))); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1239 |
by (Blast_tac 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1240 |
qed_spec_mp "nth_take_lemma"; |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1241 |
|
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1242 |
Goal "[| length xs = length ys; \ |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1243 |
\ 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
|
1244 |
\ ==> xs = ys"; |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1245 |
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
|
1246 |
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
|
1247 |
qed_spec_mp "nth_equalityI"; |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1248 |
|
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1249 |
(*The famous take-lemma*) |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1250 |
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
|
1251 |
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
|
1252 |
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
|
1253 |
qed_spec_mp "take_equalityI"; |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1254 |
|
5272 | 1255 |
|
4605 | 1256 |
(** nodups & remdups **) |
1257 |
section "nodups & remdups"; |
|
1258 |
||
4935 | 1259 |
Goal "set(remdups xs) = set xs"; |
4605 | 1260 |
by (induct_tac "xs" 1); |
1261 |
by (Simp_tac 1); |
|
4686 | 1262 |
by (asm_full_simp_tac (simpset() addsimps [insert_absorb]) 1); |
4605 | 1263 |
qed "set_remdups"; |
1264 |
Addsimps [set_remdups]; |
|
1265 |
||
4935 | 1266 |
Goal "nodups(remdups xs)"; |
4605 | 1267 |
by (induct_tac "xs" 1); |
5316 | 1268 |
by Auto_tac; |
4605 | 1269 |
qed "nodups_remdups"; |
1270 |
||
4935 | 1271 |
Goal "nodups xs --> nodups (filter P xs)"; |
4605 | 1272 |
by (induct_tac "xs" 1); |
5316 | 1273 |
by Auto_tac; |
4605 | 1274 |
qed_spec_mp "nodups_filter"; |
1275 |
||
3589
244daa75f890
Added function `replicate' and lemmas map_cong and set_replicate.
nipkow
parents:
3586
diff
changeset
|
1276 |
(** replicate **) |
244daa75f890
Added function `replicate' and lemmas map_cong and set_replicate.
nipkow
parents:
3586
diff
changeset
|
1277 |
section "replicate"; |
244daa75f890
Added function `replicate' and lemmas map_cong and set_replicate.
nipkow
parents:
3586
diff
changeset
|
1278 |
|
6794 | 1279 |
Goal "length(replicate n x) = n"; |
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1280 |
by (induct_tac "n" 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1281 |
by Auto_tac; |
6794 | 1282 |
qed "length_replicate"; |
1283 |
Addsimps [length_replicate]; |
|
1284 |
||
1285 |
Goal "map f (replicate n x) = replicate n (f x)"; |
|
1286 |
by (induct_tac "n" 1); |
|
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1287 |
by Auto_tac; |
6794 | 1288 |
qed "map_replicate"; |
1289 |
Addsimps [map_replicate]; |
|
1290 |
||
1291 |
Goal "(replicate n x) @ (x#xs) = x # replicate n x @ xs"; |
|
1292 |
by (induct_tac "n" 1); |
|
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1293 |
by Auto_tac; |
6794 | 1294 |
qed "replicate_app_Cons_same"; |
1295 |
||
1296 |
Goal "rev(replicate n x) = replicate n x"; |
|
1297 |
by (induct_tac "n" 1); |
|
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1298 |
by (Simp_tac 1); |
6794 | 1299 |
by (asm_simp_tac (simpset() addsimps [replicate_app_Cons_same]) 1); |
1300 |
qed "rev_replicate"; |
|
1301 |
Addsimps [rev_replicate]; |
|
1302 |
||
8009 | 1303 |
Goal "replicate (n+m) x = replicate n x @ replicate m x"; |
1304 |
by (induct_tac "n" 1); |
|
1305 |
by Auto_tac; |
|
1306 |
qed "replicate_add"; |
|
1307 |
||
6794 | 1308 |
Goal"n ~= 0 --> hd(replicate n x) = x"; |
1309 |
by (induct_tac "n" 1); |
|
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1310 |
by Auto_tac; |
6794 | 1311 |
qed_spec_mp "hd_replicate"; |
1312 |
Addsimps [hd_replicate]; |
|
1313 |
||
1314 |
Goal "n ~= 0 --> tl(replicate n x) = replicate (n-1) x"; |
|
1315 |
by (induct_tac "n" 1); |
|
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1316 |
by Auto_tac; |
6794 | 1317 |
qed_spec_mp "tl_replicate"; |
1318 |
Addsimps [tl_replicate]; |
|
1319 |
||
1320 |
Goal "n ~= 0 --> last(replicate n x) = x"; |
|
1321 |
by (induct_tac "n" 1); |
|
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1322 |
by Auto_tac; |
6794 | 1323 |
qed_spec_mp "last_replicate"; |
1324 |
Addsimps [last_replicate]; |
|
1325 |
||
1326 |
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
|
1327 |
by (induct_tac "n" 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1328 |
by (Simp_tac 1); |
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1329 |
by (asm_simp_tac (simpset() addsimps [nth_Cons] addsplits [nat.split]) 1); |
6794 | 1330 |
qed_spec_mp "nth_replicate"; |
1331 |
Addsimps [nth_replicate]; |
|
1332 |
||
4935 | 1333 |
Goal "set(replicate (Suc n) x) = {x}"; |
4423 | 1334 |
by (induct_tac "n" 1); |
5316 | 1335 |
by Auto_tac; |
3589
244daa75f890
Added function `replicate' and lemmas map_cong and set_replicate.
nipkow
parents:
3586
diff
changeset
|
1336 |
val lemma = result(); |
244daa75f890
Added function `replicate' and lemmas map_cong and set_replicate.
nipkow
parents:
3586
diff
changeset
|
1337 |
|
5043 | 1338 |
Goal "n ~= 0 ==> set(replicate n x) = {x}"; |
4423 | 1339 |
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
|
1340 |
qed "set_replicate"; |
244daa75f890
Added function `replicate' and lemmas map_cong and set_replicate.
nipkow
parents:
3586
diff
changeset
|
1341 |
Addsimps [set_replicate]; |
5162 | 1342 |
|
8009 | 1343 |
Goal "set(replicate n x) = (if n=0 then {} else {x})"; |
8064 | 1344 |
by (Auto_tac); |
8009 | 1345 |
qed "set_replicate_conv_if"; |
1346 |
||
1347 |
Goal "x : set(replicate n y) --> x=y"; |
|
8064 | 1348 |
by (asm_simp_tac (simpset() addsimps [set_replicate_conv_if]) 1); |
8009 | 1349 |
qed_spec_mp "in_set_replicateD"; |
1350 |
||
5162 | 1351 |
|
5281 | 1352 |
(*** Lexcicographic orderings on lists ***) |
1353 |
section"Lexcicographic orderings on lists"; |
|
1354 |
||
1355 |
Goal "wf r ==> wf(lexn r n)"; |
|
5318 | 1356 |
by (induct_tac "n" 1); |
1357 |
by (Simp_tac 1); |
|
1358 |
by (Simp_tac 1); |
|
1359 |
by (rtac wf_subset 1); |
|
1360 |
by (rtac Int_lower1 2); |
|
1361 |
by (rtac wf_prod_fun_image 1); |
|
1362 |
by (rtac injI 2); |
|
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1363 |
by Auto_tac; |
5281 | 1364 |
qed "wf_lexn"; |
1365 |
||
1366 |
Goal "!xs ys. (xs,ys) : lexn r n --> length xs = n & length ys = n"; |
|
5318 | 1367 |
by (induct_tac "n" 1); |
6813
bf90f86502b2
many new lemmas about take & drop, incl the famous take-lemma
paulson
parents:
6794
diff
changeset
|
1368 |
by Auto_tac; |
5281 | 1369 |
qed_spec_mp "lexn_length"; |
1370 |
||
1371 |
Goalw [lex_def] "wf r ==> wf(lex r)"; |
|
5318 | 1372 |
by (rtac wf_UN 1); |
1373 |
by (blast_tac (claset() addIs [wf_lexn]) 1); |
|
1374 |
by (Clarify_tac 1); |
|
1375 |
by (rename_tac "m n" 1); |
|
1376 |
by (subgoal_tac "m ~= n" 1); |
|
1377 |
by (Blast_tac 2); |
|
1378 |
by (blast_tac (claset() addDs [lexn_length,not_sym]) 1); |
|
5281 | 1379 |
qed "wf_lex"; |
1380 |
AddSIs [wf_lex]; |
|
1381 |
||
1382 |
Goal |
|
1383 |
"lexn r n = \ |
|
1384 |
\ {(xs,ys). length xs = n & length ys = n & \ |
|
1385 |
\ (? xys x y xs' ys'. xs= xys @ x#xs' & ys= xys @ y#ys' & (x,y):r)}"; |
|
5318 | 1386 |
by (induct_tac "n" 1); |
1387 |
by (Simp_tac 1); |
|
1388 |
by (Blast_tac 1); |
|
5641 | 1389 |
by (asm_full_simp_tac (simpset() |
5296 | 1390 |
addsimps [lex_prod_def]) 1); |
5641 | 1391 |
by (auto_tac (claset(), simpset())); |
5318 | 1392 |
by (Blast_tac 1); |
1393 |
by (rename_tac "a xys x xs' y ys'" 1); |
|
1394 |
by (res_inst_tac [("x","a#xys")] exI 1); |
|
1395 |
by (Simp_tac 1); |
|
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
1396 |
by (case_tac "xys" 1); |
5641 | 1397 |
by (ALLGOALS (asm_full_simp_tac (simpset()))); |
5318 | 1398 |
by (Blast_tac 1); |
5281 | 1399 |
qed "lexn_conv"; |
1400 |
||
1401 |
Goalw [lex_def] |
|
1402 |
"lex r = \ |
|
1403 |
\ {(xs,ys). length xs = length ys & \ |
|
1404 |
\ (? xys x y xs' ys'. xs= xys @ x#xs' & ys= xys @ y#ys' & (x,y):r)}"; |
|
5641 | 1405 |
by (force_tac (claset(), simpset() addsimps [lexn_conv]) 1); |
5281 | 1406 |
qed "lex_conv"; |
1407 |
||
1408 |
Goalw [lexico_def] "wf r ==> wf(lexico r)"; |
|
5318 | 1409 |
by (Blast_tac 1); |
5281 | 1410 |
qed "wf_lexico"; |
1411 |
AddSIs [wf_lexico]; |
|
1412 |
||
1413 |
Goalw |
|
1414 |
[lexico_def,diag_def,lex_prod_def,measure_def,inv_image_def] |
|
1415 |
"lexico r = {(xs,ys). length xs < length ys | \ |
|
1416 |
\ length xs = length ys & (xs,ys) : lex r}"; |
|
5318 | 1417 |
by (Simp_tac 1); |
5281 | 1418 |
qed "lexico_conv"; |
1419 |
||
5283 | 1420 |
Goal "([],ys) ~: lex r"; |
5318 | 1421 |
by (simp_tac (simpset() addsimps [lex_conv]) 1); |
5283 | 1422 |
qed "Nil_notin_lex"; |
1423 |
||
1424 |
Goal "(xs,[]) ~: lex r"; |
|
5318 | 1425 |
by (simp_tac (simpset() addsimps [lex_conv]) 1); |
5283 | 1426 |
qed "Nil2_notin_lex"; |
1427 |
||
1428 |
AddIffs [Nil_notin_lex,Nil2_notin_lex]; |
|
1429 |
||
1430 |
Goal "((x#xs,y#ys) : lex r) = \ |
|
1431 |
\ ((x,y) : r & length xs = length ys | x=y & (xs,ys) : lex r)"; |
|
5318 | 1432 |
by (simp_tac (simpset() addsimps [lex_conv]) 1); |
1433 |
by (rtac iffI 1); |
|
1434 |
by (blast_tac (claset() addIs [Cons_eq_appendI]) 2); |
|
1435 |
by (REPEAT(eresolve_tac [conjE, exE] 1)); |
|
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
1436 |
by (case_tac "xys" 1); |
5318 | 1437 |
by (Asm_full_simp_tac 1); |
1438 |
by (Asm_full_simp_tac 1); |
|
1439 |
by (Blast_tac 1); |
|
5283 | 1440 |
qed "Cons_in_lex"; |
1441 |
AddIffs [Cons_in_lex]; |
|
7032 | 1442 |
|
1443 |
||
9336 | 1444 |
(*** sublist (a generalization of nth to sets) ***) |
1445 |
||
1446 |
Goalw [sublist_def] "sublist l {} = []"; |
|
1447 |
by Auto_tac; |
|
1448 |
qed "sublist_empty"; |
|
1449 |
||
1450 |
Goalw [sublist_def] "sublist [] A = []"; |
|
1451 |
by Auto_tac; |
|
1452 |
qed "sublist_nil"; |
|
1453 |
||
1454 |
Goal "map fst [p:zip xs [i..i + length xs(] . snd p : A] = \ |
|
1455 |
\ map fst [p:zip xs [0..length xs(] . snd p + i : A]"; |
|
9747 | 1456 |
by (rev_induct_tac "xs" 1); |
9336 | 1457 |
by (asm_simp_tac (simpset() addsimps [add_commute]) 2); |
1458 |
by (Simp_tac 1); |
|
1459 |
qed "sublist_shift_lemma"; |
|
1460 |
||
1461 |
Goalw [sublist_def] |
|
1462 |
"sublist (l@l') A = sublist l A @ sublist l' {j. j + length l : A}"; |
|
9747 | 1463 |
by (rev_induct_tac "l'" 1); |
9336 | 1464 |
by (Simp_tac 1); |
1465 |
by (asm_simp_tac (simpset() addsimps [inst "i" "0" upt_add_eq_append, |
|
1466 |
zip_append, sublist_shift_lemma]) 1); |
|
1467 |
by (asm_simp_tac (simpset() addsimps [add_commute]) 1); |
|
1468 |
qed "sublist_append"; |
|
1469 |
||
1470 |
Addsimps [sublist_empty, sublist_nil]; |
|
1471 |
||
1472 |
Goal "sublist (x#l) A = (if 0:A then [x] else []) @ sublist l {j. Suc j : A}"; |
|
9747 | 1473 |
by (rev_induct_tac "l" 1); |
9336 | 1474 |
by (asm_simp_tac (simpset() delsimps [append_Cons] |
1475 |
addsimps [append_Cons RS sym, sublist_append]) 2); |
|
1476 |
by (simp_tac (simpset() addsimps [sublist_def]) 1); |
|
1477 |
qed "sublist_Cons"; |
|
1478 |
||
1479 |
Goal "sublist [x] A = (if 0 : A then [x] else [])"; |
|
1480 |
by (simp_tac (simpset() addsimps [sublist_Cons]) 1); |
|
1481 |
qed "sublist_singleton"; |
|
1482 |
Addsimps [sublist_singleton]; |
|
1483 |
||
1484 |
Goal "sublist l {..n(} = take n l"; |
|
9747 | 1485 |
by (rev_induct_tac "l" 1); |
9336 | 1486 |
by (asm_simp_tac (simpset() addsplits [nat_diff_split] |
1487 |
addsimps [sublist_append]) 2); |
|
1488 |
by (Simp_tac 1); |
|
1489 |
qed "sublist_upt_eq_take"; |
|
1490 |
Addsimps [sublist_upt_eq_take]; |
|
1491 |
||
1492 |
||
7032 | 1493 |
(*** Versions of some theorems above using binary numerals ***) |
1494 |
||
9423 | 1495 |
AddIffs (map rename_numerals |
7032 | 1496 |
[length_0_conv, zero_length_conv, length_greater_0_conv, |
1497 |
sum_eq_0_conv]); |
|
1498 |
||
1499 |
Goal "take n (x#xs) = (if n = #0 then [] else x # take (n-#1) xs)"; |
|
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
1500 |
by (case_tac "n" 1); |
7032 | 1501 |
by (ALLGOALS |
1502 |
(asm_simp_tac (simpset() addsimps [numeral_0_eq_0, numeral_1_eq_1]))); |
|
1503 |
qed "take_Cons'"; |
|
1504 |
||
1505 |
Goal "drop n (x#xs) = (if n = #0 then x#xs else drop (n-#1) xs)"; |
|
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
1506 |
by (case_tac "n" 1); |
7032 | 1507 |
by (ALLGOALS |
1508 |
(asm_simp_tac (simpset() addsimps [numeral_0_eq_0, numeral_1_eq_1]))); |
|
1509 |
qed "drop_Cons'"; |
|
1510 |
||
1511 |
Goal "(x#xs)!n = (if n = #0 then x else xs!(n-#1))"; |
|
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
1512 |
by (case_tac "n" 1); |
7032 | 1513 |
by (ALLGOALS |
1514 |
(asm_simp_tac (simpset() addsimps [numeral_0_eq_0, numeral_1_eq_1]))); |
|
1515 |
qed "nth_Cons'"; |
|
1516 |
||
1517 |
Addsimps (map (inst "n" "number_of ?v") [take_Cons', drop_Cons', nth_Cons']); |
|
1518 |