author | convert-repo |
Thu, 23 Jul 2009 14:03:20 +0000 | |
changeset 255 | 435bf30c29a5 |
parent 66 | 14b9286ed036 |
permissions | -rw-r--r-- |
0 | 1 |
(* Title: HOL/llist |
2 |
ID: $Id$ |
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
4 |
Copyright 1993 University of Cambridge |
|
5 |
||
6 |
For llist.thy. |
|
7 |
||
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
8 |
SHOULD LListD_Fun_CONS_I, etc., be equations (for rewriting)? |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
9 |
|
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
10 |
TOO LONG! needs splitting up |
0 | 11 |
*) |
12 |
||
13 |
open LList; |
|
14 |
||
15 |
(** Simplification **) |
|
16 |
||
38 | 17 |
val llist_simps = [sum_case_Inl, sum_case_Inr]; |
26 | 18 |
val llist_ss = univ_ss delsimps [Pair_eq] |
38 | 19 |
addcongs [split_weak_cong, sum_case_weak_cong] |
20 |
setloop (split_tac [expand_split, expand_sum_case]); |
|
0 | 21 |
|
22 |
(** the llist functional **) |
|
23 |
||
24 |
val LList_unfold = rewrite_rule [List_Fun_def] |
|
25 |
(List_Fun_mono RS (LList_def RS def_gfp_Tarski)); |
|
26 |
||
27 |
(*This justifies using LList in other recursive type definitions*) |
|
28 |
goalw LList.thy [LList_def] "!!A B. A<=B ==> LList(A) <= LList(B)"; |
|
29 |
by (rtac gfp_mono 1); |
|
30 |
by (etac List_Fun_mono2 1); |
|
31 |
val LList_mono = result(); |
|
32 |
||
33 |
(*Elimination is case analysis, not induction.*) |
|
34 |
val [major,prem1,prem2] = goalw LList.thy [NIL_def,CONS_def] |
|
35 |
"[| L : LList(A); \ |
|
36 |
\ L=NIL ==> P; \ |
|
37 |
\ !!M N. [| M:A; N: LList(A); L=CONS(M,N) |] ==> P \ |
|
38 |
\ |] ==> P"; |
|
39 |
by (rtac (major RS (LList_unfold RS equalityD1 RS subsetD RS usumE)) 1); |
|
40 |
by (etac uprodE 2); |
|
41 |
by (rtac prem2 2); |
|
42 |
by (rtac prem1 1); |
|
43 |
by (REPEAT (ares_tac [refl] 1 |
|
44 |
ORELSE eresolve_tac [singletonE,ssubst] 1)); |
|
45 |
val LListE = result(); |
|
46 |
||
47 |
||
48 |
(*** Type checking by co-induction, using List_Fun ***) |
|
49 |
||
50 |
val prems = goalw LList.thy [LList_def] |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
51 |
"[| M : X; X <= List_Fun(A, X Un LList(A)) |] ==> M : LList(A)"; |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
52 |
by (REPEAT (resolve_tac (prems@[List_Fun_mono RS coinduct]) 1)); |
0 | 53 |
val LList_coinduct = result(); |
54 |
||
55 |
(** Rules to prove the 2nd premise of LList_coinduct **) |
|
56 |
||
57 |
goalw LList.thy [List_Fun_def,NIL_def] "NIL: List_Fun(A,X)"; |
|
58 |
by (resolve_tac [singletonI RS usum_In0I] 1); |
|
59 |
val List_Fun_NIL_I = result(); |
|
60 |
||
61 |
goalw LList.thy [List_Fun_def,CONS_def] |
|
62 |
"!!M N. [| M: A; N: X |] ==> CONS(M,N) : List_Fun(A,X)"; |
|
63 |
by (REPEAT (ares_tac [uprodI RS usum_In1I] 1)); |
|
64 |
val List_Fun_CONS_I = result(); |
|
65 |
||
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
66 |
(*Utilise the "strong" part, i.e. gfp(f)*) |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
67 |
goalw LList.thy [LList_def] |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
68 |
"!!M N. M: LList(A) ==> M : List_Fun(A, X Un LList(A))"; |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
69 |
by (etac (List_Fun_mono RS gfp_fun_UnI2) 1); |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
70 |
val List_Fun_LList_I = result(); |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
71 |
|
0 | 72 |
(*** LList_corec satisfies the desired recurion equation ***) |
73 |
||
74 |
(*A continuity result?*) |
|
75 |
goalw LList.thy [CONS_def] "CONS(M, UN x.f(x)) = (UN x. CONS(M, f(x)))"; |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
76 |
by (simp_tac (univ_ss addsimps [In1_UN1, Scons_UN1_y]) 1); |
0 | 77 |
val CONS_UN1 = result(); |
78 |
||
79 |
goal Prod.thy "split(p, %x y.UN z.f(x,y,z)) = (UN z. split(p, %x y.f(x,y,z)))"; |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
80 |
by (simp_tac (pair_ss setloop (split_tac [expand_split])) 1); |
0 | 81 |
val split_UN1 = result(); |
38 | 82 |
(* Does not seem to be used |
83 |
goal Sum.thy "sum_case(s,f,%y.UN z.g(y,z)) = (UN z.sum_case(s,f,%y. g(y,z)))"; |
|
84 |
by (simp_tac (sum_ss setloop (split_tac [expand_sum_case])) 1); |
|
85 |
val sum_case2_UN1 = result(); |
|
86 |
*) |
|
0 | 87 |
val prems = goalw LList.thy [CONS_def] |
88 |
"[| M<=M'; N<=N' |] ==> CONS(M,N) <= CONS(M',N')"; |
|
89 |
by (REPEAT (resolve_tac ([In1_mono,Scons_mono]@prems) 1)); |
|
90 |
val CONS_mono = result(); |
|
91 |
||
92 |
val corec_fun_simps = [LList_corec_fun_def RS def_nat_rec_0, |
|
93 |
LList_corec_fun_def RS def_nat_rec_Suc]; |
|
94 |
val corec_fun_ss = llist_ss addsimps corec_fun_simps; |
|
95 |
||
96 |
(** The directions of the equality are proved separately **) |
|
97 |
||
98 |
goalw LList.thy [LList_corec_def] |
|
38 | 99 |
"LList_corec(a,f) <= sum_case(f(a), %u.NIL, \ |
0 | 100 |
\ %v. split(v, %z w. CONS(z, LList_corec(w,f))))"; |
101 |
by (rtac UN1_least 1); |
|
22 | 102 |
by (res_inst_tac [("n","k")] natE 1); |
103 |
by (ALLGOALS (asm_simp_tac corec_fun_ss)); |
|
0 | 104 |
by (REPEAT (resolve_tac [allI, impI, subset_refl RS CONS_mono, UN1_upper] 1)); |
105 |
val LList_corec_subset1 = result(); |
|
106 |
||
107 |
goalw LList.thy [LList_corec_def] |
|
38 | 108 |
"sum_case(f(a), %u.NIL, %v. split(v, %z w. CONS(z, LList_corec(w,f)))) <= \ |
0 | 109 |
\ LList_corec(a,f)"; |
110 |
by (simp_tac (corec_fun_ss addsimps [CONS_UN1]) 1); |
|
111 |
by (safe_tac set_cs); |
|
112 |
by (ALLGOALS (res_inst_tac [("x","Suc(?k)")] UN1_I THEN' |
|
113 |
asm_simp_tac corec_fun_ss)); |
|
114 |
val LList_corec_subset2 = result(); |
|
115 |
||
116 |
(*the recursion equation for LList_corec -- NOT SUITABLE FOR REWRITING!*) |
|
117 |
goal LList.thy |
|
38 | 118 |
"LList_corec(a,f) = sum_case(f(a), %u. NIL, \ |
0 | 119 |
\ %v. split(v, %z w. CONS(z, LList_corec(w,f))))"; |
120 |
by (REPEAT (resolve_tac [equalityI, LList_corec_subset1, |
|
121 |
LList_corec_subset2] 1)); |
|
122 |
val LList_corec = result(); |
|
123 |
||
124 |
(*definitional version of same*) |
|
125 |
val [rew] = goal LList.thy |
|
126 |
"[| !!x. h(x) == LList_corec(x,f) |] ==> \ |
|
38 | 127 |
\ h(a) = sum_case(f(a), %u.NIL, %v. split(v, %z w. CONS(z, h(w))))"; |
0 | 128 |
by (rewtac rew); |
129 |
by (rtac LList_corec 1); |
|
130 |
val def_LList_corec = result(); |
|
131 |
||
132 |
(*A typical use of co-induction to show membership in the gfp. |
|
133 |
Bisimulation is range(%x. LList_corec(x,f)) *) |
|
134 |
goal LList.thy "LList_corec(a,f) : LList({u.True})"; |
|
135 |
by (res_inst_tac [("X", "range(%x.LList_corec(x,?g))")] LList_coinduct 1); |
|
136 |
by (rtac rangeI 1); |
|
137 |
by (safe_tac set_cs); |
|
138 |
by (stac LList_corec 1); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
139 |
by (simp_tac (llist_ss addsimps [List_Fun_NIL_I,List_Fun_CONS_I, |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
140 |
CollectI, range_eqI]) 1); |
0 | 141 |
(* 6.7 vs 3.4 !!! |
142 |
by (ASM_SIMP_TAC (llist_ss addsimps [List_Fun_NIL_I,List_Fun_CONS_I, |
|
143 |
CollectI, rangeI]) 1); |
|
144 |
*) |
|
145 |
val LList_corec_type = result(); |
|
146 |
||
147 |
(*Lemma for the proof of llist_corec*) |
|
148 |
goal LList.thy |
|
38 | 149 |
"LList_corec(a, %z.sum_case(f(z),Inl,%x.split(x,%v w.Inr(<Leaf(v),w>)))) : \ |
150 |
\ LList(range(Leaf))"; |
|
0 | 151 |
by (res_inst_tac [("X", "range(%x.LList_corec(x,?g))")] LList_coinduct 1); |
152 |
by (rtac rangeI 1); |
|
153 |
by (safe_tac set_cs); |
|
154 |
by (stac LList_corec 1); |
|
38 | 155 |
(*nested "sum_case"; requires an explicit split*) |
0 | 156 |
by (res_inst_tac [("s", "f(xa)")] sumE 1); |
44 | 157 |
by (asm_simp_tac (univ_ss addsimps [List_Fun_NIL_I]) 1); |
158 |
by (asm_simp_tac (univ_ss addsimps [List_Fun_CONS_I, range_eqI] |
|
0 | 159 |
setloop (split_tac [expand_split])) 1); |
160 |
(* FIXME: can the selection of the case split be automated? |
|
161 |
by (ASM_SIMP_TAC (llist_ss addsimps [List_Fun_CONS_I, rangeI]) 1);*) |
|
162 |
val LList_corec_type2 = result(); |
|
163 |
||
164 |
(**** LList equality as a gfp; the bisimulation principle ****) |
|
165 |
||
166 |
goalw LList.thy [LListD_Fun_def] "mono(LListD_Fun(r))"; |
|
167 |
by (REPEAT (ares_tac [monoI, subset_refl, dsum_mono, dprod_mono] 1)); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
168 |
val LListD_Fun_mono = result(); |
0 | 169 |
|
170 |
val LListD_unfold = rewrite_rule [LListD_Fun_def] |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
171 |
(LListD_Fun_mono RS (LListD_def RS def_gfp_Tarski)); |
0 | 172 |
|
173 |
goal LList.thy "!M N. <M,N> : LListD(diag(A)) --> ntrunc(k,M) = ntrunc(k,N)"; |
|
174 |
by (res_inst_tac [("n", "k")] less_induct 1); |
|
175 |
by (safe_tac set_cs); |
|
176 |
by (etac (LListD_unfold RS equalityD1 RS subsetD RS dsumE) 1); |
|
177 |
by (safe_tac (set_cs addSEs [Pair_inject, dprodE, diagE])); |
|
178 |
by (res_inst_tac [("n", "n")] natE 1); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
179 |
by (asm_simp_tac (univ_ss addsimps [ntrunc_0]) 1); |
0 | 180 |
by (res_inst_tac [("n", "xb")] natE 1); |
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
181 |
by (asm_simp_tac (univ_ss addsimps [ntrunc_one_In1]) 1); |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
182 |
by (asm_simp_tac (univ_ss addsimps [ntrunc_In1, ntrunc_Scons]) 1); |
0 | 183 |
val LListD_implies_ntrunc_equality = result(); |
184 |
||
185 |
goalw LList.thy [LList_def,List_Fun_def] "fst``LListD(diag(A)) <= LList(A)"; |
|
186 |
by (rtac gfp_upperbound 1); |
|
187 |
by (res_inst_tac [("P", "%x. fst``x <= ?B")] (LListD_unfold RS ssubst) 1); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
188 |
by (simp_tac fst_image_ss 1); |
0 | 189 |
val fst_image_LListD = result(); |
190 |
||
191 |
(*This inclusion justifies the use of coinduction to show M=N*) |
|
192 |
goal LList.thy "LListD(diag(A)) <= diag(LList(A))"; |
|
193 |
by (rtac subsetI 1); |
|
194 |
by (res_inst_tac [("p","x")] PairE 1); |
|
195 |
by (safe_tac HOL_cs); |
|
196 |
by (res_inst_tac [("s","xa")] subst 1); |
|
197 |
by (rtac (LListD_implies_ntrunc_equality RS spec RS spec RS mp RS |
|
198 |
ntrunc_equality) 1); |
|
199 |
by (assume_tac 1); |
|
200 |
by (rtac diagI 1); |
|
201 |
by (etac (fst_imageI RS (fst_image_LListD RS subsetD)) 1); |
|
202 |
val LListD_subset_diag = result(); |
|
203 |
||
204 |
(*This converse inclusion helps to strengthen LList_equalityI*) |
|
205 |
goalw LList.thy [LListD_def] "diag(LList(A)) <= LListD(diag(A))"; |
|
206 |
by (rtac gfp_upperbound 1); |
|
207 |
by (rtac subsetI 1); |
|
208 |
by (etac diagE 1); |
|
209 |
by (etac ssubst 1); |
|
210 |
by (etac (LList_unfold RS equalityD1 RS subsetD RS usumE) 1); |
|
211 |
by (rewtac LListD_Fun_def); |
|
212 |
by (ALLGOALS (fast_tac (set_cs addIs [diagI,dsum_In0I,dsum_In1I,dprodI] |
|
213 |
addSEs [uprodE]))); |
|
214 |
val diag_subset_LListD = result(); |
|
215 |
||
216 |
goal LList.thy "LListD(diag(A)) = diag(LList(A))"; |
|
217 |
by (REPEAT (resolve_tac [equalityI, LListD_subset_diag, |
|
218 |
diag_subset_LListD] 1)); |
|
219 |
val LListD_eq_diag = result(); |
|
220 |
||
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
221 |
(** To show two LLists are equal, exhibit a bisimulation! |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
222 |
[also admits true equality] |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
223 |
Replace "A" by some particular set, like {x.True}??? *) |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
224 |
goal LList.thy |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
225 |
"!!r. [| <M,N> : r; r <= LListD_Fun(diag(A), r Un diag(LList(A))) \ |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
226 |
\ |] ==> M=N"; |
0 | 227 |
by (rtac (rewrite_rule [LListD_def] |
228 |
(LListD_subset_diag RS subsetD RS diagE)) 1); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
229 |
by (etac (LListD_Fun_mono RS coinduct) 1); |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
230 |
by (etac (rewrite_rule [LListD_def] LListD_eq_diag RS ssubst) 1); |
0 | 231 |
by (safe_tac (set_cs addSEs [Pair_inject])); |
232 |
val LList_equalityI = result(); |
|
233 |
||
234 |
(** Rules to prove the 2nd premise of LList_equalityI **) |
|
235 |
||
236 |
goalw LList.thy [LListD_Fun_def,NIL_def] "<NIL,NIL> : LListD_Fun(r,s)"; |
|
237 |
by (rtac (singletonI RS diagI RS dsum_In0I) 1); |
|
238 |
val LListD_Fun_NIL_I = result(); |
|
239 |
||
240 |
val prems = goalw LList.thy [LListD_Fun_def,CONS_def] |
|
241 |
"[| x:A; <M,N>:s |] ==> <CONS(x,M), CONS(x,N)> : LListD_Fun(diag(A),s)"; |
|
242 |
by (rtac (dprodI RS dsum_In1I) 1); |
|
243 |
by (REPEAT (resolve_tac (diagI::prems) 1)); |
|
244 |
val LListD_Fun_CONS_I = result(); |
|
245 |
||
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
246 |
(*Utilise the "strong" part, i.e. gfp(f)*) |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
247 |
goal LList.thy |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
248 |
"!!M N. M: LList(A) ==> <M,M> : LListD_Fun(diag(A), X Un diag(LList(A)))"; |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
249 |
br (rewrite_rule [LListD_def] LListD_eq_diag RS subst) 1; |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
250 |
br (LListD_Fun_mono RS gfp_fun_UnI2) 1; |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
251 |
br (rewrite_rule [LListD_def] LListD_eq_diag RS ssubst) 1; |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
252 |
be diagI 1; |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
253 |
val LListD_Fun_diag_I = result(); |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
254 |
|
0 | 255 |
|
256 |
(*** Finality of LList(A): Uniqueness of functions defined by corecursion ***) |
|
257 |
||
258 |
(*abstract proof using a bisimulation*) |
|
259 |
val [prem1,prem2] = goal LList.thy |
|
38 | 260 |
"[| !!x. h1(x) = sum_case(f(x), %u.NIL, %v. split(v, %z w. CONS(z,h1(w)))); \ |
261 |
\ !!x. h2(x) = sum_case(f(x), %u.NIL, %v. split(v, %z w. CONS(z,h2(w)))) |]\ |
|
0 | 262 |
\ ==> h1=h2"; |
263 |
by (rtac ext 1); |
|
264 |
(*next step avoids an unknown (and flexflex pair) in simplification*) |
|
265 |
by (res_inst_tac [("A", "{u.True}"), |
|
266 |
("r", "range(%u. <h1(u),h2(u)>)")] LList_equalityI 1); |
|
267 |
by (rtac rangeI 1); |
|
268 |
by (safe_tac set_cs); |
|
269 |
by (stac prem1 1); |
|
270 |
by (stac prem2 1); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
271 |
by (simp_tac (llist_ss addsimps [LListD_Fun_NIL_I, range_eqI, |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
272 |
CollectI RS LListD_Fun_CONS_I]) 1); |
0 | 273 |
(* 9.5 vs 9.2/4.1/4.3 |
274 |
by (ASM_SIMP_TAC (llist_ss addsimps [LListD_Fun_NIL_I, rangeI, |
|
275 |
CollectI RS LListD_Fun_CONS_I]) 1);*) |
|
276 |
val LList_corec_unique = result(); |
|
277 |
||
278 |
val [prem] = goal LList.thy |
|
38 | 279 |
"[| !!x. h(x) = sum_case(f(x), %u.NIL, %v. split(v, %z w. CONS(z,h(w)))) |] \ |
0 | 280 |
\ ==> h = (%x.LList_corec(x,f))"; |
281 |
by (rtac (LList_corec RS (prem RS LList_corec_unique)) 1); |
|
282 |
val equals_LList_corec = result(); |
|
283 |
||
284 |
||
285 |
(** Obsolete LList_corec_unique proof: complete induction, not coinduction **) |
|
286 |
||
287 |
goalw LList.thy [CONS_def] "ntrunc(Suc(0), CONS(M,N)) = {}"; |
|
288 |
by (rtac ntrunc_one_In1 1); |
|
289 |
val ntrunc_one_CONS = result(); |
|
290 |
||
291 |
goalw LList.thy [CONS_def] |
|
292 |
"ntrunc(Suc(Suc(k)), CONS(M,N)) = CONS (ntrunc(k,M), ntrunc(k,N))"; |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
293 |
by (simp_tac (HOL_ss addsimps [ntrunc_Scons,ntrunc_In1]) 1); |
0 | 294 |
val ntrunc_CONS = result(); |
295 |
||
296 |
val [prem1,prem2] = goal LList.thy |
|
38 | 297 |
"[| !!x. h1(x) = sum_case(f(x), %u.NIL, %v. split(v, %z w. CONS(z,h1(w)))); \ |
298 |
\ !!x. h2(x) = sum_case(f(x), %u.NIL, %v. split(v, %z w. CONS(z,h2(w)))) |]\ |
|
0 | 299 |
\ ==> h1=h2"; |
300 |
by (rtac (ntrunc_equality RS ext) 1); |
|
301 |
by (res_inst_tac [("x", "x")] spec 1); |
|
302 |
by (res_inst_tac [("n", "k")] less_induct 1); |
|
303 |
by (rtac allI 1); |
|
304 |
by (stac prem1 1); |
|
305 |
by (stac prem2 1); |
|
38 | 306 |
by (simp_tac (sum_ss setloop (split_tac [expand_split,expand_sum_case])) 1); |
0 | 307 |
by (strip_tac 1); |
308 |
by (res_inst_tac [("n", "n")] natE 1); |
|
309 |
by (res_inst_tac [("n", "xc")] natE 2); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
310 |
by (ALLGOALS(asm_simp_tac(nat_ss addsimps |
0 | 311 |
[ntrunc_0,ntrunc_one_CONS,ntrunc_CONS]))); |
312 |
val LList_corec_unique = result(); |
|
313 |
||
314 |
||
315 |
(*** Lconst -- defined directly using lfp, but equivalent to a LList_corec ***) |
|
316 |
||
317 |
goal LList.thy "mono(CONS(M))"; |
|
318 |
by (REPEAT (ares_tac [monoI, subset_refl, CONS_mono] 1)); |
|
319 |
val Lconst_fun_mono = result(); |
|
320 |
||
321 |
(* Lconst(M) = CONS(M,Lconst(M)) *) |
|
322 |
val Lconst = standard (Lconst_fun_mono RS (Lconst_def RS def_lfp_Tarski)); |
|
323 |
||
324 |
(*A typical use of co-induction to show membership in the gfp. |
|
325 |
The containing set is simply the singleton {Lconst(M)}. *) |
|
326 |
goal LList.thy "!!M A. M:A ==> Lconst(M): LList(A)"; |
|
327 |
by (rtac (singletonI RS LList_coinduct) 1); |
|
328 |
by (safe_tac set_cs); |
|
329 |
by (res_inst_tac [("P", "%u. u: ?A")] (Lconst RS ssubst) 1); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
330 |
by (REPEAT (ares_tac [List_Fun_CONS_I, singletonI, UnI1] 1)); |
0 | 331 |
val Lconst_type = result(); |
332 |
||
333 |
goal LList.thy "Lconst(M) = LList_corec(M, %x.Inr(<x,x>))"; |
|
334 |
by (rtac (equals_LList_corec RS fun_cong) 1); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
335 |
by (simp_tac sum_ss 1); |
0 | 336 |
by (rtac Lconst 1); |
337 |
val Lconst_eq_LList_corec = result(); |
|
338 |
||
339 |
(*Thus we could have used gfp in the definition of Lconst*) |
|
340 |
goal LList.thy "gfp(%N. CONS(M, N)) = LList_corec(M, %x.Inr(<x,x>))"; |
|
341 |
by (rtac (equals_LList_corec RS fun_cong) 1); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
342 |
by (simp_tac sum_ss 1); |
0 | 343 |
by (rtac (Lconst_fun_mono RS gfp_Tarski) 1); |
344 |
val gfp_Lconst_eq_LList_corec = result(); |
|
345 |
||
346 |
||
347 |
(** Introduction rules for LList constructors **) |
|
348 |
||
349 |
(* c : {Numb(0)} <+> A <*> LList(A) ==> c : LList(A) *) |
|
350 |
val LListI = LList_unfold RS equalityD2 RS subsetD; |
|
351 |
||
352 |
(*This justifies the type definition: LList(A) is nonempty.*) |
|
353 |
goalw LList.thy [NIL_def] "NIL: LList(A)"; |
|
354 |
by (rtac (singletonI RS usum_In0I RS LListI) 1); |
|
355 |
val NIL_LListI = result(); |
|
356 |
||
357 |
val prems = goalw LList.thy [CONS_def] |
|
358 |
"[| M: A; N: LList(A) |] ==> CONS(M,N) : LList(A)"; |
|
359 |
by (rtac (uprodI RS usum_In1I RS LListI) 1); |
|
360 |
by (REPEAT (resolve_tac prems 1)); |
|
361 |
val CONS_LListI = result(); |
|
362 |
||
363 |
(*** Isomorphisms ***) |
|
364 |
||
365 |
goal LList.thy "inj(Rep_LList)"; |
|
366 |
by (rtac inj_inverseI 1); |
|
367 |
by (rtac Rep_LList_inverse 1); |
|
368 |
val inj_Rep_LList = result(); |
|
369 |
||
370 |
goal LList.thy "inj_onto(Abs_LList,LList(range(Leaf)))"; |
|
371 |
by (rtac inj_onto_inverseI 1); |
|
372 |
by (etac Abs_LList_inverse 1); |
|
373 |
val inj_onto_Abs_LList = result(); |
|
374 |
||
375 |
(** Distinctness of constructors **) |
|
376 |
||
377 |
goalw LList.thy [LNil_def,LCons_def] "~ LCons(x,xs) = LNil"; |
|
378 |
by (rtac (CONS_not_NIL RS (inj_onto_Abs_LList RS inj_onto_contraD)) 1); |
|
379 |
by (REPEAT (resolve_tac [rangeI, NIL_LListI, CONS_LListI, Rep_LList] 1)); |
|
380 |
val LCons_not_LNil = result(); |
|
381 |
||
382 |
val LNil_not_LCons = standard (LCons_not_LNil RS not_sym); |
|
383 |
||
384 |
val LCons_neq_LNil = standard (LCons_not_LNil RS notE); |
|
385 |
val LNil_neq_LCons = sym RS LCons_neq_LNil; |
|
386 |
||
387 |
(** llist constructors **) |
|
388 |
||
389 |
goalw LList.thy [LNil_def] |
|
390 |
"Rep_LList(LNil) = NIL"; |
|
391 |
by (rtac (NIL_LListI RS Abs_LList_inverse) 1); |
|
392 |
val Rep_LList_LNil = result(); |
|
393 |
||
394 |
goalw LList.thy [LCons_def] |
|
395 |
"Rep_LList(LCons(x,l)) = CONS(Leaf(x),Rep_LList(l))"; |
|
396 |
by (REPEAT (resolve_tac [CONS_LListI RS Abs_LList_inverse, |
|
397 |
rangeI, Rep_LList] 1)); |
|
398 |
val Rep_LList_LCons = result(); |
|
399 |
||
400 |
(** Injectiveness of CONS and LCons **) |
|
401 |
||
402 |
goalw LList.thy [CONS_def] "(CONS(M,N)=CONS(M',N')) = (M=M' & N=N')"; |
|
403 |
by (fast_tac (HOL_cs addSEs [Scons_inject, make_elim In1_inject]) 1); |
|
404 |
val CONS_CONS_eq = result(); |
|
405 |
||
406 |
val CONS_inject = standard (CONS_CONS_eq RS iffD1 RS conjE); |
|
407 |
||
408 |
||
409 |
(*For reasoning about abstract llist constructors*) |
|
410 |
val LList_cs = set_cs addIs [Rep_LList, NIL_LListI, CONS_LListI] |
|
411 |
addSEs [CONS_neq_NIL,NIL_neq_CONS,CONS_inject] |
|
412 |
addSDs [inj_onto_Abs_LList RS inj_ontoD, |
|
413 |
inj_Rep_LList RS injD, Leaf_inject]; |
|
414 |
||
415 |
goalw LList.thy [LCons_def] "(LCons(x,xs)=LCons(y,ys)) = (x=y & xs=ys)"; |
|
416 |
by (fast_tac LList_cs 1); |
|
417 |
val LCons_LCons_eq = result(); |
|
418 |
val LCons_inject = standard (LCons_LCons_eq RS iffD1 RS conjE); |
|
419 |
||
420 |
val [major] = goal LList.thy "CONS(M,N): LList(A) ==> M: A & N: LList(A)"; |
|
421 |
by (rtac (major RS LListE) 1); |
|
422 |
by (etac CONS_neq_NIL 1); |
|
423 |
by (fast_tac LList_cs 1); |
|
424 |
val CONS_D = result(); |
|
425 |
||
426 |
||
427 |
(****** Reasoning about LList(A) ******) |
|
428 |
||
429 |
val List_case_simps = [List_case_NIL, List_case_CONS]; |
|
430 |
val List_case_ss = llist_ss addsimps List_case_simps; |
|
431 |
||
432 |
(*A special case of list_equality for functions over lazy lists*) |
|
433 |
val [MList,gMList,NILcase,CONScase] = goal LList.thy |
|
434 |
"[| M: LList(A); g(NIL): LList(A); \ |
|
435 |
\ f(NIL)=g(NIL); \ |
|
436 |
\ !!x l. [| x:A; l: LList(A) |] ==> \ |
|
437 |
\ <f(CONS(x,l)),g(CONS(x,l))> : \ |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
438 |
\ LListD_Fun(diag(A), (%u.<f(u),g(u)>)``LList(A) Un \ |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
439 |
\ diag(LList(A))) \ |
0 | 440 |
\ |] ==> f(M) = g(M)"; |
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
441 |
by (rtac LList_equalityI 1); |
0 | 442 |
br (MList RS imageI) 1; |
443 |
by (rtac subsetI 1); |
|
444 |
by (etac imageE 1); |
|
445 |
by (etac ssubst 1); |
|
446 |
by (etac LListE 1); |
|
447 |
by (etac ssubst 1); |
|
448 |
by (stac NILcase 1); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
449 |
br (gMList RS LListD_Fun_diag_I) 1; |
0 | 450 |
by (etac ssubst 1); |
451 |
by (REPEAT (ares_tac [CONScase] 1)); |
|
452 |
val LList_fun_equalityI = result(); |
|
453 |
||
454 |
||
455 |
(*** The functional "Lmap" ***) |
|
456 |
||
457 |
goal LList.thy "Lmap(f,NIL) = NIL"; |
|
458 |
by (rtac (Lmap_def RS def_LList_corec RS trans) 1); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
459 |
by (simp_tac List_case_ss 1); |
0 | 460 |
val Lmap_NIL = result(); |
461 |
||
462 |
goal LList.thy "Lmap(f, CONS(M,N)) = CONS(f(M), Lmap(f,N))"; |
|
463 |
by (rtac (Lmap_def RS def_LList_corec RS trans) 1); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
464 |
by (simp_tac List_case_ss 1); |
0 | 465 |
val Lmap_CONS = result(); |
466 |
||
467 |
(*Another type-checking proof by coinduction*) |
|
468 |
val [major,minor] = goal LList.thy |
|
469 |
"[| M: LList(A); !!x. x:A ==> f(x):B |] ==> Lmap(f,M): LList(B)"; |
|
470 |
by (rtac (major RS imageI RS LList_coinduct) 1); |
|
471 |
by (safe_tac set_cs); |
|
472 |
by (etac LListE 1); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
473 |
by (ALLGOALS (asm_simp_tac (HOL_ss addsimps [Lmap_NIL,Lmap_CONS]))); |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
474 |
by (REPEAT (ares_tac [List_Fun_NIL_I, List_Fun_CONS_I, |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
475 |
minor, imageI, UnI1] 1)); |
0 | 476 |
val Lmap_type = result(); |
477 |
||
478 |
(*This type checking rule synthesises a sufficiently large set for f*) |
|
479 |
val [major] = goal LList.thy "M: LList(A) ==> Lmap(f,M): LList(f``A)"; |
|
480 |
by (rtac (major RS Lmap_type) 1); |
|
481 |
by (etac imageI 1); |
|
482 |
val Lmap_type2 = result(); |
|
483 |
||
484 |
(** Two easy results about Lmap **) |
|
485 |
||
66 | 486 |
val [prem] = goalw LList.thy [o_def] |
0 | 487 |
"M: LList(A) ==> Lmap(f o g, M) = Lmap(f, Lmap(g, M))"; |
488 |
by (rtac (prem RS imageI RS LList_equalityI) 1); |
|
489 |
by (safe_tac set_cs); |
|
490 |
by (etac LListE 1); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
491 |
by (ALLGOALS (asm_simp_tac (HOL_ss addsimps [Lmap_NIL,Lmap_CONS]))); |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
492 |
by (REPEAT (ares_tac [LListD_Fun_NIL_I, imageI, UnI1, |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
493 |
rangeI RS LListD_Fun_CONS_I] 1)); |
0 | 494 |
val Lmap_compose = result(); |
495 |
||
496 |
val [prem] = goal LList.thy "M: LList(A) ==> Lmap(%x.x, M) = M"; |
|
497 |
by (rtac (prem RS imageI RS LList_equalityI) 1); |
|
498 |
by (safe_tac set_cs); |
|
499 |
by (etac LListE 1); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
500 |
by (ALLGOALS (asm_simp_tac (HOL_ss addsimps [Lmap_NIL,Lmap_CONS]))); |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
501 |
by (REPEAT (ares_tac [LListD_Fun_NIL_I, imageI RS UnI1, |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
502 |
rangeI RS LListD_Fun_CONS_I] 1)); |
0 | 503 |
val Lmap_ident = result(); |
504 |
||
505 |
||
506 |
(*** Lappend -- its two arguments cause some complications! ***) |
|
507 |
||
508 |
goalw LList.thy [Lappend_def] "Lappend(NIL,NIL) = NIL"; |
|
509 |
by (rtac (LList_corec RS trans) 1); |
|
510 |
(* takes 2.4(3.4 w NORM) vs 0.9 w/o NORM terms *) |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
511 |
by (simp_tac List_case_ss 1); |
0 | 512 |
(*by (SIMP_TAC List_case_ss 1);*) |
513 |
val Lappend_NIL_NIL = result(); |
|
514 |
||
515 |
goalw LList.thy [Lappend_def] |
|
516 |
"Lappend(NIL,CONS(N,N')) = CONS(N, Lappend(NIL,N'))"; |
|
517 |
by (rtac (LList_corec RS trans) 1); |
|
518 |
(* takes 5(7 w NORM) vs 2.1 w/o NORM terms *) |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
519 |
by (simp_tac List_case_ss 1); |
0 | 520 |
(*by (SIMP_TAC List_case_ss 1);*) |
521 |
val Lappend_NIL_CONS = result(); |
|
522 |
||
523 |
goalw LList.thy [Lappend_def] |
|
524 |
"Lappend(CONS(M,M'), N) = CONS(M, Lappend(M',N))"; |
|
525 |
by (rtac (LList_corec RS trans) 1); |
|
526 |
(* takes 4.9(6.7) vs 2.2 w/o NORM terms *) |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
527 |
by (simp_tac List_case_ss 1); |
0 | 528 |
(*by (SIMP_TAC List_case_ss 1);*) |
529 |
val Lappend_CONS = result(); |
|
530 |
||
531 |
val Lappend_ss = List_case_ss addsimps |
|
532 |
[NIL_LListI, Lappend_NIL_NIL, Lappend_NIL_CONS, |
|
533 |
Lappend_CONS, image_eqI, LListD_Fun_CONS_I]; |
|
534 |
||
535 |
goal LList.thy "!!M. M: LList(A) ==> Lappend(NIL,M) = M"; |
|
536 |
by (etac LList_fun_equalityI 1); |
|
537 |
by (ALLGOALS (asm_simp_tac Lappend_ss)); |
|
538 |
val Lappend_NIL = result(); |
|
539 |
||
540 |
goal LList.thy "!!M. M: LList(A) ==> Lappend(M,NIL) = M"; |
|
541 |
by (etac LList_fun_equalityI 1); |
|
542 |
by (ALLGOALS (asm_simp_tac Lappend_ss)); |
|
543 |
val Lappend_NIL2 = result(); |
|
544 |
||
545 |
(** Alternative type-checking proofs for Lappend **) |
|
546 |
||
547 |
(*weak co-induction: bisimulation and case analysis on both variables*) |
|
548 |
goal LList.thy |
|
549 |
"!!M N. [| M: LList(A); N: LList(A) |] ==> Lappend(M,N): LList(A)"; |
|
550 |
by (res_inst_tac |
|
551 |
[("X", "UN u:LList(A). UN v: LList(A). {Lappend(u,v)}")] LList_coinduct 1); |
|
552 |
by (fast_tac set_cs 1); |
|
553 |
by (safe_tac set_cs); |
|
554 |
by (eres_inst_tac [("L", "u")] LListE 1); |
|
555 |
by (eres_inst_tac [("L", "v")] LListE 1); |
|
556 |
(* 7/12 vs 7.8/13.3/8.2/13.4 *) |
|
557 |
by (ALLGOALS |
|
558 |
(asm_simp_tac Lappend_ss THEN' |
|
559 |
fast_tac (set_cs addSIs [NIL_LListI,List_Fun_NIL_I,List_Fun_CONS_I]) )); |
|
560 |
(* |
|
561 |
by (REPEAT |
|
562 |
(ASM_SIMP_TAC Lappend_ss 1 THEN |
|
563 |
fast_tac (set_cs addSIs [NIL_LListI,List_Fun_NIL_I,List_Fun_CONS_I])1)); |
|
564 |
*) |
|
565 |
val Lappend_type = result(); |
|
566 |
||
567 |
(*strong co-induction: bisimulation and case analysis on one variable*) |
|
568 |
goal LList.thy |
|
569 |
"!!M N. [| M: LList(A); N: LList(A) |] ==> Lappend(M,N): LList(A)"; |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
570 |
by (res_inst_tac [("X", "(%u.Lappend(u,N))``LList(A)")] LList_coinduct 1); |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
571 |
be imageI 1; |
0 | 572 |
br subsetI 1; |
573 |
be imageE 1; |
|
574 |
by (eres_inst_tac [("L", "u")] LListE 1); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
575 |
by (asm_simp_tac (Lappend_ss addsimps [Lappend_NIL, List_Fun_LList_I]) 1); |
0 | 576 |
by (asm_simp_tac Lappend_ss 1); |
577 |
by (fast_tac (set_cs addSIs [List_Fun_CONS_I]) 1); |
|
578 |
val Lappend_type = result(); |
|
579 |
||
580 |
(**** Lazy lists as the type 'a llist -- strongly typed versions of above ****) |
|
581 |
||
582 |
(** llist_case: case analysis for 'a llist **) |
|
583 |
||
584 |
val Rep_LList_simps = |
|
585 |
[List_case_NIL, List_case_CONS, |
|
586 |
Abs_LList_inverse, Rep_LList_inverse, NIL_LListI, CONS_LListI, |
|
587 |
Rep_LList, rangeI, inj_Leaf, Inv_f_f]; |
|
588 |
val Rep_LList_ss = llist_ss addsimps Rep_LList_simps; |
|
589 |
||
590 |
goalw LList.thy [llist_case_def,LNil_def] "llist_case(LNil, c, d) = c"; |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
591 |
by (simp_tac Rep_LList_ss 1); |
0 | 592 |
val llist_case_LNil = result(); |
593 |
||
594 |
goalw LList.thy [llist_case_def,LCons_def] |
|
595 |
"llist_case(LCons(M,N), c, d) = d(M,N)"; |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
596 |
by (simp_tac Rep_LList_ss 1); |
0 | 597 |
val llist_case_LCons = result(); |
598 |
||
599 |
(*Elimination is case analysis, not induction.*) |
|
600 |
val [prem1,prem2] = goalw LList.thy [NIL_def,CONS_def] |
|
601 |
"[| l=LNil ==> P; !!x l'. l=LCons(x,l') ==> P \ |
|
602 |
\ |] ==> P"; |
|
603 |
by (rtac (Rep_LList RS LListE) 1); |
|
604 |
by (rtac (inj_Rep_LList RS injD RS prem1) 1); |
|
605 |
by (stac Rep_LList_LNil 1); |
|
606 |
by (assume_tac 1); |
|
607 |
by (etac rangeE 1); |
|
608 |
by (rtac (inj_Rep_LList RS injD RS prem2) 1); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
609 |
by (asm_simp_tac (HOL_ss addsimps [Rep_LList_LCons]) 1); |
0 | 610 |
by (etac (Abs_LList_inverse RS ssubst) 1); |
611 |
by (rtac refl 1); |
|
612 |
val llistE = result(); |
|
613 |
||
614 |
(** llist_corec: corecursion for 'a llist **) |
|
615 |
||
616 |
goalw LList.thy [llist_corec_def,LNil_def,LCons_def] |
|
38 | 617 |
"llist_corec(a,f) = sum_case(f(a), %u. LNil, \ |
0 | 618 |
\ %v. split(v, %z w. LCons(z, llist_corec(w,f))))"; |
619 |
by (stac LList_corec 1); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
620 |
by (res_inst_tac [("s","f(a)")] sumE 1); |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
621 |
by (asm_simp_tac (llist_ss addsimps [LList_corec_type2,Abs_LList_inverse]) 1); |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
622 |
by (res_inst_tac [("p","y")] PairE 1); |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
623 |
by (asm_simp_tac (llist_ss addsimps [LList_corec_type2,Abs_LList_inverse]) 1); |
0 | 624 |
(*FIXME: correct case splits usd to be found automatically: |
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
625 |
by (ASM_SIMP_TAC(llist_ss addsimps [LList_corec_type2,Abs_LList_inverse]) 1);*) |
0 | 626 |
val llist_corec = result(); |
627 |
||
628 |
(*definitional version of same*) |
|
629 |
val [rew] = goal LList.thy |
|
630 |
"[| !!x. h(x) == llist_corec(x,f) |] ==> \ |
|
38 | 631 |
\ h(a) = sum_case(f(a), %u.LNil, %v. split(v, %z w. LCons(z, h(w))))"; |
0 | 632 |
by (rewtac rew); |
633 |
by (rtac llist_corec 1); |
|
634 |
val def_llist_corec = result(); |
|
635 |
||
636 |
(**** Proofs about type 'a llist functions ****) |
|
637 |
||
638 |
(*** Deriving llist_equalityI -- llist equality is a bisimulation ***) |
|
639 |
||
640 |
val prems = goalw LList.thy [LListD_Fun_def] |
|
641 |
"r <= Sigma(LList(A), %x.LList(A)) ==> \ |
|
642 |
\ LListD_Fun(diag(A),r) <= Sigma(LList(A), %x.LList(A))"; |
|
643 |
by (stac LList_unfold 1); |
|
644 |
by (cut_facts_tac prems 1); |
|
645 |
by (fast_tac univ_cs 1); |
|
646 |
val LListD_Fun_subset_Sigma_LList = result(); |
|
647 |
||
648 |
goal LList.thy |
|
649 |
"prod_fun(Rep_LList,Rep_LList) `` r <= \ |
|
650 |
\ Sigma(LList(range(Leaf)), %x.LList(range(Leaf)))"; |
|
651 |
by (fast_tac (set_cs addSEs [prod_fun_imageE] addIs [SigmaI, Rep_LList]) 1); |
|
652 |
val subset_Sigma_LList = result(); |
|
653 |
||
654 |
val [prem] = goal LList.thy |
|
655 |
"r <= Sigma(LList(range(Leaf)), %x.LList(range(Leaf))) ==> \ |
|
656 |
\ prod_fun(Rep_LList o Abs_LList, Rep_LList o Abs_LList) `` r <= r"; |
|
657 |
by (safe_tac (set_cs addSEs [prod_fun_imageE])); |
|
658 |
by (rtac (prem RS subsetD RS SigmaE2) 1); |
|
659 |
by (assume_tac 1); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
660 |
by (asm_simp_tac (HOL_ss addsimps [o_def,prod_fun,Abs_LList_inverse]) 1); |
0 | 661 |
val prod_fun_lemma = result(); |
662 |
||
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
663 |
goal LList.thy |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
664 |
"prod_fun(Rep_LList, Rep_LList) `` range(%x. <x, x>) = \ |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
665 |
\ diag(LList(range(Leaf)))"; |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
666 |
br equalityI 1; |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
667 |
by (fast_tac (set_cs addIs [diagI, Rep_LList] |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
668 |
addSEs [prod_fun_imageE, Pair_inject]) 1); |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
669 |
by (fast_tac (set_cs addIs [prod_fun_imageI, rangeI] |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
670 |
addSEs [diagE, Abs_LList_inverse RS subst]) 1); |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
671 |
val prod_fun_range_eq_diag = result(); |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
672 |
|
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
673 |
(** To show two llists are equal, exhibit a bisimulation! |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
674 |
[also admits true equality] **) |
0 | 675 |
val [prem1,prem2] = goalw LList.thy [llistD_Fun_def] |
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
676 |
"[| <l1,l2> : r; r <= llistD_Fun(r Un range(%x.<x,x>)) |] ==> l1=l2"; |
0 | 677 |
by (rtac (inj_Rep_LList RS injD) 1); |
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
678 |
by (res_inst_tac [("r", "prod_fun(Rep_LList,Rep_LList)``r"), |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
679 |
("A", "range(Leaf)")] |
0 | 680 |
LList_equalityI 1); |
681 |
by (rtac (prem1 RS prod_fun_imageI) 1); |
|
682 |
by (rtac (prem2 RS image_mono RS subset_trans) 1); |
|
683 |
by (rtac (image_compose RS subst) 1); |
|
684 |
by (rtac (prod_fun_compose RS subst) 1); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
685 |
by (rtac (image_Un RS ssubst) 1); |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
686 |
by (stac prod_fun_range_eq_diag 1); |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
687 |
by (rtac (LListD_Fun_subset_Sigma_LList RS prod_fun_lemma) 1); |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
688 |
by (rtac (subset_Sigma_LList RS Un_least) 1); |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
689 |
by (rtac diag_subset_Sigma 1); |
0 | 690 |
val llist_equalityI = result(); |
691 |
||
692 |
(** Rules to prove the 2nd premise of llist_equalityI **) |
|
693 |
goalw LList.thy [llistD_Fun_def,LNil_def] "<LNil,LNil> : llistD_Fun(r)"; |
|
694 |
by (rtac (LListD_Fun_NIL_I RS prod_fun_imageI) 1); |
|
695 |
val llistD_Fun_LNil_I = result(); |
|
696 |
||
697 |
val [prem] = goalw LList.thy [llistD_Fun_def,LCons_def] |
|
698 |
"<l1,l2>:r ==> <LCons(x,l1), LCons(x,l2)> : llistD_Fun(r)"; |
|
699 |
by (rtac (rangeI RS LListD_Fun_CONS_I RS prod_fun_imageI) 1); |
|
700 |
by (rtac (prem RS prod_fun_imageI) 1); |
|
701 |
val llistD_Fun_LCons_I = result(); |
|
702 |
||
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
703 |
(*Utilise the "strong" part, i.e. gfp(f)*) |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
704 |
goalw LList.thy [llistD_Fun_def] |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
705 |
"!!l. <l,l> : llistD_Fun(r Un range(%x.<x,x>))"; |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
706 |
br (Rep_LList_inverse RS subst) 1; |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
707 |
br prod_fun_imageI 1; |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
708 |
by (rtac (image_Un RS ssubst) 1); |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
709 |
by (stac prod_fun_range_eq_diag 1); |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
710 |
br (Rep_LList RS LListD_Fun_diag_I) 1; |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
711 |
val llistD_Fun_range_I = result(); |
0 | 712 |
|
713 |
(*A special case of list_equality for functions over lazy lists*) |
|
714 |
val [prem1,prem2] = goal LList.thy |
|
715 |
"[| f(LNil)=g(LNil); \ |
|
716 |
\ !!x l. <f(LCons(x,l)),g(LCons(x,l))> : \ |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
717 |
\ llistD_Fun(range(%u. <f(u),g(u)>) Un range(%v. <v,v>)) \ |
0 | 718 |
\ |] ==> f(l) = g(l :: 'a llist) :: 'b llist"; |
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
719 |
by (res_inst_tac [("r", "range(%u. <f(u),g(u)>)")] llist_equalityI 1); |
0 | 720 |
by (rtac rangeI 1); |
721 |
by (rtac subsetI 1); |
|
722 |
by (etac rangeE 1); |
|
723 |
by (etac ssubst 1); |
|
724 |
by (res_inst_tac [("l", "u")] llistE 1); |
|
725 |
by (etac ssubst 1); |
|
726 |
by (stac prem1 1); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
727 |
by (rtac llistD_Fun_range_I 1); |
0 | 728 |
by (etac ssubst 1); |
729 |
by (rtac prem2 1); |
|
730 |
val llist_fun_equalityI = result(); |
|
731 |
||
732 |
(*simpset for llist bisimulations*) |
|
733 |
val llistD_simps = [llist_case_LNil, llist_case_LCons, range_eqI, |
|
734 |
llistD_Fun_LNil_I, llistD_Fun_LCons_I]; |
|
735 |
val llistD_ss = llist_ss addsimps llistD_simps; |
|
736 |
||
737 |
||
738 |
(*** The functional "lmap" ***) |
|
739 |
||
740 |
goal LList.thy "lmap(f,LNil) = LNil"; |
|
741 |
by (rtac (lmap_def RS def_llist_corec RS trans) 1); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
742 |
by (simp_tac llistD_ss 1); |
0 | 743 |
val lmap_LNil = result(); |
744 |
||
745 |
goal LList.thy "lmap(f, LCons(M,N)) = LCons(f(M), lmap(f,N))"; |
|
746 |
by (rtac (lmap_def RS def_llist_corec RS trans) 1); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
747 |
by (simp_tac llistD_ss 1); |
0 | 748 |
val lmap_LCons = result(); |
749 |
||
750 |
||
751 |
(** Two easy results about lmap **) |
|
752 |
||
753 |
goal LList.thy "lmap(f o g, l) = lmap(f, lmap(g, l))"; |
|
754 |
by (res_inst_tac [("l","l")] llist_fun_equalityI 1); |
|
755 |
by (ALLGOALS (simp_tac (llistD_ss addsimps [lmap_LNil, lmap_LCons]))); |
|
756 |
val lmap_compose = result(); |
|
757 |
||
758 |
goal LList.thy "lmap(%x.x, l) = l"; |
|
759 |
by (res_inst_tac [("l","l")] llist_fun_equalityI 1); |
|
760 |
by (ALLGOALS (simp_tac (llistD_ss addsimps [lmap_LNil, lmap_LCons]))); |
|
761 |
val lmap_ident = result(); |
|
762 |
||
763 |
||
764 |
(*** iterates -- llist_fun_equalityI cannot be used! ***) |
|
765 |
||
766 |
goal LList.thy "iterates(f,x) = LCons(x, iterates(f,f(x)))"; |
|
767 |
by (rtac (iterates_def RS def_llist_corec RS trans) 1); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
768 |
by (simp_tac sum_ss 1); |
0 | 769 |
val iterates = result(); |
770 |
||
771 |
goal LList.thy "lmap(f, iterates(f,x)) = iterates(f,f(x))"; |
|
772 |
by (res_inst_tac [("r", "range(%u.<lmap(f,iterates(f,u)),iterates(f,f(u))>)")] |
|
773 |
llist_equalityI 1); |
|
774 |
by (rtac rangeI 1); |
|
775 |
by (safe_tac set_cs); |
|
776 |
by (res_inst_tac [("x1", "f(u)")] (iterates RS ssubst) 1); |
|
777 |
by (res_inst_tac [("x1", "u")] (iterates RS ssubst) 1); |
|
778 |
by (simp_tac (llistD_ss addsimps [lmap_LCons]) 1); |
|
779 |
val lmap_iterates = result(); |
|
780 |
||
781 |
goal LList.thy "iterates(f,x) = LCons(x, lmap(f, iterates(f,x)))"; |
|
782 |
br (lmap_iterates RS ssubst) 1; |
|
783 |
br iterates 1; |
|
784 |
val iterates_lmap = result(); |
|
785 |
||
786 |
(*** A rather complex proof about iterates -- cf Andy Pitts ***) |
|
787 |
||
788 |
(** Two lemmas about natrec(n,x,%m.g), which is essentially (g^n)(x) **) |
|
789 |
||
790 |
goal LList.thy |
|
791 |
"nat_rec(n, LCons(b, l), %m. lmap(f)) = \ |
|
792 |
\ LCons(nat_rec(n, b, %m. f), nat_rec(n, l, %m. lmap(f)))"; |
|
793 |
by (nat_ind_tac "n" 1); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
794 |
by (ALLGOALS (asm_simp_tac (nat_ss addsimps [lmap_LCons]))); |
0 | 795 |
val fun_power_lmap = result(); |
796 |
||
797 |
goal Nat.thy "nat_rec(n, g(x), %m. g) = nat_rec(Suc(n), x, %m. g)"; |
|
798 |
by (nat_ind_tac "n" 1); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
799 |
by (ALLGOALS (asm_simp_tac nat_ss)); |
0 | 800 |
val fun_power_Suc = result(); |
801 |
||
802 |
val Pair_cong = read_instantiate_sg (sign_of Prod.thy) |
|
803 |
[("f","Pair")] (standard(refl RS cong RS cong)); |
|
804 |
||
805 |
(*The bisimulation consists of {<lmap(f)^n (h(u)), lmap(f)^n (iterates(f,u))>} |
|
806 |
for all u and all n::nat.*) |
|
807 |
val [prem] = goal LList.thy |
|
808 |
"(!!x. h(x) = LCons(x, lmap(f,h(x)))) ==> h = iterates(f)"; |
|
809 |
br ext 1; |
|
810 |
by (res_inst_tac [("r", |
|
811 |
"UN u. range(%n. <nat_rec(n, h(u), %m y.lmap(f,y)), \ |
|
812 |
\ nat_rec(n, iterates(f,u), %m y.lmap(f,y))>)")] |
|
813 |
llist_equalityI 1); |
|
814 |
by (REPEAT (resolve_tac [UN1_I, range_eqI, Pair_cong, nat_rec_0 RS sym] 1)); |
|
815 |
by (safe_tac set_cs); |
|
816 |
by (stac iterates 1); |
|
817 |
by (stac prem 1); |
|
818 |
by (stac fun_power_lmap 1); |
|
819 |
by (stac fun_power_lmap 1); |
|
820 |
br llistD_Fun_LCons_I 1; |
|
821 |
by (rtac (lmap_iterates RS subst) 1); |
|
822 |
by (stac fun_power_Suc 1); |
|
823 |
by (stac fun_power_Suc 1); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
824 |
br (UN1_I RS UnI1) 1; |
0 | 825 |
br rangeI 1; |
826 |
val iterates_equality = result(); |
|
827 |
||
828 |
||
829 |
(*** lappend -- its two arguments cause some complications! ***) |
|
830 |
||
831 |
goalw LList.thy [lappend_def] "lappend(LNil,LNil) = LNil"; |
|
832 |
by (rtac (llist_corec RS trans) 1); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
833 |
by (simp_tac llistD_ss 1); |
0 | 834 |
val lappend_LNil_LNil = result(); |
835 |
||
836 |
goalw LList.thy [lappend_def] |
|
837 |
"lappend(LNil,LCons(l,l')) = LCons(l, lappend(LNil,l'))"; |
|
838 |
by (rtac (llist_corec RS trans) 1); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
839 |
by (simp_tac llistD_ss 1); |
0 | 840 |
(* 3.3(5.7) vs 1.3 !by (SIMP_TAC llistD_ss 1);*) |
841 |
val lappend_LNil_LCons = result(); |
|
842 |
||
843 |
goalw LList.thy [lappend_def] |
|
844 |
"lappend(LCons(l,l'), N) = LCons(l, lappend(l',N))"; |
|
845 |
by (rtac (llist_corec RS trans) 1); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
846 |
by (simp_tac llistD_ss 1); |
0 | 847 |
(* 5(5.5) vs 1.3 !by (SIMP_TAC llistD_ss 1);*) |
848 |
val lappend_LCons = result(); |
|
849 |
||
850 |
goal LList.thy "lappend(LNil,l) = l"; |
|
851 |
by (res_inst_tac [("l","l")] llist_fun_equalityI 1); |
|
852 |
by (ALLGOALS (simp_tac (llistD_ss addsimps [lappend_LNil_LNil, |
|
853 |
lappend_LNil_LCons]))); |
|
854 |
val lappend_LNil = result(); |
|
855 |
||
856 |
goal LList.thy "lappend(l,LNil) = l"; |
|
857 |
by (res_inst_tac [("l","l")] llist_fun_equalityI 1); |
|
858 |
by (ALLGOALS (simp_tac(llistD_ss addsimps [lappend_LNil_LNil,lappend_LCons]))); |
|
859 |
val lappend_LNil2 = result(); |
|
860 |
||
861 |
(*The infinite first argument blocks the second*) |
|
862 |
goal LList.thy "lappend(iterates(f,x), N) = iterates(f,x)"; |
|
863 |
by (res_inst_tac [("r", "range(%u.<lappend(iterates(f,u),N),iterates(f,u)>)")] |
|
864 |
llist_equalityI 1); |
|
865 |
by (rtac rangeI 1); |
|
866 |
by (safe_tac set_cs); |
|
867 |
by (stac iterates 1); |
|
868 |
by (simp_tac (llistD_ss addsimps [lappend_LCons]) 1); |
|
869 |
val lappend_iterates = result(); |
|
870 |
||
871 |
(** Two proofs that lmap distributes over lappend **) |
|
872 |
||
873 |
(*Long proof requiring case analysis on both both arguments*) |
|
874 |
goal LList.thy "lmap(f, lappend(l,n)) = lappend(lmap(f,l), lmap(f,n))"; |
|
875 |
by (res_inst_tac |
|
876 |
[("r", |
|
877 |
"UN n. range(%l.<lmap(f,lappend(l,n)), lappend(lmap(f,l),lmap(f,n))>)")] |
|
878 |
llist_equalityI 1); |
|
879 |
by (rtac UN1_I 1); |
|
880 |
by (rtac rangeI 1); |
|
881 |
by (safe_tac set_cs); |
|
882 |
by (res_inst_tac [("l", "l")] llistE 1); |
|
883 |
by (res_inst_tac [("l", "n")] llistE 1); |
|
884 |
by (ALLGOALS (asm_simp_tac (llistD_ss addsimps |
|
885 |
[lappend_LNil_LNil,lappend_LCons,lappend_LNil_LCons, |
|
886 |
lmap_LNil,lmap_LCons]))); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
887 |
by (REPEAT_SOME (ares_tac [llistD_Fun_LCons_I, UN1_I RS UnI1, rangeI])); |
0 | 888 |
by (rtac range_eqI 1); |
889 |
by (rtac (refl RS Pair_cong) 1); |
|
890 |
by (stac lmap_LNil 1); |
|
891 |
by (rtac refl 1); |
|
892 |
val lmap_lappend_distrib = result(); |
|
893 |
||
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
894 |
(*Shorter proof of theorem above using llist_equalityI as strong coinduction*) |
0 | 895 |
goal LList.thy "lmap(f, lappend(l,n)) = lappend(lmap(f,l), lmap(f,n))"; |
896 |
by (res_inst_tac [("l","l")] llist_fun_equalityI 1); |
|
897 |
by (simp_tac (llistD_ss addsimps [lappend_LNil, lmap_LNil])1); |
|
898 |
by (simp_tac (llistD_ss addsimps [lappend_LCons, lmap_LCons]) 1); |
|
899 |
val lmap_lappend_distrib = result(); |
|
900 |
||
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
901 |
(*Without strong coinduction, three case analyses might be needed*) |
0 | 902 |
goal LList.thy "lappend(lappend(l1,l2) ,l3) = lappend(l1, lappend(l2,l3))"; |
903 |
by (res_inst_tac [("l","l1")] llist_fun_equalityI 1); |
|
904 |
by (simp_tac (llistD_ss addsimps [lappend_LNil])1); |
|
905 |
by (simp_tac (llistD_ss addsimps [lappend_LCons]) 1); |
|
906 |
val lappend_assoc = result(); |