author | wenzelm |
Sun, 25 Oct 1998 12:33:27 +0100 | |
changeset 5769 | 6a422b22ba02 |
parent 5529 | 4a54acae6a15 |
child 6141 | a6922171b396 |
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 |
|
5068 | 24 |
Goal "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 |
4091 | 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 |
||
5137 | 32 |
Goalw llist.defs "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 |
|
5268 | 46 |
Goal "Ord(i) ==> ALL l: llist(quniv(A)). l Int Vset(i) <= univ(eclose(A))"; |
173 | 47 |
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
|
48 |
by (rtac ballI 1); |
515 | 49 |
by (etac llist.elim 1); |
50 |
by (rewrite_goals_tac ([QInl_def,QInr_def]@llist.con_defs)); |
|
173 | 51 |
(*LNil case*) |
2469 | 52 |
by (Asm_simp_tac 1); |
173 | 53 |
(*LCons case*) |
4091 | 54 |
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
|
55 |
qed "llist_quniv_lemma"; |
0 | 56 |
|
5068 | 57 |
Goal "llist(quniv(A)) <= quniv(A)"; |
173 | 58 |
by (rtac (qunivI RS subsetI) 1); |
59 |
by (rtac Int_Vset_subset 1); |
|
0 | 60 |
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
|
61 |
qed "llist_quniv"; |
0 | 62 |
|
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
63 |
bind_thm ("llist_subset_quniv", |
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
64 |
(llist_mono RS (llist_quniv RSN (2,subset_trans)))); |
0 | 65 |
|
515 | 66 |
|
67 |
(*** Lazy List Equality: lleq ***) |
|
68 |
||
2469 | 69 |
AddSIs [QPair_Int_Vset_subset_UN RS subset_trans, QPair_mono]; |
70 |
AddSEs [Ord_in_Ord, Pair_inject]; |
|
515 | 71 |
|
72 |
(*Lemma for proving finality. Unfold the lazy list; use induction hypothesis*) |
|
5268 | 73 |
Goal "Ord(i) ==> ALL l l'. <l,l'> : lleq(A) --> l Int Vset(i) <= l'"; |
515 | 74 |
by (etac trans_induct 1); |
75 |
by (REPEAT (resolve_tac [allI, impI] 1)); |
|
76 |
by (etac lleq.elim 1); |
|
77 |
by (rewrite_goals_tac (QInr_def::llist.con_defs)); |
|
4152 | 78 |
by Safe_tac; |
515 | 79 |
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
|
80 |
qed "lleq_Int_Vset_subset_lemma"; |
515 | 81 |
|
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
82 |
bind_thm ("lleq_Int_Vset_subset", |
1461 | 83 |
(lleq_Int_Vset_subset_lemma RS spec RS spec RS mp)); |
515 | 84 |
|
85 |
||
86 |
(*lleq(A) is a symmetric relation because qconverse(lleq(A)) is a fixedpoint*) |
|
87 |
val [prem] = goal LList.thy "<l,l'> : lleq(A) ==> <l',l> : lleq(A)"; |
|
88 |
by (rtac (prem RS converseI RS lleq.coinduct) 1); |
|
89 |
by (rtac (lleq.dom_subset RS converse_type) 1); |
|
4152 | 90 |
by Safe_tac; |
515 | 91 |
by (etac lleq.elim 1); |
2469 | 92 |
by (ALLGOALS Fast_tac); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
93 |
qed "lleq_symmetric"; |
515 | 94 |
|
5137 | 95 |
Goal "<l,l'> : lleq(A) ==> l=l'"; |
515 | 96 |
by (rtac equalityI 1); |
97 |
by (REPEAT (ares_tac [lleq_Int_Vset_subset RS Int_Vset_subset] 1 |
|
98 |
ORELSE etac lleq_symmetric 1)); |
|
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
99 |
qed "lleq_implies_equal"; |
515 | 100 |
|
101 |
val [eqprem,lprem] = goal LList.thy |
|
102 |
"[| l=l'; l: llist(A) |] ==> <l,l'> : lleq(A)"; |
|
103 |
by (res_inst_tac [("X", "{<l,l>. l: llist(A)}")] lleq.coinduct 1); |
|
104 |
by (rtac (lprem RS RepFunI RS (eqprem RS subst)) 1); |
|
4152 | 105 |
by Safe_tac; |
515 | 106 |
by (etac llist.elim 1); |
2469 | 107 |
by (ALLGOALS Fast_tac); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
108 |
qed "equal_llist_implies_leq"; |
515 | 109 |
|
110 |
||
111 |
(*** Lazy List Functions ***) |
|
112 |
||
113 |
(*Examples of coinduction for type-checking and to prove llist equations*) |
|
114 |
||
115 |
(*** lconst -- defined directly using lfp, but equivalent to a LList_corec ***) |
|
116 |
||
5068 | 117 |
Goalw llist.con_defs "bnd_mono(univ(a), %l. LCons(a,l))"; |
515 | 118 |
by (rtac bnd_monoI 1); |
119 |
by (REPEAT (ares_tac [subset_refl, QInr_mono, QPair_mono] 2)); |
|
120 |
by (REPEAT (ares_tac [subset_refl, A_subset_univ, |
|
1461 | 121 |
QInr_subset_univ, QPair_subset_univ] 1)); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
122 |
qed "lconst_fun_bnd_mono"; |
515 | 123 |
|
124 |
(* lconst(a) = LCons(a,lconst(a)) *) |
|
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
125 |
bind_thm ("lconst", |
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
126 |
([lconst_def, lconst_fun_bnd_mono] MRS def_lfp_Tarski)); |
515 | 127 |
|
128 |
val lconst_subset = lconst_def RS def_lfp_subset; |
|
129 |
||
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
130 |
bind_thm ("member_subset_Union_eclose", (arg_into_eclose RS Union_upper)); |
515 | 131 |
|
5137 | 132 |
Goal "a : A ==> lconst(a) : quniv(A)"; |
515 | 133 |
by (rtac (lconst_subset RS subset_trans RS qunivI) 1); |
134 |
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
|
135 |
qed "lconst_in_quniv"; |
515 | 136 |
|
5137 | 137 |
Goal "a:A ==> lconst(a): llist(A)"; |
515 | 138 |
by (rtac (singletonI RS llist.coinduct) 1); |
576 | 139 |
by (etac (lconst_in_quniv RS singleton_subsetI) 1); |
4091 | 140 |
by (fast_tac (claset() addSIs [lconst]) 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
141 |
qed "lconst_type"; |
515 | 142 |
|
143 |
(*** flip --- equations merely assumed; certain consequences proved ***) |
|
144 |
||
2469 | 145 |
Addsimps [flip_LNil, flip_LCons, not_type]; |
515 | 146 |
|
147 |
goal QUniv.thy "!!b. b:bool ==> b Int X <= univ(eclose(A))"; |
|
4091 | 148 |
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
|
149 |
qed "bool_Int_subset_univ"; |
515 | 150 |
|
2469 | 151 |
AddSIs [not_type]; |
152 |
AddIs [bool_Int_subset_univ]; |
|
515 | 153 |
|
154 |
(*Reasoning borrowed from lleq.ML; a similar proof works for all |
|
155 |
"productive" functions -- cf Coquand's "Infinite Objects in Type Theory".*) |
|
5268 | 156 |
Goal "Ord(i) ==> ALL l: llist(bool). flip(l) Int Vset(i) <= \ |
515 | 157 |
\ univ(eclose(bool))"; |
158 |
by (etac trans_induct 1); |
|
159 |
by (rtac ballI 1); |
|
160 |
by (etac llist.elim 1); |
|
2469 | 161 |
by (ALLGOALS Asm_simp_tac); |
162 |
by (ALLGOALS |
|
5529 | 163 |
(asm_simp_tac (simpset() addsimps [QInl_def,QInr_def] @ llist.con_defs))); |
515 | 164 |
(*LCons case*) |
4091 | 165 |
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
|
166 |
qed "flip_llist_quniv_lemma"; |
515 | 167 |
|
5137 | 168 |
Goal "l: llist(bool) ==> flip(l) : quniv(bool)"; |
515 | 169 |
by (rtac (flip_llist_quniv_lemma RS bspec RS Int_Vset_subset RS qunivI) 1); |
170 |
by (REPEAT (assume_tac 1)); |
|
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
171 |
qed "flip_in_quniv"; |
515 | 172 |
|
173 |
val [prem] = goal LList.thy "l : llist(bool) ==> flip(l): llist(bool)"; |
|
174 |
by (res_inst_tac [("X", "{flip(l) . l:llist(bool)}")] |
|
175 |
llist.coinduct 1); |
|
176 |
by (rtac (prem RS RepFunI) 1); |
|
4091 | 177 |
by (fast_tac (claset() addSIs [flip_in_quniv]) 1); |
515 | 178 |
by (etac RepFunE 1); |
179 |
by (etac llist.elim 1); |
|
2469 | 180 |
by (ALLGOALS Asm_simp_tac); |
181 |
by (Fast_tac 1); |
|
760 | 182 |
qed "flip_type"; |
515 | 183 |
|
184 |
val [prem] = goal LList.thy |
|
185 |
"l : llist(bool) ==> flip(flip(l)) = l"; |
|
186 |
by (res_inst_tac [("X1", "{<flip(flip(l)),l> . l:llist(bool)}")] |
|
187 |
(lleq.coinduct RS lleq_implies_equal) 1); |
|
188 |
by (rtac (prem RS RepFunI) 1); |
|
4091 | 189 |
by (fast_tac (claset() addSIs [flip_type]) 1); |
515 | 190 |
by (etac RepFunE 1); |
191 |
by (etac llist.elim 1); |
|
2469 | 192 |
by (Asm_simp_tac 1); |
4091 | 193 |
by (asm_simp_tac (simpset() addsimps [flip_type, not_not]) 1); |
194 |
by (fast_tac (claset() addSIs [not_type]) 1); |
|
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
195 |
qed "flip_flip"; |