author | wenzelm |
Mon, 18 Nov 1996 17:27:59 +0100 | |
changeset 2195 | e8271379ba4b |
parent 2033 | 639de962ded4 |
child 2469 | b50b8c0eec01 |
permissions | -rw-r--r-- |
1461 | 1 |
(* Title: ZF/List.ML |
0 | 2 |
ID: $Id$ |
1461 | 3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
0 | 4 |
Copyright 1993 University of Cambridge |
5 |
||
6 |
Datatype definition of Lists |
|
7 |
*) |
|
8 |
||
516 | 9 |
open List; |
0 | 10 |
|
516 | 11 |
(*** Aspects of the datatype definition ***) |
0 | 12 |
|
13 |
(*An elimination rule, for type-checking*) |
|
516 | 14 |
val ConsE = list.mk_cases list.con_defs "Cons(a,l) : list(A)"; |
0 | 15 |
|
16 |
(*Proving freeness results*) |
|
516 | 17 |
val Cons_iff = list.mk_free "Cons(a,l)=Cons(a',l') <-> a=a' & l=l'"; |
18 |
val Nil_Cons_iff = list.mk_free "~ Nil=Cons(a,l)"; |
|
0 | 19 |
|
20 |
(*Perform induction on l, then prove the major premise using prems. *) |
|
21 |
fun list_ind_tac a prems i = |
|
516 | 22 |
EVERY [res_inst_tac [("x",a)] list.induct i, |
1461 | 23 |
rename_last_tac a ["1"] (i+2), |
24 |
ares_tac prems i]; |
|
0 | 25 |
|
435 | 26 |
goal List.thy "list(A) = {0} + (A * list(A))"; |
525
e62519a8497d
ZF/List, ex/Brouwer,Data,LList,Ntree,TF,Term: much simplified proof of _unfold
lcp
parents:
516
diff
changeset
|
27 |
let open list; val rew = rewrite_rule con_defs in |
e62519a8497d
ZF/List, ex/Brouwer,Data,LList,Ntree,TF,Term: much simplified proof of _unfold
lcp
parents:
516
diff
changeset
|
28 |
by (fast_tac (sum_cs addSIs (equalityI :: map rew intrs) |
e62519a8497d
ZF/List, ex/Brouwer,Data,LList,Ntree,TF,Term: much simplified proof of _unfold
lcp
parents:
516
diff
changeset
|
29 |
addEs [rew elim]) 1) |
e62519a8497d
ZF/List, ex/Brouwer,Data,LList,Ntree,TF,Term: much simplified proof of _unfold
lcp
parents:
516
diff
changeset
|
30 |
end; |
760 | 31 |
qed "list_unfold"; |
435 | 32 |
|
0 | 33 |
(** Lemmas to justify using "list" in other recursive type definitions **) |
34 |
||
516 | 35 |
goalw List.thy list.defs "!!A B. A<=B ==> list(A) <= list(B)"; |
0 | 36 |
by (rtac lfp_mono 1); |
516 | 37 |
by (REPEAT (rtac list.bnd_mono 1)); |
0 | 38 |
by (REPEAT (ares_tac (univ_mono::basic_monos) 1)); |
760 | 39 |
qed "list_mono"; |
0 | 40 |
|
41 |
(*There is a similar proof by list induction.*) |
|
516 | 42 |
goalw List.thy (list.defs@list.con_defs) "list(univ(A)) <= univ(A)"; |
0 | 43 |
by (rtac lfp_lowerbound 1); |
44 |
by (rtac (A_subset_univ RS univ_mono) 2); |
|
45 |
by (fast_tac (ZF_cs addSIs [zero_in_univ, Inl_in_univ, Inr_in_univ, |
|
1461 | 46 |
Pair_in_univ]) 1); |
760 | 47 |
qed "list_univ"; |
0 | 48 |
|
908
1f99a44c10cb
Updated comment about list_subset_univ and list_into_univ.
lcp
parents:
782
diff
changeset
|
49 |
(*These two theorems justify datatypes involving list(nat), list(A), ...*) |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
50 |
bind_thm ("list_subset_univ", ([list_mono, list_univ] MRS subset_trans)); |
0 | 51 |
|
435 | 52 |
goal List.thy "!!l A B. [| l: list(A); A <= univ(B) |] ==> l: univ(B)"; |
53 |
by (REPEAT (ares_tac [list_subset_univ RS subsetD] 1)); |
|
760 | 54 |
qed "list_into_univ"; |
435 | 55 |
|
0 | 56 |
val major::prems = goal List.thy |
57 |
"[| l: list(A); \ |
|
15
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
58 |
\ c: C(Nil); \ |
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
59 |
\ !!x y. [| x: A; y: list(A) |] ==> h(x,y): C(Cons(x,y)) \ |
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
60 |
\ |] ==> list_case(c,h,l) : C(l)"; |
516 | 61 |
by (rtac (major RS list.induct) 1); |
62 |
by (ALLGOALS (asm_simp_tac (ZF_ss addsimps (list.case_eqns @ prems)))); |
|
760 | 63 |
qed "list_case_type"; |
0 | 64 |
|
65 |
||
66 |
(** For recursion **) |
|
67 |
||
516 | 68 |
goalw List.thy list.con_defs "rank(a) < rank(Cons(a,l))"; |
6
8ce8c4d13d4d
Installation of new simplifier for ZF. Deleted all congruence rules not
lcp
parents:
0
diff
changeset
|
69 |
by (simp_tac rank_ss 1); |
760 | 70 |
qed "rank_Cons1"; |
0 | 71 |
|
516 | 72 |
goalw List.thy list.con_defs "rank(l) < rank(Cons(a,l))"; |
6
8ce8c4d13d4d
Installation of new simplifier for ZF. Deleted all congruence rules not
lcp
parents:
0
diff
changeset
|
73 |
by (simp_tac rank_ss 1); |
760 | 74 |
qed "rank_Cons2"; |
0 | 75 |
|
516 | 76 |
|
77 |
(*** List functions ***) |
|
78 |
||
79 |
(** hd and tl **) |
|
80 |
||
81 |
goalw List.thy [hd_def] "hd(Cons(a,l)) = a"; |
|
82 |
by (resolve_tac list.case_eqns 1); |
|
760 | 83 |
qed "hd_Cons"; |
516 | 84 |
|
85 |
goalw List.thy [tl_def] "tl(Nil) = Nil"; |
|
86 |
by (resolve_tac list.case_eqns 1); |
|
760 | 87 |
qed "tl_Nil"; |
516 | 88 |
|
89 |
goalw List.thy [tl_def] "tl(Cons(a,l)) = l"; |
|
90 |
by (resolve_tac list.case_eqns 1); |
|
760 | 91 |
qed "tl_Cons"; |
516 | 92 |
|
93 |
goal List.thy "!!l. l: list(A) ==> tl(l) : list(A)"; |
|
94 |
by (etac list.elim 1); |
|
95 |
by (ALLGOALS (asm_simp_tac (ZF_ss addsimps (list.intrs @ [tl_Nil,tl_Cons])))); |
|
760 | 96 |
qed "tl_type"; |
516 | 97 |
|
98 |
(** drop **) |
|
99 |
||
100 |
goalw List.thy [drop_def] "drop(0, l) = l"; |
|
101 |
by (rtac rec_0 1); |
|
760 | 102 |
qed "drop_0"; |
516 | 103 |
|
104 |
goalw List.thy [drop_def] "!!i. i:nat ==> drop(i, Nil) = Nil"; |
|
105 |
by (etac nat_induct 1); |
|
106 |
by (ALLGOALS (asm_simp_tac (nat_ss addsimps [tl_Nil]))); |
|
760 | 107 |
qed "drop_Nil"; |
516 | 108 |
|
109 |
goalw List.thy [drop_def] |
|
110 |
"!!i. i:nat ==> drop(succ(i), Cons(a,l)) = drop(i,l)"; |
|
111 |
by (etac nat_induct 1); |
|
1663
7e84d8712a0b
adapted proof of drop_succ_Cons: problem with non-confluent simpset removed
oheimb
parents:
1461
diff
changeset
|
112 |
by (simp_tac (nat_ss addsimps [tl_Cons]) 1); |
2033 | 113 |
by (stac rec_succ 1); |
114 |
by (stac rec_succ 1); |
|
1663
7e84d8712a0b
adapted proof of drop_succ_Cons: problem with non-confluent simpset removed
oheimb
parents:
1461
diff
changeset
|
115 |
by (asm_simp_tac ZF_ss 1); |
760 | 116 |
qed "drop_succ_Cons"; |
516 | 117 |
|
118 |
goalw List.thy [drop_def] |
|
119 |
"!!i l. [| i:nat; l: list(A) |] ==> drop(i,l) : list(A)"; |
|
120 |
by (etac nat_induct 1); |
|
121 |
by (ALLGOALS (asm_simp_tac (nat_ss addsimps [tl_type]))); |
|
760 | 122 |
qed "drop_type"; |
516 | 123 |
|
124 |
(** list_rec -- by Vset recursion **) |
|
125 |
||
126 |
goal List.thy "list_rec(Nil,c,h) = c"; |
|
127 |
by (rtac (list_rec_def RS def_Vrec RS trans) 1); |
|
128 |
by (simp_tac (ZF_ss addsimps list.case_eqns) 1); |
|
760 | 129 |
qed "list_rec_Nil"; |
516 | 130 |
|
131 |
goal List.thy "list_rec(Cons(a,l), c, h) = h(a, l, list_rec(l,c,h))"; |
|
132 |
by (rtac (list_rec_def RS def_Vrec RS trans) 1); |
|
133 |
by (simp_tac (rank_ss addsimps (rank_Cons2::list.case_eqns)) 1); |
|
760 | 134 |
qed "list_rec_Cons"; |
516 | 135 |
|
136 |
(*Type checking -- proved by induction, as usual*) |
|
137 |
val prems = goal List.thy |
|
138 |
"[| l: list(A); \ |
|
139 |
\ c: C(Nil); \ |
|
140 |
\ !!x y r. [| x:A; y: list(A); r: C(y) |] ==> h(x,y,r): C(Cons(x,y)) \ |
|
141 |
\ |] ==> list_rec(l,c,h) : C(l)"; |
|
142 |
by (list_ind_tac "l" prems 1); |
|
143 |
by (ALLGOALS (asm_simp_tac |
|
1461 | 144 |
(ZF_ss addsimps (prems@[list_rec_Nil,list_rec_Cons])))); |
760 | 145 |
qed "list_rec_type"; |
516 | 146 |
|
147 |
(** Versions for use with definitions **) |
|
148 |
||
149 |
val [rew] = goal List.thy |
|
150 |
"[| !!l. j(l)==list_rec(l, c, h) |] ==> j(Nil) = c"; |
|
151 |
by (rewtac rew); |
|
152 |
by (rtac list_rec_Nil 1); |
|
760 | 153 |
qed "def_list_rec_Nil"; |
516 | 154 |
|
155 |
val [rew] = goal List.thy |
|
156 |
"[| !!l. j(l)==list_rec(l, c, h) |] ==> j(Cons(a,l)) = h(a,l,j(l))"; |
|
157 |
by (rewtac rew); |
|
158 |
by (rtac list_rec_Cons 1); |
|
760 | 159 |
qed "def_list_rec_Cons"; |
516 | 160 |
|
161 |
fun list_recs def = map standard |
|
1461 | 162 |
([def] RL [def_list_rec_Nil, def_list_rec_Cons]); |
516 | 163 |
|
164 |
(** map **) |
|
165 |
||
166 |
val [map_Nil,map_Cons] = list_recs map_def; |
|
167 |
||
168 |
val prems = goalw List.thy [map_def] |
|
169 |
"[| l: list(A); !!x. x: A ==> h(x): B |] ==> map(h,l) : list(B)"; |
|
170 |
by (REPEAT (ares_tac (prems @ list.intrs @ [list_rec_type]) 1)); |
|
760 | 171 |
qed "map_type"; |
516 | 172 |
|
173 |
val [major] = goal List.thy "l: list(A) ==> map(h,l) : list({h(u). u:A})"; |
|
174 |
by (rtac (major RS map_type) 1); |
|
175 |
by (etac RepFunI 1); |
|
760 | 176 |
qed "map_type2"; |
516 | 177 |
|
178 |
(** length **) |
|
179 |
||
180 |
val [length_Nil,length_Cons] = list_recs length_def; |
|
181 |
||
182 |
goalw List.thy [length_def] |
|
183 |
"!!l. l: list(A) ==> length(l) : nat"; |
|
184 |
by (REPEAT (ares_tac [list_rec_type, nat_0I, nat_succI] 1)); |
|
760 | 185 |
qed "length_type"; |
516 | 186 |
|
187 |
(** app **) |
|
188 |
||
189 |
val [app_Nil,app_Cons] = list_recs app_def; |
|
190 |
||
191 |
goalw List.thy [app_def] |
|
192 |
"!!xs ys. [| xs: list(A); ys: list(A) |] ==> xs@ys : list(A)"; |
|
193 |
by (REPEAT (ares_tac [list_rec_type, list.Cons_I] 1)); |
|
760 | 194 |
qed "app_type"; |
516 | 195 |
|
196 |
(** rev **) |
|
197 |
||
198 |
val [rev_Nil,rev_Cons] = list_recs rev_def; |
|
199 |
||
200 |
goalw List.thy [rev_def] |
|
201 |
"!!xs. xs: list(A) ==> rev(xs) : list(A)"; |
|
202 |
by (REPEAT (ares_tac (list.intrs @ [list_rec_type, app_type]) 1)); |
|
760 | 203 |
qed "rev_type"; |
516 | 204 |
|
205 |
||
206 |
(** flat **) |
|
207 |
||
208 |
val [flat_Nil,flat_Cons] = list_recs flat_def; |
|
209 |
||
210 |
goalw List.thy [flat_def] |
|
211 |
"!!ls. ls: list(list(A)) ==> flat(ls) : list(A)"; |
|
212 |
by (REPEAT (ares_tac (list.intrs @ [list_rec_type, app_type]) 1)); |
|
760 | 213 |
qed "flat_type"; |
516 | 214 |
|
215 |
||
1926 | 216 |
(** set_of_list **) |
217 |
||
218 |
val [set_of_list_Nil,set_of_list_Cons] = list_recs set_of_list_def; |
|
219 |
||
220 |
goalw List.thy [set_of_list_def] |
|
221 |
"!!l. l: list(A) ==> set_of_list(l) : Pow(A)"; |
|
2033 | 222 |
by (etac list_rec_type 1); |
1926 | 223 |
by (ALLGOALS (fast_tac ZF_cs)); |
224 |
qed "set_of_list_type"; |
|
225 |
||
226 |
goal List.thy |
|
227 |
"!!l. xs: list(A) ==> \ |
|
228 |
\ set_of_list (xs@ys) = set_of_list(xs) Un set_of_list(ys)"; |
|
229 |
by (etac list.induct 1); |
|
230 |
by (ALLGOALS (asm_simp_tac (ZF_ss addsimps [set_of_list_Nil,set_of_list_Cons, |
|
2033 | 231 |
app_Nil,app_Cons,Un_cons]))); |
1926 | 232 |
qed "set_of_list_append"; |
233 |
||
234 |
||
516 | 235 |
(** list_add **) |
236 |
||
237 |
val [list_add_Nil,list_add_Cons] = list_recs list_add_def; |
|
238 |
||
239 |
goalw List.thy [list_add_def] |
|
240 |
"!!xs. xs: list(nat) ==> list_add(xs) : nat"; |
|
241 |
by (REPEAT (ares_tac [list_rec_type, nat_0I, add_type] 1)); |
|
760 | 242 |
qed "list_add_type"; |
516 | 243 |
|
244 |
(** List simplification **) |
|
245 |
||
246 |
val list_typechecks = |
|
247 |
list.intrs @ |
|
248 |
[list_rec_type, map_type, map_type2, app_type, length_type, |
|
249 |
rev_type, flat_type, list_add_type]; |
|
250 |
||
251 |
val list_ss = arith_ss |
|
252 |
addsimps list.case_eqns |
|
253 |
addsimps [list_rec_Nil, list_rec_Cons, |
|
1461 | 254 |
map_Nil, map_Cons, app_Nil, app_Cons, |
255 |
length_Nil, length_Cons, rev_Nil, rev_Cons, |
|
256 |
flat_Nil, flat_Cons, list_add_Nil, list_add_Cons] |
|
516 | 257 |
setsolver (type_auto_tac list_typechecks); |
258 |
||
259 |
||
260 |
(*** theorems about map ***) |
|
261 |
||
262 |
val prems = goal List.thy |
|
263 |
"l: list(A) ==> map(%u.u, l) = l"; |
|
264 |
by (list_ind_tac "l" prems 1); |
|
265 |
by (ALLGOALS (asm_simp_tac list_ss)); |
|
760 | 266 |
qed "map_ident"; |
516 | 267 |
|
268 |
val prems = goal List.thy |
|
269 |
"l: list(A) ==> map(h, map(j,l)) = map(%u.h(j(u)), l)"; |
|
270 |
by (list_ind_tac "l" prems 1); |
|
271 |
by (ALLGOALS (asm_simp_tac list_ss)); |
|
760 | 272 |
qed "map_compose"; |
516 | 273 |
|
274 |
val prems = goal List.thy |
|
275 |
"xs: list(A) ==> map(h, xs@ys) = map(h,xs) @ map(h,ys)"; |
|
276 |
by (list_ind_tac "xs" prems 1); |
|
277 |
by (ALLGOALS (asm_simp_tac list_ss)); |
|
760 | 278 |
qed "map_app_distrib"; |
516 | 279 |
|
280 |
val prems = goal List.thy |
|
281 |
"ls: list(list(A)) ==> map(h, flat(ls)) = flat(map(map(h),ls))"; |
|
282 |
by (list_ind_tac "ls" prems 1); |
|
283 |
by (ALLGOALS (asm_simp_tac (list_ss addsimps [map_app_distrib]))); |
|
760 | 284 |
qed "map_flat"; |
516 | 285 |
|
286 |
val prems = goal List.thy |
|
287 |
"l: list(A) ==> \ |
|
288 |
\ list_rec(map(h,l), c, d) = \ |
|
289 |
\ list_rec(l, c, %x xs r. d(h(x), map(h,xs), r))"; |
|
290 |
by (list_ind_tac "l" prems 1); |
|
291 |
by (ALLGOALS (asm_simp_tac list_ss)); |
|
760 | 292 |
qed "list_rec_map"; |
516 | 293 |
|
294 |
(** theorems about list(Collect(A,P)) -- used in ex/term.ML **) |
|
295 |
||
296 |
(* c : list(Collect(B,P)) ==> c : list(B) *) |
|
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
297 |
bind_thm ("list_CollectD", (Collect_subset RS list_mono RS subsetD)); |
516 | 298 |
|
299 |
val prems = goal List.thy |
|
300 |
"l: list({x:A. h(x)=j(x)}) ==> map(h,l) = map(j,l)"; |
|
301 |
by (list_ind_tac "l" prems 1); |
|
302 |
by (ALLGOALS (asm_simp_tac list_ss)); |
|
760 | 303 |
qed "map_list_Collect"; |
516 | 304 |
|
305 |
(*** theorems about length ***) |
|
306 |
||
307 |
val prems = goal List.thy |
|
308 |
"xs: list(A) ==> length(map(h,xs)) = length(xs)"; |
|
309 |
by (list_ind_tac "xs" prems 1); |
|
310 |
by (ALLGOALS (asm_simp_tac list_ss)); |
|
760 | 311 |
qed "length_map"; |
516 | 312 |
|
313 |
val prems = goal List.thy |
|
314 |
"xs: list(A) ==> length(xs@ys) = length(xs) #+ length(ys)"; |
|
315 |
by (list_ind_tac "xs" prems 1); |
|
316 |
by (ALLGOALS (asm_simp_tac list_ss)); |
|
760 | 317 |
qed "length_app"; |
516 | 318 |
|
319 |
(* [| m: nat; n: nat |] ==> m #+ succ(n) = succ(n) #+ m |
|
320 |
Used for rewriting below*) |
|
321 |
val add_commute_succ = nat_succI RSN (2,add_commute); |
|
322 |
||
323 |
val prems = goal List.thy |
|
324 |
"xs: list(A) ==> length(rev(xs)) = length(xs)"; |
|
325 |
by (list_ind_tac "xs" prems 1); |
|
326 |
by (ALLGOALS (asm_simp_tac (list_ss addsimps [length_app, add_commute_succ]))); |
|
760 | 327 |
qed "length_rev"; |
516 | 328 |
|
329 |
val prems = goal List.thy |
|
330 |
"ls: list(list(A)) ==> length(flat(ls)) = list_add(map(length,ls))"; |
|
331 |
by (list_ind_tac "ls" prems 1); |
|
332 |
by (ALLGOALS (asm_simp_tac (list_ss addsimps [length_app]))); |
|
760 | 333 |
qed "length_flat"; |
516 | 334 |
|
335 |
(** Length and drop **) |
|
336 |
||
337 |
(*Lemma for the inductive step of drop_length*) |
|
338 |
goal List.thy |
|
339 |
"!!xs. xs: list(A) ==> \ |
|
340 |
\ ALL x. EX z zs. drop(length(xs), Cons(x,xs)) = Cons(z,zs)"; |
|
341 |
by (etac list.induct 1); |
|
342 |
by (ALLGOALS (asm_simp_tac (list_ss addsimps [drop_0,drop_succ_Cons]))); |
|
343 |
by (fast_tac ZF_cs 1); |
|
760 | 344 |
qed "drop_length_Cons_lemma"; |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
345 |
bind_thm ("drop_length_Cons", (drop_length_Cons_lemma RS spec)); |
516 | 346 |
|
347 |
goal List.thy |
|
348 |
"!!l. l: list(A) ==> ALL i: length(l). EX z zs. drop(i,l) = Cons(z,zs)"; |
|
349 |
by (etac list.induct 1); |
|
350 |
by (ALLGOALS (asm_simp_tac (list_ss addsimps bquant_simps))); |
|
351 |
by (rtac conjI 1); |
|
352 |
by (etac drop_length_Cons 1); |
|
353 |
by (rtac ballI 1); |
|
354 |
by (rtac natE 1); |
|
355 |
by (etac ([asm_rl, length_type, Ord_nat] MRS Ord_trans) 1); |
|
356 |
by (assume_tac 1); |
|
357 |
by (asm_simp_tac (list_ss addsimps [drop_0]) 1); |
|
358 |
by (fast_tac ZF_cs 1); |
|
359 |
by (asm_simp_tac (list_ss addsimps [drop_succ_Cons]) 1); |
|
360 |
by (dtac bspec 1); |
|
361 |
by (fast_tac ZF_cs 2); |
|
362 |
by (fast_tac (ZF_cs addEs [succ_in_naturalD,length_type]) 1); |
|
760 | 363 |
qed "drop_length_lemma"; |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
364 |
bind_thm ("drop_length", (drop_length_lemma RS bspec)); |
516 | 365 |
|
366 |
||
367 |
(*** theorems about app ***) |
|
368 |
||
369 |
val [major] = goal List.thy "xs: list(A) ==> xs@Nil=xs"; |
|
370 |
by (rtac (major RS list.induct) 1); |
|
371 |
by (ALLGOALS (asm_simp_tac list_ss)); |
|
760 | 372 |
qed "app_right_Nil"; |
516 | 373 |
|
374 |
val prems = goal List.thy "xs: list(A) ==> (xs@ys)@zs = xs@(ys@zs)"; |
|
375 |
by (list_ind_tac "xs" prems 1); |
|
376 |
by (ALLGOALS (asm_simp_tac list_ss)); |
|
760 | 377 |
qed "app_assoc"; |
516 | 378 |
|
379 |
val prems = goal List.thy |
|
380 |
"ls: list(list(A)) ==> flat(ls@ms) = flat(ls)@flat(ms)"; |
|
381 |
by (list_ind_tac "ls" prems 1); |
|
382 |
by (ALLGOALS (asm_simp_tac (list_ss addsimps [app_assoc]))); |
|
760 | 383 |
qed "flat_app_distrib"; |
516 | 384 |
|
385 |
(*** theorems about rev ***) |
|
386 |
||
387 |
val prems = goal List.thy "l: list(A) ==> rev(map(h,l)) = map(h,rev(l))"; |
|
388 |
by (list_ind_tac "l" prems 1); |
|
389 |
by (ALLGOALS (asm_simp_tac (list_ss addsimps [map_app_distrib]))); |
|
760 | 390 |
qed "rev_map_distrib"; |
516 | 391 |
|
392 |
(*Simplifier needs the premises as assumptions because rewriting will not |
|
393 |
instantiate the variable ?A in the rules' typing conditions; note that |
|
394 |
rev_type does not instantiate ?A. Only the premises do. |
|
395 |
*) |
|
396 |
goal List.thy |
|
397 |
"!!xs. [| xs: list(A); ys: list(A) |] ==> rev(xs@ys) = rev(ys)@rev(xs)"; |
|
398 |
by (etac list.induct 1); |
|
399 |
by (ALLGOALS (asm_simp_tac (list_ss addsimps [app_right_Nil,app_assoc]))); |
|
760 | 400 |
qed "rev_app_distrib"; |
516 | 401 |
|
402 |
val prems = goal List.thy "l: list(A) ==> rev(rev(l))=l"; |
|
403 |
by (list_ind_tac "l" prems 1); |
|
404 |
by (ALLGOALS (asm_simp_tac (list_ss addsimps [rev_app_distrib]))); |
|
760 | 405 |
qed "rev_rev_ident"; |
516 | 406 |
|
407 |
val prems = goal List.thy |
|
408 |
"ls: list(list(A)) ==> rev(flat(ls)) = flat(map(rev,rev(ls)))"; |
|
409 |
by (list_ind_tac "ls" prems 1); |
|
410 |
by (ALLGOALS (asm_simp_tac (list_ss addsimps |
|
411 |
[map_app_distrib, flat_app_distrib, rev_app_distrib, app_right_Nil]))); |
|
760 | 412 |
qed "rev_flat"; |
516 | 413 |
|
414 |
||
415 |
(*** theorems about list_add ***) |
|
416 |
||
417 |
val prems = goal List.thy |
|
418 |
"[| xs: list(nat); ys: list(nat) |] ==> \ |
|
419 |
\ list_add(xs@ys) = list_add(ys) #+ list_add(xs)"; |
|
420 |
by (cut_facts_tac prems 1); |
|
421 |
by (list_ind_tac "xs" prems 1); |
|
422 |
by (ALLGOALS |
|
423 |
(asm_simp_tac (list_ss addsimps [add_0_right, add_assoc RS sym]))); |
|
424 |
by (rtac (add_commute RS subst_context) 1); |
|
425 |
by (REPEAT (ares_tac [refl, list_add_type] 1)); |
|
760 | 426 |
qed "list_add_app"; |
516 | 427 |
|
428 |
val prems = goal List.thy |
|
429 |
"l: list(nat) ==> list_add(rev(l)) = list_add(l)"; |
|
430 |
by (list_ind_tac "l" prems 1); |
|
431 |
by (ALLGOALS |
|
432 |
(asm_simp_tac (list_ss addsimps [list_add_app, add_0_right]))); |
|
760 | 433 |
qed "list_add_rev"; |
516 | 434 |
|
435 |
val prems = goal List.thy |
|
436 |
"ls: list(list(nat)) ==> list_add(flat(ls)) = list_add(map(list_add,ls))"; |
|
437 |
by (list_ind_tac "ls" prems 1); |
|
438 |
by (ALLGOALS (asm_simp_tac (list_ss addsimps [list_add_app]))); |
|
439 |
by (REPEAT (ares_tac [refl, list_add_type, map_type, add_commute] 1)); |
|
760 | 440 |
qed "list_add_flat"; |
516 | 441 |
|
442 |
(** New induction rule **) |
|
443 |
||
444 |
val major::prems = goal List.thy |
|
445 |
"[| l: list(A); \ |
|
446 |
\ P(Nil); \ |
|
447 |
\ !!x y. [| x: A; y: list(A); P(y) |] ==> P(y @ [x]) \ |
|
448 |
\ |] ==> P(l)"; |
|
449 |
by (rtac (major RS rev_rev_ident RS subst) 1); |
|
450 |
by (rtac (major RS rev_type RS list.induct) 1); |
|
451 |
by (ALLGOALS (asm_simp_tac (list_ss addsimps prems))); |
|
760 | 452 |
qed "list_append_induct"; |
516 | 453 |