author | paulson |
Fri, 18 Feb 2000 15:35:29 +0100 | |
changeset 8255 | 38f96394c099 |
parent 6141 | a6922171b396 |
child 10216 | e928bdf62014 |
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 |
||
6141 | 9 |
(*These commands cause classical reasoning to regard the subset relation |
10 |
as primitive, not reducing it to membership*) |
|
11 |
||
2469 | 12 |
Delrules [subsetI, subsetCE]; |
13 |
AddSIs [subset_refl, cons_subsetI, subset_consI, |
|
14 |
Union_least, UN_least, Un_least, |
|
15 |
Inter_greatest, Int_greatest, RepFun_subset, |
|
16 |
Un_upper1, Un_upper2, Int_lower1, Int_lower2]; |
|
17 |
||
0 | 18 |
(*An elimination rule, for type-checking*) |
6141 | 19 |
val LConsE = llist.mk_cases "LCons(a,l) : llist(A)"; |
0 | 20 |
|
21 |
(*Proving freeness results*) |
|
515 | 22 |
val LCons_iff = llist.mk_free "LCons(a,l)=LCons(a',l') <-> a=a' & l=l'"; |
23 |
val LNil_LCons_iff = llist.mk_free "~ LNil=LCons(a,l)"; |
|
0 | 24 |
|
5068 | 25 |
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
|
26 |
let open llist; val rew = rewrite_rule con_defs in |
4091 | 27 |
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
|
28 |
end; |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
29 |
qed "llist_unfold"; |
434 | 30 |
|
0 | 31 |
(*** Lemmas to justify using "llist" in other recursive type definitions ***) |
32 |
||
5137 | 33 |
Goalw llist.defs "A<=B ==> llist(A) <= llist(B)"; |
0 | 34 |
by (rtac gfp_mono 1); |
515 | 35 |
by (REPEAT (rtac llist.bnd_mono 1)); |
0 | 36 |
by (REPEAT (ares_tac (quniv_mono::basic_monos) 1)); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
37 |
qed "llist_mono"; |
0 | 38 |
|
39 |
(** Closure of quniv(A) under llist -- why so complex? Its a gfp... **) |
|
40 |
||
2469 | 41 |
AddSIs [QPair_Int_Vset_subset_UN RS subset_trans, |
1461 | 42 |
QPair_subset_univ, |
2469 | 43 |
empty_subsetI, one_in_quniv RS qunivD]; |
44 |
AddSDs [qunivD]; |
|
45 |
AddSEs [Ord_in_Ord]; |
|
0 | 46 |
|
5268 | 47 |
Goal "Ord(i) ==> ALL l: llist(quniv(A)). l Int Vset(i) <= univ(eclose(A))"; |
173 | 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*) |
4091 | 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 |
|
5068 | 58 |
Goal "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*) |
|
5268 | 74 |
Goal "Ord(i) ==> ALL l l'. <l,l'> : lleq(A) --> l Int Vset(i) <= l'"; |
515 | 75 |
by (etac trans_induct 1); |
76 |
by (REPEAT (resolve_tac [allI, impI] 1)); |
|
77 |
by (etac lleq.elim 1); |
|
78 |
by (rewrite_goals_tac (QInr_def::llist.con_defs)); |
|
4152 | 79 |
by Safe_tac; |
515 | 80 |
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
|
81 |
qed "lleq_Int_Vset_subset_lemma"; |
515 | 82 |
|
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
83 |
bind_thm ("lleq_Int_Vset_subset", |
1461 | 84 |
(lleq_Int_Vset_subset_lemma RS spec RS spec RS mp)); |
515 | 85 |
|
86 |
||
87 |
(*lleq(A) is a symmetric relation because qconverse(lleq(A)) is a fixedpoint*) |
|
88 |
val [prem] = goal LList.thy "<l,l'> : lleq(A) ==> <l',l> : lleq(A)"; |
|
89 |
by (rtac (prem RS converseI RS lleq.coinduct) 1); |
|
90 |
by (rtac (lleq.dom_subset RS converse_type) 1); |
|
4152 | 91 |
by Safe_tac; |
515 | 92 |
by (etac lleq.elim 1); |
2469 | 93 |
by (ALLGOALS Fast_tac); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
94 |
qed "lleq_symmetric"; |
515 | 95 |
|
5137 | 96 |
Goal "<l,l'> : lleq(A) ==> l=l'"; |
515 | 97 |
by (rtac equalityI 1); |
98 |
by (REPEAT (ares_tac [lleq_Int_Vset_subset RS Int_Vset_subset] 1 |
|
99 |
ORELSE etac lleq_symmetric 1)); |
|
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
100 |
qed "lleq_implies_equal"; |
515 | 101 |
|
102 |
val [eqprem,lprem] = goal LList.thy |
|
103 |
"[| l=l'; l: llist(A) |] ==> <l,l'> : lleq(A)"; |
|
104 |
by (res_inst_tac [("X", "{<l,l>. l: llist(A)}")] lleq.coinduct 1); |
|
105 |
by (rtac (lprem RS RepFunI RS (eqprem RS subst)) 1); |
|
4152 | 106 |
by Safe_tac; |
515 | 107 |
by (etac llist.elim 1); |
2469 | 108 |
by (ALLGOALS Fast_tac); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
109 |
qed "equal_llist_implies_leq"; |
515 | 110 |
|
111 |
||
112 |
(*** Lazy List Functions ***) |
|
113 |
||
114 |
(*Examples of coinduction for type-checking and to prove llist equations*) |
|
115 |
||
116 |
(*** lconst -- defined directly using lfp, but equivalent to a LList_corec ***) |
|
117 |
||
5068 | 118 |
Goalw llist.con_defs "bnd_mono(univ(a), %l. LCons(a,l))"; |
515 | 119 |
by (rtac bnd_monoI 1); |
120 |
by (REPEAT (ares_tac [subset_refl, QInr_mono, QPair_mono] 2)); |
|
121 |
by (REPEAT (ares_tac [subset_refl, A_subset_univ, |
|
1461 | 122 |
QInr_subset_univ, QPair_subset_univ] 1)); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
123 |
qed "lconst_fun_bnd_mono"; |
515 | 124 |
|
125 |
(* lconst(a) = LCons(a,lconst(a)) *) |
|
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
126 |
bind_thm ("lconst", |
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
127 |
([lconst_def, lconst_fun_bnd_mono] MRS def_lfp_Tarski)); |
515 | 128 |
|
129 |
val lconst_subset = lconst_def RS def_lfp_subset; |
|
130 |
||
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
131 |
bind_thm ("member_subset_Union_eclose", (arg_into_eclose RS Union_upper)); |
515 | 132 |
|
5137 | 133 |
Goal "a : A ==> lconst(a) : quniv(A)"; |
515 | 134 |
by (rtac (lconst_subset RS subset_trans RS qunivI) 1); |
135 |
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
|
136 |
qed "lconst_in_quniv"; |
515 | 137 |
|
5137 | 138 |
Goal "a:A ==> lconst(a): llist(A)"; |
515 | 139 |
by (rtac (singletonI RS llist.coinduct) 1); |
576 | 140 |
by (etac (lconst_in_quniv RS singleton_subsetI) 1); |
4091 | 141 |
by (fast_tac (claset() addSIs [lconst]) 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
142 |
qed "lconst_type"; |
515 | 143 |
|
144 |
(*** flip --- equations merely assumed; certain consequences proved ***) |
|
145 |
||
2469 | 146 |
Addsimps [flip_LNil, flip_LCons, not_type]; |
515 | 147 |
|
148 |
goal QUniv.thy "!!b. b:bool ==> b Int X <= univ(eclose(A))"; |
|
4091 | 149 |
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
|
150 |
qed "bool_Int_subset_univ"; |
515 | 151 |
|
2469 | 152 |
AddSIs [not_type]; |
153 |
AddIs [bool_Int_subset_univ]; |
|
515 | 154 |
|
155 |
(*Reasoning borrowed from lleq.ML; a similar proof works for all |
|
156 |
"productive" functions -- cf Coquand's "Infinite Objects in Type Theory".*) |
|
5268 | 157 |
Goal "Ord(i) ==> ALL l: llist(bool). flip(l) Int Vset(i) <= \ |
515 | 158 |
\ univ(eclose(bool))"; |
159 |
by (etac trans_induct 1); |
|
160 |
by (rtac ballI 1); |
|
161 |
by (etac llist.elim 1); |
|
2469 | 162 |
by (ALLGOALS Asm_simp_tac); |
163 |
by (ALLGOALS |
|
5529 | 164 |
(asm_simp_tac (simpset() addsimps [QInl_def,QInr_def] @ llist.con_defs))); |
515 | 165 |
(*LCons case*) |
4091 | 166 |
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
|
167 |
qed "flip_llist_quniv_lemma"; |
515 | 168 |
|
5137 | 169 |
Goal "l: llist(bool) ==> flip(l) : quniv(bool)"; |
515 | 170 |
by (rtac (flip_llist_quniv_lemma RS bspec RS Int_Vset_subset RS qunivI) 1); |
171 |
by (REPEAT (assume_tac 1)); |
|
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
172 |
qed "flip_in_quniv"; |
515 | 173 |
|
174 |
val [prem] = goal LList.thy "l : llist(bool) ==> flip(l): llist(bool)"; |
|
175 |
by (res_inst_tac [("X", "{flip(l) . l:llist(bool)}")] |
|
176 |
llist.coinduct 1); |
|
177 |
by (rtac (prem RS RepFunI) 1); |
|
4091 | 178 |
by (fast_tac (claset() addSIs [flip_in_quniv]) 1); |
515 | 179 |
by (etac RepFunE 1); |
180 |
by (etac llist.elim 1); |
|
2469 | 181 |
by (ALLGOALS Asm_simp_tac); |
182 |
by (Fast_tac 1); |
|
760 | 183 |
qed "flip_type"; |
515 | 184 |
|
185 |
val [prem] = goal LList.thy |
|
186 |
"l : llist(bool) ==> flip(flip(l)) = l"; |
|
187 |
by (res_inst_tac [("X1", "{<flip(flip(l)),l> . l:llist(bool)}")] |
|
188 |
(lleq.coinduct RS lleq_implies_equal) 1); |
|
189 |
by (rtac (prem RS RepFunI) 1); |
|
4091 | 190 |
by (fast_tac (claset() addSIs [flip_type]) 1); |
515 | 191 |
by (etac RepFunE 1); |
192 |
by (etac llist.elim 1); |
|
2469 | 193 |
by (Asm_simp_tac 1); |
4091 | 194 |
by (asm_simp_tac (simpset() addsimps [flip_type, not_not]) 1); |
195 |
by (fast_tac (claset() addSIs [not_type]) 1); |
|
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
196 |
qed "flip_flip"; |