author | paulson |
Mon, 29 Sep 1997 11:37:02 +0200 | |
changeset 3724 | f33e301a89f5 |
parent 2496 | 40efb87985b5 |
child 4091 | 771b1f6422a8 |
permissions | -rw-r--r-- |
1461 | 1 |
(* Title: ZF/ex/LList.ML |
0 | 2 |
ID: $Id$ |
1461 | 3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
515 | 4 |
Copyright 1994 University of Cambridge |
0 | 5 |
|
173 | 6 |
Codatatype definition of Lazy Lists |
0 | 7 |
*) |
8 |
||
515 | 9 |
open LList; |
0 | 10 |
|
2469 | 11 |
Delrules [subsetI, subsetCE]; |
12 |
AddSIs [subset_refl, cons_subsetI, subset_consI, |
|
13 |
Union_least, UN_least, Un_least, |
|
14 |
Inter_greatest, Int_greatest, RepFun_subset, |
|
15 |
Un_upper1, Un_upper2, Int_lower1, Int_lower2]; |
|
16 |
||
0 | 17 |
(*An elimination rule, for type-checking*) |
515 | 18 |
val LConsE = llist.mk_cases llist.con_defs "LCons(a,l) : llist(A)"; |
0 | 19 |
|
20 |
(*Proving freeness results*) |
|
515 | 21 |
val LCons_iff = llist.mk_free "LCons(a,l)=LCons(a',l') <-> a=a' & l=l'"; |
22 |
val LNil_LCons_iff = llist.mk_free "~ LNil=LCons(a,l)"; |
|
0 | 23 |
|
434 | 24 |
goal LList.thy "llist(A) = {0} <+> (A <*> llist(A))"; |
529
f0d16216e394
ZF/List, ex/Brouwer,Data,LList,Ntree,TF,Term: much simplified proof of _unfold
lcp
parents:
515
diff
changeset
|
25 |
let open llist; val rew = rewrite_rule con_defs in |
2496 | 26 |
by (fast_tac (!claset addSIs (subsetI ::map rew intrs) addEs [rew elim]) 1) |
529
f0d16216e394
ZF/List, ex/Brouwer,Data,LList,Ntree,TF,Term: much simplified proof of _unfold
lcp
parents:
515
diff
changeset
|
27 |
end; |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
28 |
qed "llist_unfold"; |
434 | 29 |
|
0 | 30 |
(*** Lemmas to justify using "llist" in other recursive type definitions ***) |
31 |
||
515 | 32 |
goalw LList.thy llist.defs "!!A B. A<=B ==> llist(A) <= llist(B)"; |
0 | 33 |
by (rtac gfp_mono 1); |
515 | 34 |
by (REPEAT (rtac llist.bnd_mono 1)); |
0 | 35 |
by (REPEAT (ares_tac (quniv_mono::basic_monos) 1)); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
36 |
qed "llist_mono"; |
0 | 37 |
|
38 |
(** Closure of quniv(A) under llist -- why so complex? Its a gfp... **) |
|
39 |
||
2469 | 40 |
AddSIs [QPair_Int_Vset_subset_UN RS subset_trans, |
1461 | 41 |
QPair_subset_univ, |
2469 | 42 |
empty_subsetI, one_in_quniv RS qunivD]; |
43 |
AddSDs [qunivD]; |
|
44 |
AddSEs [Ord_in_Ord]; |
|
0 | 45 |
|
46 |
goal LList.thy |
|
173 | 47 |
"!!i. Ord(i) ==> ALL l: llist(quniv(A)). l Int Vset(i) <= univ(eclose(A))"; |
48 |
by (etac trans_induct 1); |
|
16
0b033d50ca1c
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
7
diff
changeset
|
49 |
by (rtac ballI 1); |
515 | 50 |
by (etac llist.elim 1); |
51 |
by (rewrite_goals_tac ([QInl_def,QInr_def]@llist.con_defs)); |
|
173 | 52 |
(*LNil case*) |
2469 | 53 |
by (Asm_simp_tac 1); |
173 | 54 |
(*LCons case*) |
2469 | 55 |
by (deepen_tac (!claset addIs [Ord_trans, Int_lower1 RS subset_trans]) 2 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
56 |
qed "llist_quniv_lemma"; |
0 | 57 |
|
58 |
goal LList.thy "llist(quniv(A)) <= quniv(A)"; |
|
173 | 59 |
by (rtac (qunivI RS subsetI) 1); |
60 |
by (rtac Int_Vset_subset 1); |
|
0 | 61 |
by (REPEAT (ares_tac [llist_quniv_lemma RS bspec] 1)); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
62 |
qed "llist_quniv"; |
0 | 63 |
|
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
64 |
bind_thm ("llist_subset_quniv", |
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
65 |
(llist_mono RS (llist_quniv RSN (2,subset_trans)))); |
0 | 66 |
|
515 | 67 |
|
68 |
(*** Lazy List Equality: lleq ***) |
|
69 |
||
2469 | 70 |
AddSIs [QPair_Int_Vset_subset_UN RS subset_trans, QPair_mono]; |
71 |
AddSEs [Ord_in_Ord, Pair_inject]; |
|
515 | 72 |
|
73 |
(*Lemma for proving finality. Unfold the lazy list; use induction hypothesis*) |
|
74 |
goal LList.thy |
|
75 |
"!!i. Ord(i) ==> ALL l l'. <l,l'> : lleq(A) --> l Int Vset(i) <= l'"; |
|
76 |
by (etac trans_induct 1); |
|
77 |
by (REPEAT (resolve_tac [allI, impI] 1)); |
|
78 |
by (etac lleq.elim 1); |
|
79 |
by (rewrite_goals_tac (QInr_def::llist.con_defs)); |
|
2469 | 80 |
by (safe_tac (!claset)); |
515 | 81 |
by (fast_tac (subset_cs addSEs [Ord_trans, make_elim bspec]) 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
82 |
qed "lleq_Int_Vset_subset_lemma"; |
515 | 83 |
|
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
84 |
bind_thm ("lleq_Int_Vset_subset", |
1461 | 85 |
(lleq_Int_Vset_subset_lemma RS spec RS spec RS mp)); |
515 | 86 |
|
87 |
||
88 |
(*lleq(A) is a symmetric relation because qconverse(lleq(A)) is a fixedpoint*) |
|
89 |
val [prem] = goal LList.thy "<l,l'> : lleq(A) ==> <l',l> : lleq(A)"; |
|
90 |
by (rtac (prem RS converseI RS lleq.coinduct) 1); |
|
91 |
by (rtac (lleq.dom_subset RS converse_type) 1); |
|
2469 | 92 |
by (safe_tac (!claset)); |
515 | 93 |
by (etac lleq.elim 1); |
2469 | 94 |
by (ALLGOALS Fast_tac); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
95 |
qed "lleq_symmetric"; |
515 | 96 |
|
97 |
goal LList.thy "!!l l'. <l,l'> : lleq(A) ==> l=l'"; |
|
98 |
by (rtac equalityI 1); |
|
99 |
by (REPEAT (ares_tac [lleq_Int_Vset_subset RS Int_Vset_subset] 1 |
|
100 |
ORELSE etac lleq_symmetric 1)); |
|
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
101 |
qed "lleq_implies_equal"; |
515 | 102 |
|
103 |
val [eqprem,lprem] = goal LList.thy |
|
104 |
"[| l=l'; l: llist(A) |] ==> <l,l'> : lleq(A)"; |
|
105 |
by (res_inst_tac [("X", "{<l,l>. l: llist(A)}")] lleq.coinduct 1); |
|
106 |
by (rtac (lprem RS RepFunI RS (eqprem RS subst)) 1); |
|
2469 | 107 |
by (safe_tac (!claset)); |
515 | 108 |
by (etac llist.elim 1); |
2469 | 109 |
by (ALLGOALS Fast_tac); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
110 |
qed "equal_llist_implies_leq"; |
515 | 111 |
|
112 |
||
113 |
(*** Lazy List Functions ***) |
|
114 |
||
115 |
(*Examples of coinduction for type-checking and to prove llist equations*) |
|
116 |
||
117 |
(*** lconst -- defined directly using lfp, but equivalent to a LList_corec ***) |
|
118 |
||
119 |
goalw LList.thy llist.con_defs "bnd_mono(univ(a), %l. LCons(a,l))"; |
|
120 |
by (rtac bnd_monoI 1); |
|
121 |
by (REPEAT (ares_tac [subset_refl, QInr_mono, QPair_mono] 2)); |
|
122 |
by (REPEAT (ares_tac [subset_refl, A_subset_univ, |
|
1461 | 123 |
QInr_subset_univ, QPair_subset_univ] 1)); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
124 |
qed "lconst_fun_bnd_mono"; |
515 | 125 |
|
126 |
(* lconst(a) = LCons(a,lconst(a)) *) |
|
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
127 |
bind_thm ("lconst", |
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
128 |
([lconst_def, lconst_fun_bnd_mono] MRS def_lfp_Tarski)); |
515 | 129 |
|
130 |
val lconst_subset = lconst_def RS def_lfp_subset; |
|
131 |
||
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
132 |
bind_thm ("member_subset_Union_eclose", (arg_into_eclose RS Union_upper)); |
515 | 133 |
|
134 |
goal LList.thy "!!a A. a : A ==> lconst(a) : quniv(A)"; |
|
135 |
by (rtac (lconst_subset RS subset_trans RS qunivI) 1); |
|
136 |
by (etac (arg_into_eclose RS eclose_subset RS univ_mono) 1); |
|
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
137 |
qed "lconst_in_quniv"; |
515 | 138 |
|
139 |
goal LList.thy "!!a A. a:A ==> lconst(a): llist(A)"; |
|
140 |
by (rtac (singletonI RS llist.coinduct) 1); |
|
576 | 141 |
by (etac (lconst_in_quniv RS singleton_subsetI) 1); |
2469 | 142 |
by (fast_tac (!claset addSIs [lconst]) 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
143 |
qed "lconst_type"; |
515 | 144 |
|
145 |
(*** flip --- equations merely assumed; certain consequences proved ***) |
|
146 |
||
2469 | 147 |
Addsimps [flip_LNil, flip_LCons, not_type]; |
515 | 148 |
|
149 |
goal QUniv.thy "!!b. b:bool ==> b Int X <= univ(eclose(A))"; |
|
2469 | 150 |
by (fast_tac (!claset addIs [Int_lower1 RS subset_trans] addSEs [boolE]) 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
151 |
qed "bool_Int_subset_univ"; |
515 | 152 |
|
2469 | 153 |
AddSIs [not_type]; |
154 |
AddIs [bool_Int_subset_univ]; |
|
515 | 155 |
|
156 |
(*Reasoning borrowed from lleq.ML; a similar proof works for all |
|
157 |
"productive" functions -- cf Coquand's "Infinite Objects in Type Theory".*) |
|
158 |
goal LList.thy |
|
159 |
"!!i. Ord(i) ==> ALL l: llist(bool). flip(l) Int Vset(i) <= \ |
|
160 |
\ univ(eclose(bool))"; |
|
161 |
by (etac trans_induct 1); |
|
162 |
by (rtac ballI 1); |
|
163 |
by (etac llist.elim 1); |
|
2469 | 164 |
by (ALLGOALS Asm_simp_tac); |
165 |
by (ALLGOALS |
|
166 |
(asm_simp_tac (!simpset addsimps ([QInl_def,QInr_def]@llist.con_defs)))); |
|
515 | 167 |
(*LCons case*) |
2469 | 168 |
by (deepen_tac (!claset addIs [Ord_trans, Int_lower1 RS subset_trans]) 2 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
169 |
qed "flip_llist_quniv_lemma"; |
515 | 170 |
|
171 |
goal LList.thy "!!l. l: llist(bool) ==> flip(l) : quniv(bool)"; |
|
172 |
by (rtac (flip_llist_quniv_lemma RS bspec RS Int_Vset_subset RS qunivI) 1); |
|
173 |
by (REPEAT (assume_tac 1)); |
|
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
174 |
qed "flip_in_quniv"; |
515 | 175 |
|
176 |
val [prem] = goal LList.thy "l : llist(bool) ==> flip(l): llist(bool)"; |
|
177 |
by (res_inst_tac [("X", "{flip(l) . l:llist(bool)}")] |
|
178 |
llist.coinduct 1); |
|
179 |
by (rtac (prem RS RepFunI) 1); |
|
2469 | 180 |
by (fast_tac (!claset addSIs [flip_in_quniv]) 1); |
515 | 181 |
by (etac RepFunE 1); |
182 |
by (etac llist.elim 1); |
|
2469 | 183 |
by (ALLGOALS Asm_simp_tac); |
184 |
by (Fast_tac 1); |
|
760 | 185 |
qed "flip_type"; |
515 | 186 |
|
187 |
val [prem] = goal LList.thy |
|
188 |
"l : llist(bool) ==> flip(flip(l)) = l"; |
|
189 |
by (res_inst_tac [("X1", "{<flip(flip(l)),l> . l:llist(bool)}")] |
|
190 |
(lleq.coinduct RS lleq_implies_equal) 1); |
|
191 |
by (rtac (prem RS RepFunI) 1); |
|
2469 | 192 |
by (fast_tac (!claset addSIs [flip_type]) 1); |
515 | 193 |
by (etac RepFunE 1); |
194 |
by (etac llist.elim 1); |
|
2469 | 195 |
by (Asm_simp_tac 1); |
196 |
by (asm_simp_tac (!simpset addsimps [flip_type, not_not]) 1); |
|
197 |
by (fast_tac (!claset addSIs [not_type]) 1); |
|
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
198 |
qed "flip_flip"; |