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