author | clasohm |
Wed, 02 Mar 1994 12:26:55 +0100 | |
changeset 48 | 21291189b51e |
parent 44 | 64eda8afe2b4 |
child 83 | e886a3010f8b |
permissions | -rw-r--r-- |
0 | 1 |
(* Title: HOL/list |
2 |
ID: $Id$ |
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
4 |
Copyright 1993 University of Cambridge |
|
5 |
||
6 |
For list.thy. |
|
7 |
*) |
|
8 |
||
9 |
open List; |
|
10 |
||
11 |
(** the list functional **) |
|
12 |
||
13 |
goalw List.thy [List_Fun_def] "mono(List_Fun(A))"; |
|
14 |
by (REPEAT (ares_tac [monoI, subset_refl, usum_mono, uprod_mono] 1)); |
|
15 |
val List_Fun_mono = result(); |
|
16 |
||
17 |
goalw List.thy [List_Fun_def] |
|
18 |
"!!A B. A<=B ==> List_Fun(A,Z) <= List_Fun(B,Z)"; |
|
19 |
by (REPEAT (ares_tac [subset_refl, usum_mono, uprod_mono] 1)); |
|
20 |
val List_Fun_mono2 = result(); |
|
21 |
||
22 |
(*This justifies using List in other recursive type definitions*) |
|
23 |
goalw List.thy [List_def] "!!A B. A<=B ==> List(A) <= List(B)"; |
|
24 |
by (rtac lfp_mono 1); |
|
25 |
by (etac List_Fun_mono2 1); |
|
26 |
val List_mono = result(); |
|
27 |
||
28 |
(** Type checking rules -- List creates well-founded sets **) |
|
29 |
||
30 |
val prems = goalw List.thy [List_def,List_Fun_def] "List(Sexp) <= Sexp"; |
|
31 |
by (rtac lfp_lowerbound 1); |
|
32 |
by (fast_tac (univ_cs addIs [Sexp_NumbI,Sexp_In0I,Sexp_In1I,Sexp_SconsI]) 1); |
|
33 |
val List_Sexp = result(); |
|
34 |
||
35 |
(* A <= Sexp ==> List(A) <= Sexp *) |
|
36 |
val List_subset_Sexp = standard |
|
37 |
(List_mono RS (List_Sexp RSN (2,subset_trans))); |
|
38 |
||
39 |
(** Induction **) |
|
40 |
||
41 |
(*Induction for the set List(A) *) |
|
42 |
val major::prems = goalw List.thy [NIL_def,CONS_def] |
|
43 |
"[| M: List(A); P(NIL); \ |
|
44 |
\ !!M N. [| M: A; N: List(A); P(N) |] ==> P(CONS(M,N)) |] \ |
|
45 |
\ ==> P(M)"; |
|
46 |
by (rtac (major RS (List_def RS def_induct)) 1); |
|
47 |
by (rtac List_Fun_mono 1); |
|
48 |
by (rewtac List_Fun_def); |
|
49 |
by (fast_tac (set_cs addIs prems addEs [usumE,uprodE]) 1); |
|
50 |
val List_induct = result(); |
|
51 |
||
52 |
(*Induction for the type 'a list *) |
|
53 |
val prems = goalw List.thy [Nil_def,Cons_def] |
|
54 |
"[| P(Nil); \ |
|
48
21291189b51e
changed "." to "$" and Cons to infix "#" to eliminate ambiguity
clasohm
parents:
44
diff
changeset
|
55 |
\ !!x xs. P(xs) ==> P(x # xs) |] ==> P(l)"; |
0 | 56 |
by (rtac (Rep_List_inverse RS subst) 1); (*types force good instantiation*) |
57 |
by (rtac (Rep_List RS List_induct) 1); |
|
58 |
by (REPEAT (ares_tac prems 1 |
|
59 |
ORELSE eresolve_tac [rangeE, ssubst, Abs_List_inverse RS subst] 1)); |
|
60 |
val list_induct = result(); |
|
61 |
||
62 |
(*Perform induction on xs. *) |
|
63 |
fun list_ind_tac a M = |
|
64 |
EVERY [res_inst_tac [("l",a)] list_induct M, |
|
65 |
rename_last_tac a ["1"] (M+1)]; |
|
66 |
||
67 |
(** Introduction rules for List constructors **) |
|
68 |
||
69 |
val List_unfold = rewrite_rule [List_Fun_def] |
|
70 |
(List_Fun_mono RS (List_def RS def_lfp_Tarski)); |
|
71 |
||
72 |
(* c : {Numb(0)} <+> A <*> List(A) ==> c : List(A) *) |
|
73 |
val ListI = List_unfold RS equalityD2 RS subsetD; |
|
74 |
||
75 |
(* NIL is a List -- this also justifies the type definition*) |
|
76 |
goalw List.thy [NIL_def] "NIL: List(A)"; |
|
77 |
by (rtac (singletonI RS usum_In0I RS ListI) 1); |
|
78 |
val NIL_I = result(); |
|
79 |
||
80 |
goalw List.thy [CONS_def] |
|
81 |
"!!a A M. [| a: A; M: List(A) |] ==> CONS(a,M) : List(A)"; |
|
82 |
by (REPEAT (ares_tac [uprodI RS usum_In1I RS ListI] 1)); |
|
83 |
val CONS_I = result(); |
|
84 |
||
85 |
(*** Isomorphisms ***) |
|
86 |
||
87 |
goal List.thy "inj(Rep_List)"; |
|
88 |
by (rtac inj_inverseI 1); |
|
89 |
by (rtac Rep_List_inverse 1); |
|
90 |
val inj_Rep_List = result(); |
|
91 |
||
92 |
goal List.thy "inj_onto(Abs_List,List(range(Leaf)))"; |
|
93 |
by (rtac inj_onto_inverseI 1); |
|
94 |
by (etac Abs_List_inverse 1); |
|
95 |
val inj_onto_Abs_List = result(); |
|
96 |
||
97 |
(** Distinctness of constructors **) |
|
98 |
||
5 | 99 |
goalw List.thy [NIL_def,CONS_def] "CONS(M,N) ~= NIL"; |
0 | 100 |
by (rtac In1_not_In0 1); |
101 |
val CONS_not_NIL = result(); |
|
102 |
val NIL_not_CONS = standard (CONS_not_NIL RS not_sym); |
|
103 |
||
104 |
val CONS_neq_NIL = standard (CONS_not_NIL RS notE); |
|
105 |
val NIL_neq_CONS = sym RS CONS_neq_NIL; |
|
106 |
||
48
21291189b51e
changed "." to "$" and Cons to infix "#" to eliminate ambiguity
clasohm
parents:
44
diff
changeset
|
107 |
goalw List.thy [Nil_def,Cons_def] "x # xs ~= Nil"; |
0 | 108 |
by (rtac (CONS_not_NIL RS (inj_onto_Abs_List RS inj_onto_contraD)) 1); |
109 |
by (REPEAT (resolve_tac [rangeI, NIL_I, CONS_I, Rep_List] 1)); |
|
110 |
val Cons_not_Nil = result(); |
|
111 |
||
112 |
val Nil_not_Cons = standard (Cons_not_Nil RS not_sym); |
|
113 |
||
114 |
val Cons_neq_Nil = standard (Cons_not_Nil RS notE); |
|
115 |
val Nil_neq_Cons = sym RS Cons_neq_Nil; |
|
116 |
||
117 |
(** Injectiveness of CONS and Cons **) |
|
118 |
||
119 |
goalw List.thy [CONS_def] "(CONS(K,M)=CONS(L,N)) = (K=L & M=N)"; |
|
120 |
by (fast_tac (HOL_cs addSEs [Scons_inject, make_elim In1_inject]) 1); |
|
121 |
val CONS_CONS_eq = result(); |
|
122 |
||
123 |
val CONS_inject = standard (CONS_CONS_eq RS iffD1 RS conjE); |
|
124 |
||
125 |
(*For reasoning about abstract list constructors*) |
|
126 |
val List_cs = set_cs addIs [Rep_List, NIL_I, CONS_I] |
|
127 |
addSEs [CONS_neq_NIL,NIL_neq_CONS,CONS_inject] |
|
128 |
addSDs [inj_onto_Abs_List RS inj_ontoD, |
|
129 |
inj_Rep_List RS injD, Leaf_inject]; |
|
130 |
||
48
21291189b51e
changed "." to "$" and Cons to infix "#" to eliminate ambiguity
clasohm
parents:
44
diff
changeset
|
131 |
goalw List.thy [Cons_def] "(x#xs=y#ys) = (x=y & xs=ys)"; |
0 | 132 |
by (fast_tac List_cs 1); |
133 |
val Cons_Cons_eq = result(); |
|
134 |
val Cons_inject = standard (Cons_Cons_eq RS iffD1 RS conjE); |
|
135 |
||
136 |
val [major] = goal List.thy "CONS(M,N): List(A) ==> M: A & N: List(A)"; |
|
137 |
by (rtac (major RS setup_induction) 1); |
|
138 |
by (etac List_induct 1); |
|
139 |
by (ALLGOALS (fast_tac List_cs)); |
|
140 |
val CONS_D = result(); |
|
141 |
||
142 |
val prems = goalw List.thy [CONS_def,In1_def] |
|
143 |
"CONS(M,N): Sexp ==> M: Sexp & N: Sexp"; |
|
144 |
by (cut_facts_tac prems 1); |
|
145 |
by (fast_tac (set_cs addSDs [Scons_D]) 1); |
|
146 |
val Sexp_CONS_D = result(); |
|
147 |
||
148 |
||
149 |
(*Basic ss with constructors and their freeness*) |
|
150 |
val list_free_simps = [Cons_not_Nil, Nil_not_Cons, Cons_Cons_eq, |
|
151 |
CONS_not_NIL, NIL_not_CONS, CONS_CONS_eq, |
|
152 |
NIL_I, CONS_I]; |
|
153 |
val list_free_ss = HOL_ss addsimps list_free_simps; |
|
154 |
||
5 | 155 |
goal List.thy "!!N. N: List(A) ==> !M. N ~= CONS(M,N)"; |
0 | 156 |
by (etac List_induct 1); |
157 |
by (ALLGOALS (asm_simp_tac list_free_ss)); |
|
158 |
val not_CONS_self = result(); |
|
159 |
||
48
21291189b51e
changed "." to "$" and Cons to infix "#" to eliminate ambiguity
clasohm
parents:
44
diff
changeset
|
160 |
goal List.thy "!x. l ~= x#l"; |
0 | 161 |
by (list_ind_tac "l" 1); |
162 |
by (ALLGOALS (asm_simp_tac list_free_ss)); |
|
163 |
val not_Cons_self = result(); |
|
164 |
||
165 |
||
48
21291189b51e
changed "." to "$" and Cons to infix "#" to eliminate ambiguity
clasohm
parents:
44
diff
changeset
|
166 |
goal List.thy "(xs ~= []) = (? y ys. xs = y#ys)"; |
40 | 167 |
by(list_ind_tac "xs" 1); |
168 |
by(simp_tac list_free_ss 1); |
|
169 |
by(asm_simp_tac list_free_ss 1); |
|
170 |
by(REPEAT(resolve_tac [exI,refl,conjI] 1)); |
|
171 |
val neq_Nil_conv = result(); |
|
172 |
||
0 | 173 |
(** Conversion rules for List_case: case analysis operator **) |
174 |
||
175 |
goalw List.thy [List_case_def,NIL_def] "List_case(NIL,c,h) = c"; |
|
176 |
by (rtac Case_In0 1); |
|
177 |
val List_case_NIL = result(); |
|
178 |
||
179 |
goalw List.thy [List_case_def,CONS_def] "List_case(CONS(M,N), c, h) = h(M,N)"; |
|
180 |
by (simp_tac (HOL_ss addsimps [Split,Case_In1]) 1); |
|
181 |
val List_case_CONS = result(); |
|
182 |
||
183 |
(*** List_rec -- by wf recursion on pred_Sexp ***) |
|
184 |
||
185 |
(* The trancl(pred_sexp) is essential because pred_Sexp_CONS_I1,2 would not |
|
186 |
hold if pred_Sexp^+ were changed to pred_Sexp. *) |
|
187 |
||
188 |
val List_rec_unfold = wf_pred_Sexp RS wf_trancl RS (List_rec_def RS def_wfrec); |
|
189 |
||
190 |
(** pred_Sexp lemmas **) |
|
191 |
||
192 |
goalw List.thy [CONS_def,In1_def] |
|
193 |
"!!M. [| M: Sexp; N: Sexp |] ==> <M, CONS(M,N)> : pred_Sexp^+"; |
|
194 |
by (asm_simp_tac pred_Sexp_ss 1); |
|
195 |
val pred_Sexp_CONS_I1 = result(); |
|
196 |
||
197 |
goalw List.thy [CONS_def,In1_def] |
|
198 |
"!!M. [| M: Sexp; N: Sexp |] ==> <N, CONS(M,N)> : pred_Sexp^+"; |
|
199 |
by (asm_simp_tac pred_Sexp_ss 1); |
|
200 |
val pred_Sexp_CONS_I2 = result(); |
|
201 |
||
202 |
val [prem] = goal List.thy |
|
203 |
"<CONS(M1,M2), N> : pred_Sexp^+ ==> \ |
|
204 |
\ <M1,N> : pred_Sexp^+ & <M2,N> : pred_Sexp^+"; |
|
205 |
by (rtac (prem RS (pred_Sexp_subset_Sigma RS trancl_subset_Sigma RS |
|
206 |
subsetD RS SigmaE2)) 1); |
|
207 |
by (etac (Sexp_CONS_D RS conjE) 1); |
|
208 |
by (REPEAT (ares_tac [conjI, pred_Sexp_CONS_I1, pred_Sexp_CONS_I2, |
|
209 |
prem RSN (2, trans_trancl RS transD)] 1)); |
|
210 |
val pred_Sexp_CONS_D = result(); |
|
211 |
||
212 |
(** Conversion rules for List_rec **) |
|
213 |
||
214 |
goal List.thy "List_rec(NIL,c,h) = c"; |
|
215 |
by (rtac (List_rec_unfold RS trans) 1); |
|
216 |
by (rtac List_case_NIL 1); |
|
217 |
val List_rec_NIL = result(); |
|
218 |
||
219 |
goal List.thy "!!M. [| M: Sexp; N: Sexp |] ==> \ |
|
220 |
\ List_rec(CONS(M,N), c, h) = h(M, N, List_rec(N,c,h))"; |
|
221 |
by (rtac (List_rec_unfold RS trans) 1); |
|
222 |
by (rtac (List_case_CONS RS trans) 1); |
|
223 |
by(asm_simp_tac(HOL_ss addsimps [CONS_I, pred_Sexp_CONS_I2, cut_apply])1); |
|
224 |
val List_rec_CONS = result(); |
|
225 |
||
226 |
(*** list_rec -- by List_rec ***) |
|
227 |
||
228 |
val Rep_List_in_Sexp = |
|
229 |
Rep_List RS (range_Leaf_subset_Sexp RS List_subset_Sexp RS subsetD); |
|
230 |
||
231 |
local |
|
232 |
val list_rec_simps = list_free_simps @ |
|
233 |
[List_rec_NIL, List_rec_CONS, |
|
234 |
Abs_List_inverse, Rep_List_inverse, |
|
235 |
Rep_List, rangeI, inj_Leaf, Inv_f_f, |
|
236 |
Sexp_LeafI, Rep_List_in_Sexp] |
|
237 |
in |
|
238 |
val list_rec_Nil = prove_goalw List.thy [list_rec_def, Nil_def] |
|
239 |
"list_rec(Nil,c,h) = c" |
|
240 |
(fn _=> [simp_tac (HOL_ss addsimps list_rec_simps) 1]); |
|
241 |
||
242 |
val list_rec_Cons = prove_goalw List.thy [list_rec_def, Cons_def] |
|
48
21291189b51e
changed "." to "$" and Cons to infix "#" to eliminate ambiguity
clasohm
parents:
44
diff
changeset
|
243 |
"list_rec(a#l, c, h) = h(a, l, list_rec(l,c,h))" |
0 | 244 |
(fn _=> [simp_tac (HOL_ss addsimps list_rec_simps) 1]); |
245 |
end; |
|
246 |
||
247 |
val list_simps = [List_rec_NIL, List_rec_CONS, |
|
248 |
list_rec_Nil, list_rec_Cons]; |
|
249 |
val list_ss = list_free_ss addsimps list_simps; |
|
250 |
||
251 |
||
252 |
(*Type checking. Useful?*) |
|
253 |
val major::A_subset_Sexp::prems = goal List.thy |
|
254 |
"[| M: List(A); \ |
|
255 |
\ A<=Sexp; \ |
|
256 |
\ c: C(NIL); \ |
|
257 |
\ !!x y r. [| x: A; y: List(A); r: C(y) |] ==> h(x,y,r): C(CONS(x,y)) \ |
|
258 |
\ |] ==> List_rec(M,c,h) : C(M :: 'a node set)"; |
|
259 |
val Sexp_ListA_I = A_subset_Sexp RS List_subset_Sexp RS subsetD; |
|
260 |
val Sexp_A_I = A_subset_Sexp RS subsetD; |
|
261 |
by (rtac (major RS List_induct) 1); |
|
262 |
by (ALLGOALS(asm_simp_tac (list_ss addsimps ([Sexp_A_I,Sexp_ListA_I]@prems)))); |
|
263 |
val List_rec_type = result(); |
|
264 |
||
265 |
(** Generalized map functionals **) |
|
266 |
||
267 |
goalw List.thy [Rep_map_def] "Rep_map(f,Nil) = NIL"; |
|
268 |
by (rtac list_rec_Nil 1); |
|
269 |
val Rep_map_Nil = result(); |
|
270 |
||
271 |
goalw List.thy [Rep_map_def] |
|
48
21291189b51e
changed "." to "$" and Cons to infix "#" to eliminate ambiguity
clasohm
parents:
44
diff
changeset
|
272 |
"Rep_map(f, x#xs) = CONS(f(x), Rep_map(f,xs))"; |
0 | 273 |
by (rtac list_rec_Cons 1); |
274 |
val Rep_map_Cons = result(); |
|
275 |
||
276 |
goalw List.thy [Rep_map_def] "!!f. (!!x. f(x): A) ==> Rep_map(f,xs): List(A)"; |
|
277 |
by (rtac list_induct 1); |
|
278 |
by(ALLGOALS(asm_simp_tac list_ss)); |
|
279 |
val Rep_map_type = result(); |
|
280 |
||
281 |
goalw List.thy [Abs_map_def] "Abs_map(g,NIL) = Nil"; |
|
282 |
by (rtac List_rec_NIL 1); |
|
283 |
val Abs_map_NIL = result(); |
|
284 |
||
285 |
val prems = goalw List.thy [Abs_map_def] |
|
286 |
"[| M: Sexp; N: Sexp |] ==> \ |
|
48
21291189b51e
changed "." to "$" and Cons to infix "#" to eliminate ambiguity
clasohm
parents:
44
diff
changeset
|
287 |
\ Abs_map(g, CONS(M,N)) = g(M) # Abs_map(g,N)"; |
0 | 288 |
by (REPEAT (resolve_tac (List_rec_CONS::prems) 1)); |
289 |
val Abs_map_CONS = result(); |
|
290 |
||
34 | 291 |
(*These 2 rules ease the use of primitive recursion. NOTE USE OF == *) |
292 |
val [rew] = goal List.thy |
|
293 |
"[| !!xs. f(xs) == list_rec(xs,c,h) |] ==> f([]) = c"; |
|
294 |
by (rewtac rew); |
|
0 | 295 |
by (rtac list_rec_Nil 1); |
34 | 296 |
val def_list_rec_Nil = result(); |
0 | 297 |
|
34 | 298 |
val [rew] = goal List.thy |
48
21291189b51e
changed "." to "$" and Cons to infix "#" to eliminate ambiguity
clasohm
parents:
44
diff
changeset
|
299 |
"[| !!xs. f(xs) == list_rec(xs,c,h) |] ==> f(x#xs) = h(x,xs,f(xs))"; |
34 | 300 |
by (rewtac rew); |
0 | 301 |
by (rtac list_rec_Cons 1); |
34 | 302 |
val def_list_rec_Cons = result(); |
0 | 303 |
|
34 | 304 |
fun list_recs def = |
305 |
[standard (def RS def_list_rec_Nil), |
|
306 |
standard (def RS def_list_rec_Cons)]; |
|
0 | 307 |
|
34 | 308 |
(*** Unfolding the basic combinators ***) |
0 | 309 |
|
34 | 310 |
val [null_Nil,null_Cons] = list_recs null_def; |
311 |
val [_,hd_Cons] = list_recs hd_def; |
|
312 |
val [_,tl_Cons] = list_recs tl_def; |
|
40 | 313 |
val [ttl_Nil,ttl_Cons] = list_recs ttl_def; |
34 | 314 |
val [append_Nil,append_Cons] = list_recs append_def; |
315 |
val [mem_Nil, mem_Cons] = list_recs mem_def; |
|
316 |
val [map_Nil,map_Cons] = list_recs map_def; |
|
317 |
val [list_case_Nil,list_case_Cons] = list_recs list_case_def; |
|
318 |
val [filter_Nil,filter_Cons] = list_recs filter_def; |
|
319 |
val [list_all_Nil,list_all_Cons] = list_recs list_all_def; |
|
0 | 320 |
|
34 | 321 |
val list_ss = arith_ss addsimps |
322 |
[Cons_not_Nil, Nil_not_Cons, Cons_Cons_eq, |
|
323 |
list_rec_Nil, list_rec_Cons, |
|
40 | 324 |
null_Nil, null_Cons, hd_Cons, tl_Cons, ttl_Nil, ttl_Cons, |
34 | 325 |
mem_Nil, mem_Cons, |
326 |
list_case_Nil, list_case_Cons, |
|
327 |
append_Nil, append_Cons, |
|
328 |
map_Nil, map_Cons, |
|
329 |
list_all_Nil, list_all_Cons, |
|
330 |
filter_Nil, filter_Cons]; |
|
331 |
||
0 | 332 |
|
13 | 333 |
(** @ - append **) |
334 |
||
335 |
goal List.thy "(xs@ys)@zs = xs@(ys@zs)"; |
|
34 | 336 |
by(list_ind_tac "xs" 1); |
337 |
by(ALLGOALS(asm_simp_tac list_ss)); |
|
13 | 338 |
val append_assoc = result(); |
0 | 339 |
|
40 | 340 |
goal List.thy "xs @ [] = xs"; |
341 |
by(list_ind_tac "xs" 1); |
|
342 |
by(ALLGOALS(asm_simp_tac list_ss)); |
|
343 |
val append_Nil2 = result(); |
|
344 |
||
34 | 345 |
(** mem **) |
346 |
||
347 |
goal List.thy "x mem (xs@ys) = (x mem xs | x mem ys)"; |
|
348 |
by(list_ind_tac "xs" 1); |
|
349 |
by(ALLGOALS(asm_simp_tac (list_ss setloop (split_tac [expand_if])))); |
|
350 |
val mem_append = result(); |
|
351 |
||
352 |
goal List.thy "x mem [x:xs.P(x)] = (x mem xs & P(x))"; |
|
353 |
by(list_ind_tac "xs" 1); |
|
354 |
by(ALLGOALS(asm_simp_tac (list_ss setloop (split_tac [expand_if])))); |
|
355 |
val mem_filter = result(); |
|
356 |
||
357 |
(** list_all **) |
|
0 | 358 |
|
34 | 359 |
goal List.thy "(Alls x:xs.True) = True"; |
360 |
by(list_ind_tac "xs" 1); |
|
361 |
by(ALLGOALS(asm_simp_tac list_ss)); |
|
362 |
val list_all_True = result(); |
|
0 | 363 |
|
34 | 364 |
goal List.thy "list_all(p,xs@ys) = (list_all(p,xs) & list_all(p,ys))"; |
365 |
by(list_ind_tac "xs" 1); |
|
366 |
by(ALLGOALS(asm_simp_tac list_ss)); |
|
367 |
val list_all_conj = result(); |
|
368 |
||
369 |
goal List.thy "(Alls x:xs.P(x)) = (!x. x mem xs --> P(x))"; |
|
370 |
by(list_ind_tac "xs" 1); |
|
371 |
by(ALLGOALS(asm_simp_tac (list_ss setloop (split_tac [expand_if])))); |
|
372 |
by(fast_tac HOL_cs 1); |
|
373 |
val list_all_mem_conv = result(); |
|
374 |
||
375 |
||
376 |
(** The functional "map" **) |
|
0 | 377 |
|
378 |
val map_simps = [Abs_map_NIL, Abs_map_CONS, |
|
379 |
Rep_map_Nil, Rep_map_Cons, |
|
380 |
map_Nil, map_Cons]; |
|
381 |
val map_ss = list_free_ss addsimps map_simps; |
|
382 |
||
383 |
val [major,A_subset_Sexp,minor] = goal List.thy |
|
384 |
"[| M: List(A); A<=Sexp; !!z. z: A ==> f(g(z)) = z |] \ |
|
385 |
\ ==> Rep_map(f, Abs_map(g,M)) = M"; |
|
386 |
by (rtac (major RS List_induct) 1); |
|
387 |
by (ALLGOALS (asm_simp_tac(map_ss addsimps [Sexp_A_I,Sexp_ListA_I,minor]))); |
|
388 |
val Abs_map_inverse = result(); |
|
389 |
||
390 |
(*Rep_map_inverse is obtained via Abs_Rep_map and map_ident*) |
|
391 |
||
40 | 392 |
(** list_case **) |
393 |
||
394 |
goal List.thy |
|
395 |
"P(list_case(xs,a,f)) = ((xs=[] --> P(a)) & \ |
|
48
21291189b51e
changed "." to "$" and Cons to infix "#" to eliminate ambiguity
clasohm
parents:
44
diff
changeset
|
396 |
\ (!y ys. xs=y#ys --> P(f(y,ys))))"; |
40 | 397 |
by(list_ind_tac "xs" 1); |
44 | 398 |
by(ALLGOALS(asm_simp_tac list_ss)); |
40 | 399 |
by(fast_tac HOL_cs 1); |
400 |
val expand_list_case = result(); |
|
401 |
||
0 | 402 |
|
403 |
(** Additional mapping lemmas **) |
|
404 |
||
405 |
goal List.thy "map(%x.x, xs) = xs"; |
|
406 |
by (list_ind_tac "xs" 1); |
|
407 |
by (ALLGOALS (asm_simp_tac map_ss)); |
|
408 |
val map_ident = result(); |
|
409 |
||
410 |
goal List.thy "!!f. (!!x. f(x): Sexp) ==> \ |
|
411 |
\ Abs_map(g, Rep_map(f,xs)) = map(%t. g(f(t)), xs)"; |
|
412 |
by (list_ind_tac "xs" 1); |
|
413 |
by(ALLGOALS(asm_simp_tac(map_ss addsimps |
|
414 |
[Rep_map_type,List_Sexp RS subsetD]))); |
|
415 |
val Abs_Rep_map = result(); |
|
20 | 416 |
|
34 | 417 |
val list_ss = list_ss addsimps |
40 | 418 |
[mem_append, mem_filter, append_assoc, append_Nil2, map_ident, |
34 | 419 |
list_all_True, list_all_conj]; |
40 | 420 |