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