| author | lcp |
| Fri, 24 Jun 1994 13:01:53 +0200 | |
| changeset 440 | 1577cbcd0936 |
| parent 435 | ca5356bd315a |
| child 444 | 3ca9d49fd662 |
| permissions | -rw-r--r-- |
| 435 | 1 |
(* Title: ZF/List.ML |
| 0 | 2 |
ID: $Id$ |
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
4 |
Copyright 1993 University of Cambridge |
|
5 |
||
6 |
Datatype definition of Lists |
|
7 |
*) |
|
8 |
||
9 |
structure List = Datatype_Fun |
|
| 279 | 10 |
(val thy = Univ.thy |
11 |
val rec_specs = [("list", "univ(A)",
|
|
12 |
[(["Nil"], "i"), |
|
13 |
(["Cons"], "[i,i]=>i")])] |
|
14 |
val rec_styp = "i=>i" |
|
15 |
val ext = None |
|
16 |
val sintrs = ["Nil : list(A)", |
|
17 |
"[| a: A; l: list(A) |] ==> Cons(a,l) : list(A)"] |
|
18 |
val monos = [] |
|
|
70
8a29f8b4aca1
ZF/ind-syntax/fold_con_tac: deleted, since fold_tac now works
lcp
parents:
55
diff
changeset
|
19 |
val type_intrs = datatype_intrs |
| 84 | 20 |
val type_elims = datatype_elims); |
| 0 | 21 |
|
| 124 | 22 |
store_theory "List" List.thy; |
23 |
||
| 0 | 24 |
val [NilI, ConsI] = List.intrs; |
25 |
||
26 |
(*An elimination rule, for type-checking*) |
|
27 |
val ConsE = List.mk_cases List.con_defs "Cons(a,l) : list(A)"; |
|
28 |
||
29 |
(*Proving freeness results*) |
|
30 |
val Cons_iff = List.mk_free "Cons(a,l)=Cons(a',l') <-> a=a' & l=l'"; |
|
31 |
val Nil_Cons_iff = List.mk_free "~ Nil=Cons(a,l)"; |
|
32 |
||
33 |
(*Perform induction on l, then prove the major premise using prems. *) |
|
34 |
fun list_ind_tac a prems i = |
|
35 |
EVERY [res_inst_tac [("x",a)] List.induct i,
|
|
36 |
rename_last_tac a ["1"] (i+2), |
|
37 |
ares_tac prems i]; |
|
38 |
||
| 435 | 39 |
goal List.thy "list(A) = {0} + (A * list(A))";
|
40 |
by (rtac (List.unfold RS trans) 1); |
|
41 |
bws List.con_defs; |
|
42 |
by (fast_tac (sum_cs addIs ([equalityI] @ datatype_intrs) |
|
43 |
addDs [List.dom_subset RS subsetD] |
|
44 |
addEs [A_into_univ]) 1); |
|
45 |
val list_unfold = result(); |
|
46 |
||
| 0 | 47 |
(** Lemmas to justify using "list" in other recursive type definitions **) |
48 |
||
49 |
goalw List.thy List.defs "!!A B. A<=B ==> list(A) <= list(B)"; |
|
50 |
by (rtac lfp_mono 1); |
|
51 |
by (REPEAT (rtac List.bnd_mono 1)); |
|
52 |
by (REPEAT (ares_tac (univ_mono::basic_monos) 1)); |
|
53 |
val list_mono = result(); |
|
54 |
||
55 |
(*There is a similar proof by list induction.*) |
|
56 |
goalw List.thy (List.defs@List.con_defs) "list(univ(A)) <= univ(A)"; |
|
57 |
by (rtac lfp_lowerbound 1); |
|
58 |
by (rtac (A_subset_univ RS univ_mono) 2); |
|
59 |
by (fast_tac (ZF_cs addSIs [zero_in_univ, Inl_in_univ, Inr_in_univ, |
|
60 |
Pair_in_univ]) 1); |
|
61 |
val list_univ = result(); |
|
62 |
||
| 55 | 63 |
val list_subset_univ = standard ([list_mono, list_univ] MRS subset_trans); |
| 0 | 64 |
|
| 435 | 65 |
goal List.thy "!!l A B. [| l: list(A); A <= univ(B) |] ==> l: univ(B)"; |
66 |
by (REPEAT (ares_tac [list_subset_univ RS subsetD] 1)); |
|
67 |
val list_into_univ = result(); |
|
68 |
||
| 0 | 69 |
val major::prems = goal List.thy |
70 |
"[| l: list(A); \ |
|
|
15
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
71 |
\ c: C(Nil); \ |
|
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
72 |
\ !!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
|
73 |
\ |] ==> list_case(c,h,l) : C(l)"; |
|
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
74 |
by (rtac (major RS List.induct) 1); |
|
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
75 |
by (ALLGOALS (asm_simp_tac (ZF_ss addsimps (List.case_eqns @ prems)))); |
| 0 | 76 |
val list_case_type = result(); |
77 |
||
78 |
||
79 |
(** For recursion **) |
|
80 |
||
| 30 | 81 |
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
|
82 |
by (simp_tac rank_ss 1); |
| 0 | 83 |
val rank_Cons1 = result(); |
84 |
||
| 30 | 85 |
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
|
86 |
by (simp_tac rank_ss 1); |
| 0 | 87 |
val rank_Cons2 = result(); |
88 |