author | lcp |
Fri, 12 Aug 1994 10:57:55 +0200 | |
changeset 512 | 55755ed9fab9 |
parent 484 | 70b789956bd3 |
child 516 | 1957113f0d7d |
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 |
477 | 11 |
val thy_name = "List" |
279 | 12 |
val rec_specs = [("list", "univ(A)", |
484 | 13 |
[(["Nil"], "i", NoSyn), |
14 |
(["Cons"], "[i,i]=>i", NoSyn)])] |
|
279 | 15 |
val rec_styp = "i=>i" |
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 |
|
22 |
val [NilI, ConsI] = List.intrs; |
|
23 |
||
24 |
(*An elimination rule, for type-checking*) |
|
25 |
val ConsE = List.mk_cases List.con_defs "Cons(a,l) : list(A)"; |
|
26 |
||
27 |
(*Proving freeness results*) |
|
28 |
val Cons_iff = List.mk_free "Cons(a,l)=Cons(a',l') <-> a=a' & l=l'"; |
|
29 |
val Nil_Cons_iff = List.mk_free "~ Nil=Cons(a,l)"; |
|
30 |
||
31 |
(*Perform induction on l, then prove the major premise using prems. *) |
|
32 |
fun list_ind_tac a prems i = |
|
33 |
EVERY [res_inst_tac [("x",a)] List.induct i, |
|
34 |
rename_last_tac a ["1"] (i+2), |
|
35 |
ares_tac prems i]; |
|
36 |
||
435 | 37 |
goal List.thy "list(A) = {0} + (A * list(A))"; |
38 |
by (rtac (List.unfold RS trans) 1); |
|
39 |
bws List.con_defs; |
|
40 |
by (fast_tac (sum_cs addIs ([equalityI] @ datatype_intrs) |
|
41 |
addDs [List.dom_subset RS subsetD] |
|
42 |
addEs [A_into_univ]) 1); |
|
43 |
val list_unfold = result(); |
|
44 |
||
0 | 45 |
(** Lemmas to justify using "list" in other recursive type definitions **) |
46 |
||
47 |
goalw List.thy List.defs "!!A B. A<=B ==> list(A) <= list(B)"; |
|
48 |
by (rtac lfp_mono 1); |
|
49 |
by (REPEAT (rtac List.bnd_mono 1)); |
|
50 |
by (REPEAT (ares_tac (univ_mono::basic_monos) 1)); |
|
51 |
val list_mono = result(); |
|
52 |
||
53 |
(*There is a similar proof by list induction.*) |
|
54 |
goalw List.thy (List.defs@List.con_defs) "list(univ(A)) <= univ(A)"; |
|
55 |
by (rtac lfp_lowerbound 1); |
|
56 |
by (rtac (A_subset_univ RS univ_mono) 2); |
|
57 |
by (fast_tac (ZF_cs addSIs [zero_in_univ, Inl_in_univ, Inr_in_univ, |
|
58 |
Pair_in_univ]) 1); |
|
59 |
val list_univ = result(); |
|
60 |
||
55 | 61 |
val list_subset_univ = standard ([list_mono, list_univ] MRS subset_trans); |
0 | 62 |
|
435 | 63 |
goal List.thy "!!l A B. [| l: list(A); A <= univ(B) |] ==> l: univ(B)"; |
64 |
by (REPEAT (ares_tac [list_subset_univ RS subsetD] 1)); |
|
65 |
val list_into_univ = result(); |
|
66 |
||
0 | 67 |
val major::prems = goal List.thy |
68 |
"[| l: list(A); \ |
|
15
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
69 |
\ c: C(Nil); \ |
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
70 |
\ !!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
|
71 |
\ |] ==> 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
|
72 |
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
|
73 |
by (ALLGOALS (asm_simp_tac (ZF_ss addsimps (List.case_eqns @ prems)))); |
0 | 74 |
val list_case_type = result(); |
75 |
||
76 |
||
77 |
(** For recursion **) |
|
78 |
||
30 | 79 |
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
|
80 |
by (simp_tac rank_ss 1); |
0 | 81 |
val rank_Cons1 = result(); |
82 |
||
30 | 83 |
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
|
84 |
by (simp_tac rank_ss 1); |
0 | 85 |
val rank_Cons2 = result(); |
86 |