author | nipkow |
Tue, 10 Mar 1998 16:47:26 +0100 | |
changeset 4716 | a291e858061c |
parent 4681 | a331c1f5a23e |
child 4721 | c8a8482a8124 |
permissions | -rw-r--r-- |
3071 | 1 |
(* Title: HOLCF/IOA/meta_theory/Sequence.ML |
3275 | 2 |
ID: $Id$ |
3071 | 3 |
Author: Olaf M"uller |
4 |
Copyright 1996 TU Muenchen |
|
5 |
||
6 |
Theorems about Sequences over flat domains with lifted elements |
|
7 |
||
8 |
*) |
|
9 |
||
3656 | 10 |
|
3071 | 11 |
Addsimps [andalso_and,andalso_or]; |
12 |
||
13 |
(* ----------------------------------------------------------------------------------- *) |
|
14 |
||
15 |
section "recursive equations of operators"; |
|
16 |
||
17 |
(* ---------------------------------------------------------------- *) |
|
18 |
(* Map *) |
|
19 |
(* ---------------------------------------------------------------- *) |
|
20 |
||
21 |
goal thy "Map f`UU =UU"; |
|
4098 | 22 |
by (simp_tac (simpset() addsimps [Map_def]) 1); |
3071 | 23 |
qed"Map_UU"; |
24 |
||
25 |
goal thy "Map f`nil =nil"; |
|
4098 | 26 |
by (simp_tac (simpset() addsimps [Map_def]) 1); |
3071 | 27 |
qed"Map_nil"; |
28 |
||
29 |
goal thy "Map f`(x>>xs)=(f x) >> Map f`xs"; |
|
4098 | 30 |
by (simp_tac (simpset() addsimps [Map_def, Cons_def,flift2_def]) 1); |
3071 | 31 |
qed"Map_cons"; |
32 |
||
33 |
(* ---------------------------------------------------------------- *) |
|
34 |
(* Filter *) |
|
35 |
(* ---------------------------------------------------------------- *) |
|
36 |
||
37 |
goal thy "Filter P`UU =UU"; |
|
4098 | 38 |
by (simp_tac (simpset() addsimps [Filter_def]) 1); |
3071 | 39 |
qed"Filter_UU"; |
40 |
||
41 |
goal thy "Filter P`nil =nil"; |
|
4098 | 42 |
by (simp_tac (simpset() addsimps [Filter_def]) 1); |
3071 | 43 |
qed"Filter_nil"; |
44 |
||
45 |
goal thy "Filter P`(x>>xs)= (if P x then x>>(Filter P`xs) else Filter P`xs)"; |
|
4098 | 46 |
by (simp_tac (simpset() addsimps [Filter_def, Cons_def,flift2_def,If_and_if]) 1); |
3071 | 47 |
qed"Filter_cons"; |
48 |
||
49 |
(* ---------------------------------------------------------------- *) |
|
50 |
(* Forall *) |
|
51 |
(* ---------------------------------------------------------------- *) |
|
52 |
||
53 |
goal thy "Forall P UU"; |
|
4098 | 54 |
by (simp_tac (simpset() addsimps [Forall_def,sforall_def]) 1); |
3071 | 55 |
qed"Forall_UU"; |
56 |
||
57 |
goal thy "Forall P nil"; |
|
4098 | 58 |
by (simp_tac (simpset() addsimps [Forall_def,sforall_def]) 1); |
3071 | 59 |
qed"Forall_nil"; |
60 |
||
61 |
goal thy "Forall P (x>>xs)= (P x & Forall P xs)"; |
|
4098 | 62 |
by (simp_tac (simpset() addsimps [Forall_def, sforall_def, |
3071 | 63 |
Cons_def,flift2_def]) 1); |
64 |
qed"Forall_cons"; |
|
65 |
||
66 |
(* ---------------------------------------------------------------- *) |
|
67 |
(* Conc *) |
|
68 |
(* ---------------------------------------------------------------- *) |
|
69 |
||
70 |
||
71 |
goal thy "(x>>xs) @@ y = x>>(xs @@y)"; |
|
4098 | 72 |
by (simp_tac (simpset() addsimps [Cons_def]) 1); |
3071 | 73 |
qed"Conc_cons"; |
74 |
||
75 |
(* ---------------------------------------------------------------- *) |
|
76 |
(* Takewhile *) |
|
77 |
(* ---------------------------------------------------------------- *) |
|
78 |
||
79 |
goal thy "Takewhile P`UU =UU"; |
|
4098 | 80 |
by (simp_tac (simpset() addsimps [Takewhile_def]) 1); |
3071 | 81 |
qed"Takewhile_UU"; |
82 |
||
83 |
goal thy "Takewhile P`nil =nil"; |
|
4098 | 84 |
by (simp_tac (simpset() addsimps [Takewhile_def]) 1); |
3071 | 85 |
qed"Takewhile_nil"; |
86 |
||
87 |
goal thy "Takewhile P`(x>>xs)= (if P x then x>>(Takewhile P`xs) else nil)"; |
|
4098 | 88 |
by (simp_tac (simpset() addsimps [Takewhile_def, Cons_def,flift2_def,If_and_if]) 1); |
3071 | 89 |
qed"Takewhile_cons"; |
90 |
||
91 |
(* ---------------------------------------------------------------- *) |
|
92 |
(* Dropwhile *) |
|
93 |
(* ---------------------------------------------------------------- *) |
|
94 |
||
95 |
goal thy "Dropwhile P`UU =UU"; |
|
4098 | 96 |
by (simp_tac (simpset() addsimps [Dropwhile_def]) 1); |
3071 | 97 |
qed"Dropwhile_UU"; |
98 |
||
99 |
goal thy "Dropwhile P`nil =nil"; |
|
4098 | 100 |
by (simp_tac (simpset() addsimps [Dropwhile_def]) 1); |
3071 | 101 |
qed"Dropwhile_nil"; |
102 |
||
103 |
goal thy "Dropwhile P`(x>>xs)= (if P x then Dropwhile P`xs else x>>xs)"; |
|
4098 | 104 |
by (simp_tac (simpset() addsimps [Dropwhile_def, Cons_def,flift2_def,If_and_if]) 1); |
3071 | 105 |
qed"Dropwhile_cons"; |
106 |
||
107 |
(* ---------------------------------------------------------------- *) |
|
108 |
(* Last *) |
|
109 |
(* ---------------------------------------------------------------- *) |
|
110 |
||
111 |
||
112 |
goal thy "Last`UU =UU"; |
|
4098 | 113 |
by (simp_tac (simpset() addsimps [Last_def]) 1); |
3071 | 114 |
qed"Last_UU"; |
115 |
||
116 |
goal thy "Last`nil =UU"; |
|
4098 | 117 |
by (simp_tac (simpset() addsimps [Last_def]) 1); |
3071 | 118 |
qed"Last_nil"; |
119 |
||
120 |
goal thy "Last`(x>>xs)= (if xs=nil then Def x else Last`xs)"; |
|
4098 | 121 |
by (simp_tac (simpset() addsimps [Last_def, Cons_def]) 1); |
4042 | 122 |
by (res_inst_tac [("x","xs")] seq.casedist 1); |
4098 | 123 |
by (asm_simp_tac (simpset() setloop split_tac [expand_if]) 1); |
3071 | 124 |
by (REPEAT (Asm_simp_tac 1)); |
125 |
qed"Last_cons"; |
|
126 |
||
127 |
||
128 |
(* ---------------------------------------------------------------- *) |
|
129 |
(* Flat *) |
|
130 |
(* ---------------------------------------------------------------- *) |
|
131 |
||
132 |
goal thy "Flat`UU =UU"; |
|
4098 | 133 |
by (simp_tac (simpset() addsimps [Flat_def]) 1); |
3071 | 134 |
qed"Flat_UU"; |
135 |
||
136 |
goal thy "Flat`nil =nil"; |
|
4098 | 137 |
by (simp_tac (simpset() addsimps [Flat_def]) 1); |
3071 | 138 |
qed"Flat_nil"; |
139 |
||
140 |
goal thy "Flat`(x##xs)= x @@ (Flat`xs)"; |
|
4098 | 141 |
by (simp_tac (simpset() addsimps [Flat_def, Cons_def]) 1); |
3071 | 142 |
qed"Flat_cons"; |
143 |
||
144 |
||
145 |
(* ---------------------------------------------------------------- *) |
|
146 |
(* Zip *) |
|
147 |
(* ---------------------------------------------------------------- *) |
|
148 |
||
149 |
goal thy "Zip = (LAM t1 t2. case t1 of \ |
|
150 |
\ nil => nil \ |
|
151 |
\ | x##xs => (case t2 of \ |
|
152 |
\ nil => UU \ |
|
153 |
\ | y##ys => (case x of \ |
|
154 |
\ Undef => UU \ |
|
155 |
\ | Def a => (case y of \ |
|
156 |
\ Undef => UU \ |
|
157 |
\ | Def b => Def (a,b)##(Zip`xs`ys)))))"; |
|
158 |
by (rtac trans 1); |
|
3457 | 159 |
by (rtac fix_eq2 1); |
160 |
by (rtac Zip_def 1); |
|
161 |
by (rtac beta_cfun 1); |
|
3071 | 162 |
by (Simp_tac 1); |
163 |
qed"Zip_unfold"; |
|
164 |
||
165 |
goal thy "Zip`UU`y =UU"; |
|
166 |
by (stac Zip_unfold 1); |
|
167 |
by (Simp_tac 1); |
|
168 |
qed"Zip_UU1"; |
|
169 |
||
170 |
goal thy "!! x. x~=nil ==> Zip`x`UU =UU"; |
|
171 |
by (stac Zip_unfold 1); |
|
172 |
by (Simp_tac 1); |
|
4042 | 173 |
by (res_inst_tac [("x","x")] seq.casedist 1); |
3071 | 174 |
by (REPEAT (Asm_full_simp_tac 1)); |
175 |
qed"Zip_UU2"; |
|
176 |
||
177 |
goal thy "Zip`nil`y =nil"; |
|
178 |
by (stac Zip_unfold 1); |
|
179 |
by (Simp_tac 1); |
|
180 |
qed"Zip_nil"; |
|
181 |
||
182 |
goal thy "Zip`(x>>xs)`nil= UU"; |
|
183 |
by (stac Zip_unfold 1); |
|
4098 | 184 |
by (simp_tac (simpset() addsimps [Cons_def]) 1); |
3071 | 185 |
qed"Zip_cons_nil"; |
186 |
||
187 |
goal thy "Zip`(x>>xs)`(y>>ys)= (x,y) >> Zip`xs`ys"; |
|
3457 | 188 |
by (rtac trans 1); |
3071 | 189 |
by (stac Zip_unfold 1); |
190 |
by (Simp_tac 1); |
|
191 |
(* FIX: Why Simp_tac 2 times. Does continuity in simpflication make job sometimes not |
|
192 |
completely ready ? *) |
|
4098 | 193 |
by (simp_tac (simpset() addsimps [Cons_def]) 1); |
3071 | 194 |
qed"Zip_cons"; |
195 |
||
196 |
||
197 |
Delsimps [sfilter_UU,sfilter_nil,sfilter_cons, |
|
198 |
smap_UU,smap_nil,smap_cons, |
|
199 |
sforall2_UU,sforall2_nil,sforall2_cons, |
|
200 |
slast_UU,slast_nil,slast_cons, |
|
201 |
stakewhile_UU, stakewhile_nil, stakewhile_cons, |
|
202 |
sdropwhile_UU, sdropwhile_nil, sdropwhile_cons, |
|
203 |
sflat_UU,sflat_nil,sflat_cons, |
|
204 |
szip_UU1,szip_UU2,szip_nil,szip_cons_nil,szip_cons]; |
|
205 |
||
206 |
||
207 |
Addsimps [Filter_UU,Filter_nil,Filter_cons, |
|
208 |
Map_UU,Map_nil,Map_cons, |
|
209 |
Forall_UU,Forall_nil,Forall_cons, |
|
210 |
Last_UU,Last_nil,Last_cons, |
|
3275 | 211 |
Conc_cons, |
3071 | 212 |
Takewhile_UU, Takewhile_nil, Takewhile_cons, |
213 |
Dropwhile_UU, Dropwhile_nil, Dropwhile_cons, |
|
214 |
Zip_UU1,Zip_UU2,Zip_nil,Zip_cons_nil,Zip_cons]; |
|
215 |
||
216 |
||
217 |
(* |
|
218 |
||
219 |
Can Filter with HOL predicate directly be defined as fixpoint ? |
|
220 |
||
221 |
goal thy "Filter2 P = (LAM tr. case tr of \ |
|
222 |
\ nil => nil \ |
|
223 |
\ | x##xs => (case x of Undef => UU | Def y => \ |
|
224 |
\ (if P y then y>>(Filter2 P`xs) else Filter2 P`xs)))"; |
|
225 |
by (rtac trans 1); |
|
3457 | 226 |
by (rtac fix_eq2 1); |
227 |
by (rtac Filter2_def 1); |
|
228 |
by (rtac beta_cfun 1); |
|
3071 | 229 |
by (Simp_tac 1); |
230 |
||
231 |
is also possible, if then else has to be proven continuous and it would be nice if a case for |
|
232 |
Seq would be available. |
|
233 |
||
234 |
*) |
|
235 |
||
236 |
||
237 |
(* ------------------------------------------------------------------------------------- *) |
|
238 |
||
239 |
||
240 |
section "Cons"; |
|
241 |
||
242 |
goal thy "a>>s = (Def a)##s"; |
|
4098 | 243 |
by (simp_tac (simpset() addsimps [Cons_def]) 1); |
3071 | 244 |
qed"Cons_def2"; |
245 |
||
246 |
goal thy "x = UU | x = nil | (? a s. x = a >> s)"; |
|
4098 | 247 |
by (simp_tac (simpset() addsimps [Cons_def2]) 1); |
3071 | 248 |
by (cut_facts_tac [seq.exhaust] 1); |
249 |
by (fast_tac (HOL_cs addDs [not_Undef_is_Def RS iffD1]) 1); |
|
250 |
qed"Seq_exhaust"; |
|
251 |
||
252 |
||
253 |
goal thy "!!P. [| x = UU ==> P; x = nil ==> P; !!a s. x = a >> s ==> P |] ==> P"; |
|
254 |
by (cut_inst_tac [("x","x")] Seq_exhaust 1); |
|
3457 | 255 |
by (etac disjE 1); |
3071 | 256 |
by (Asm_full_simp_tac 1); |
3457 | 257 |
by (etac disjE 1); |
3071 | 258 |
by (Asm_full_simp_tac 1); |
259 |
by (REPEAT (etac exE 1)); |
|
260 |
by (Asm_full_simp_tac 1); |
|
261 |
qed"Seq_cases"; |
|
262 |
||
263 |
fun Seq_case_tac s i = res_inst_tac [("x",s)] Seq_cases i |
|
264 |
THEN hyp_subst_tac i THEN hyp_subst_tac (i+1) THEN hyp_subst_tac (i+2); |
|
265 |
||
266 |
(* on a>>s only simp_tac, as full_simp_tac is uncomplete and often causes errors *) |
|
267 |
fun Seq_case_simp_tac s i = Seq_case_tac s i THEN Asm_simp_tac (i+2) |
|
268 |
THEN Asm_full_simp_tac (i+1) |
|
269 |
THEN Asm_full_simp_tac i; |
|
270 |
||
271 |
goal thy "a>>s ~= UU"; |
|
272 |
by (stac Cons_def2 1); |
|
273 |
by (resolve_tac seq.con_rews 1); |
|
3457 | 274 |
by (rtac Def_not_UU 1); |
3071 | 275 |
qed"Cons_not_UU"; |
276 |
||
3275 | 277 |
|
3071 | 278 |
goal thy "~(a>>x) << UU"; |
279 |
by (rtac notI 1); |
|
280 |
by (dtac antisym_less 1); |
|
281 |
by (Simp_tac 1); |
|
4098 | 282 |
by (asm_full_simp_tac (simpset() addsimps [Cons_not_UU]) 1); |
3071 | 283 |
qed"Cons_not_less_UU"; |
284 |
||
285 |
goal thy "~a>>s << nil"; |
|
286 |
by (stac Cons_def2 1); |
|
287 |
by (resolve_tac seq.rews 1); |
|
3457 | 288 |
by (rtac Def_not_UU 1); |
3071 | 289 |
qed"Cons_not_less_nil"; |
290 |
||
291 |
goal thy "a>>s ~= nil"; |
|
292 |
by (stac Cons_def2 1); |
|
293 |
by (resolve_tac seq.rews 1); |
|
294 |
qed"Cons_not_nil"; |
|
295 |
||
3275 | 296 |
goal thy "nil ~= a>>s"; |
4098 | 297 |
by (simp_tac (simpset() addsimps [Cons_def2]) 1); |
3275 | 298 |
qed"Cons_not_nil2"; |
299 |
||
3071 | 300 |
goal thy "(a>>s = b>>t) = (a = b & s = t)"; |
301 |
by (simp_tac (HOL_ss addsimps [Cons_def2]) 1); |
|
302 |
by (stac (hd lift.inject RS sym) 1); |
|
303 |
back(); back(); |
|
304 |
by (rtac scons_inject_eq 1); |
|
305 |
by (REPEAT(rtac Def_not_UU 1)); |
|
306 |
qed"Cons_inject_eq"; |
|
307 |
||
308 |
goal thy "(a>>s<<b>>t) = (a = b & s<<t)"; |
|
4098 | 309 |
by (simp_tac (simpset() addsimps [Cons_def2]) 1); |
3071 | 310 |
by (stac (Def_inject_less_eq RS sym) 1); |
311 |
back(); |
|
312 |
by (rtac iffI 1); |
|
313 |
(* 1 *) |
|
314 |
by (etac (hd seq.inverts) 1); |
|
315 |
by (REPEAT(rtac Def_not_UU 1)); |
|
316 |
(* 2 *) |
|
317 |
by (Asm_full_simp_tac 1); |
|
318 |
by (etac conjE 1); |
|
319 |
by (etac monofun_cfun_arg 1); |
|
320 |
qed"Cons_inject_less_eq"; |
|
321 |
||
322 |
goal thy "seq_take (Suc n)`(a>>x) = a>> (seq_take n`x)"; |
|
4098 | 323 |
by (simp_tac (simpset() addsimps [Cons_def]) 1); |
3071 | 324 |
qed"seq_take_Cons"; |
325 |
||
3275 | 326 |
Addsimps [Cons_not_nil2,Cons_inject_eq,Cons_inject_less_eq,seq_take_Cons, |
3071 | 327 |
Cons_not_UU,Cons_not_less_UU,Cons_not_less_nil,Cons_not_nil]; |
328 |
||
3275 | 329 |
(* Instead of adding UU_neq_Cons every equation UU~=x could be changed to x~=UU *) |
330 |
goal thy "UU ~= x>>xs"; |
|
331 |
by (res_inst_tac [("s1","UU"),("t1","x>>xs")] (sym RS rev_contrapos) 1); |
|
332 |
by (REPEAT (Simp_tac 1)); |
|
333 |
qed"UU_neq_Cons"; |
|
334 |
||
335 |
Addsimps [UU_neq_Cons]; |
|
336 |
||
3071 | 337 |
|
338 |
(* ----------------------------------------------------------------------------------- *) |
|
339 |
||
340 |
section "induction"; |
|
341 |
||
342 |
goal thy "!! P. [| adm P; P UU; P nil; !! a s. P s ==> P (a>>s)|] ==> P x"; |
|
3457 | 343 |
by (etac seq.ind 1); |
3071 | 344 |
by (REPEAT (atac 1)); |
345 |
by (def_tac 1); |
|
4098 | 346 |
by (asm_full_simp_tac (simpset() addsimps [Cons_def]) 1); |
3071 | 347 |
qed"Seq_induct"; |
348 |
||
349 |
goal thy "!! P.[|P UU;P nil; !! a s. P s ==> P(a>>s) |] \ |
|
350 |
\ ==> seq_finite x --> P x"; |
|
3457 | 351 |
by (etac seq_finite_ind 1); |
3071 | 352 |
by (REPEAT (atac 1)); |
353 |
by (def_tac 1); |
|
4098 | 354 |
by (asm_full_simp_tac (simpset() addsimps [Cons_def]) 1); |
3071 | 355 |
qed"Seq_FinitePartial_ind"; |
356 |
||
357 |
goal thy "!! P.[| Finite x; P nil; !! a s. [| Finite s; P s|] ==> P (a>>s) |] ==> P x"; |
|
3457 | 358 |
by (etac sfinite.induct 1); |
359 |
by (assume_tac 1); |
|
3071 | 360 |
by (def_tac 1); |
4098 | 361 |
by (asm_full_simp_tac (simpset() addsimps [Cons_def]) 1); |
3071 | 362 |
qed"Seq_Finite_ind"; |
363 |
||
364 |
||
365 |
(* rws are definitions to be unfolded for admissibility check *) |
|
366 |
fun Seq_induct_tac s rws i = res_inst_tac [("x",s)] Seq_induct i |
|
367 |
THEN (REPEAT_DETERM (CHANGED (Asm_simp_tac (i+1)))) |
|
4098 | 368 |
THEN simp_tac (simpset() addsimps rws) i; |
3071 | 369 |
|
370 |
fun Seq_Finite_induct_tac i = etac Seq_Finite_ind i |
|
371 |
THEN (REPEAT_DETERM (CHANGED (Asm_simp_tac i))); |
|
372 |
||
373 |
fun pair_tac s = res_inst_tac [("p",s)] PairE |
|
374 |
THEN' hyp_subst_tac THEN' Asm_full_simp_tac; |
|
375 |
||
376 |
(* induction on a sequence of pairs with pairsplitting and simplification *) |
|
377 |
fun pair_induct_tac s rws i = |
|
378 |
res_inst_tac [("x",s)] Seq_induct i |
|
379 |
THEN pair_tac "a" (i+3) |
|
380 |
THEN (REPEAT_DETERM (CHANGED (Simp_tac (i+1)))) |
|
4098 | 381 |
THEN simp_tac (simpset() addsimps rws) i; |
3071 | 382 |
|
383 |
||
384 |
||
385 |
(* ------------------------------------------------------------------------------------ *) |
|
386 |
||
387 |
section "HD,TL"; |
|
388 |
||
389 |
goal thy "HD`(x>>y) = Def x"; |
|
4098 | 390 |
by (simp_tac (simpset() addsimps [Cons_def]) 1); |
3071 | 391 |
qed"HD_Cons"; |
392 |
||
393 |
goal thy "TL`(x>>y) = y"; |
|
4098 | 394 |
by (simp_tac (simpset() addsimps [Cons_def]) 1); |
3071 | 395 |
qed"TL_Cons"; |
396 |
||
397 |
Addsimps [HD_Cons,TL_Cons]; |
|
398 |
||
399 |
(* ------------------------------------------------------------------------------------ *) |
|
400 |
||
401 |
section "Finite, Partial, Infinite"; |
|
402 |
||
403 |
goal thy "Finite (a>>xs) = Finite xs"; |
|
4098 | 404 |
by (simp_tac (simpset() addsimps [Cons_def2,Finite_cons]) 1); |
3071 | 405 |
qed"Finite_Cons"; |
406 |
||
407 |
Addsimps [Finite_Cons]; |
|
3275 | 408 |
goal thy "!! x. Finite (x::'a Seq) ==> Finite y --> Finite (x@@y)"; |
409 |
by (Seq_Finite_induct_tac 1); |
|
410 |
qed"FiniteConc_1"; |
|
411 |
||
412 |
goal thy "!! z. Finite (z::'a Seq) ==> !x y. z= x@@y --> (Finite x & Finite y)"; |
|
413 |
by (Seq_Finite_induct_tac 1); |
|
414 |
(* nil*) |
|
415 |
by (strip_tac 1); |
|
416 |
by (Seq_case_simp_tac "x" 1); |
|
417 |
by (Asm_full_simp_tac 1); |
|
418 |
(* cons *) |
|
419 |
by (strip_tac 1); |
|
420 |
by (Seq_case_simp_tac "x" 1); |
|
421 |
by (Seq_case_simp_tac "y" 1); |
|
4098 | 422 |
by (SELECT_GOAL (auto_tac (claset(),simpset()))1); |
3275 | 423 |
by (eres_inst_tac [("x","sa")] allE 1); |
424 |
by (eres_inst_tac [("x","y")] allE 1); |
|
425 |
by (Asm_full_simp_tac 1); |
|
426 |
qed"FiniteConc_2"; |
|
427 |
||
428 |
goal thy "Finite(x@@y) = (Finite (x::'a Seq) & Finite y)"; |
|
429 |
by (rtac iffI 1); |
|
3457 | 430 |
by (etac (FiniteConc_2 RS spec RS spec RS mp) 1); |
431 |
by (rtac refl 1); |
|
432 |
by (rtac (FiniteConc_1 RS mp) 1); |
|
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4098
diff
changeset
|
433 |
by Auto_tac; |
3275 | 434 |
qed"FiniteConc"; |
435 |
||
436 |
Addsimps [FiniteConc]; |
|
437 |
||
438 |
||
439 |
goal thy "!! s. Finite s ==> Finite (Map f`s)"; |
|
440 |
by (Seq_Finite_induct_tac 1); |
|
441 |
qed"FiniteMap1"; |
|
442 |
||
443 |
goal thy "!! s. Finite s ==> ! t. (s = Map f`t) --> Finite t"; |
|
444 |
by (Seq_Finite_induct_tac 1); |
|
445 |
by (strip_tac 1); |
|
446 |
by (Seq_case_simp_tac "t" 1); |
|
447 |
by (Asm_full_simp_tac 1); |
|
448 |
(* main case *) |
|
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4098
diff
changeset
|
449 |
by Auto_tac; |
3275 | 450 |
by (Seq_case_simp_tac "t" 1); |
451 |
by (Asm_full_simp_tac 1); |
|
452 |
qed"FiniteMap2"; |
|
453 |
||
454 |
goal thy "Finite (Map f`s) = Finite s"; |
|
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4098
diff
changeset
|
455 |
by Auto_tac; |
3457 | 456 |
by (etac (FiniteMap2 RS spec RS mp) 1); |
457 |
by (rtac refl 1); |
|
458 |
by (etac FiniteMap1 1); |
|
3275 | 459 |
qed"Map2Finite"; |
460 |
||
3433
2de17c994071
added deadlock freedom, polished definitions and proofs
mueller
parents:
3361
diff
changeset
|
461 |
|
2de17c994071
added deadlock freedom, polished definitions and proofs
mueller
parents:
3361
diff
changeset
|
462 |
goal thy "!! s. Finite s ==> Finite (Filter P`s)"; |
2de17c994071
added deadlock freedom, polished definitions and proofs
mueller
parents:
3361
diff
changeset
|
463 |
by (Seq_Finite_induct_tac 1); |
2de17c994071
added deadlock freedom, polished definitions and proofs
mueller
parents:
3361
diff
changeset
|
464 |
qed"FiniteFilter"; |
2de17c994071
added deadlock freedom, polished definitions and proofs
mueller
parents:
3361
diff
changeset
|
465 |
|
2de17c994071
added deadlock freedom, polished definitions and proofs
mueller
parents:
3361
diff
changeset
|
466 |
|
3361 | 467 |
(* ----------------------------------------------------------------------------------- *) |
468 |
||
469 |
||
470 |
section "admissibility"; |
|
471 |
||
472 |
(* Finite x is proven to be adm: Finite_flat shows that there are only chains of length one. |
|
3461 | 473 |
Then the assumption that an _infinite_ chain exists (from admI2) is set to a contradiction |
3361 | 474 |
to Finite_flat *) |
475 |
||
476 |
goal thy "!! (x:: 'a Seq). Finite x ==> !y. Finite (y:: 'a Seq) & x<<y --> x=y"; |
|
477 |
by (Seq_Finite_induct_tac 1); |
|
478 |
by (strip_tac 1); |
|
3457 | 479 |
by (etac conjE 1); |
480 |
by (etac nil_less_is_nil 1); |
|
3361 | 481 |
(* main case *) |
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4098
diff
changeset
|
482 |
by Auto_tac; |
3361 | 483 |
by (Seq_case_simp_tac "y" 1); |
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4098
diff
changeset
|
484 |
by Auto_tac; |
3361 | 485 |
qed_spec_mp"Finite_flat"; |
486 |
||
487 |
||
488 |
goal thy "adm(%(x:: 'a Seq).Finite x)"; |
|
3461 | 489 |
by (rtac admI2 1); |
3361 | 490 |
by (eres_inst_tac [("x","0")] allE 1); |
491 |
back(); |
|
3457 | 492 |
by (etac exE 1); |
3361 | 493 |
by (REPEAT (etac conjE 1)); |
494 |
by (res_inst_tac [("x","0")] allE 1); |
|
3457 | 495 |
by (assume_tac 1); |
3361 | 496 |
by (eres_inst_tac [("x","j")] allE 1); |
497 |
by (cut_inst_tac [("x","Y 0"),("y","Y j")] Finite_flat 1); |
|
498 |
(* Generates a contradiction in subgoal 3 *) |
|
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4098
diff
changeset
|
499 |
by Auto_tac; |
3361 | 500 |
qed"adm_Finite"; |
501 |
||
502 |
Addsimps [adm_Finite]; |
|
503 |
||
3071 | 504 |
|
505 |
(* ------------------------------------------------------------------------------------ *) |
|
506 |
||
507 |
section "Conc"; |
|
508 |
||
509 |
goal thy "!! x::'a Seq. Finite x ==> ((x @@ y) = (x @@ z)) = (y = z)"; |
|
510 |
by (Seq_Finite_induct_tac 1); |
|
511 |
qed"Conc_cong"; |
|
512 |
||
3275 | 513 |
goal thy "(x @@ y) @@ z = (x::'a Seq) @@ y @@ z"; |
514 |
by (Seq_induct_tac "x" [] 1); |
|
515 |
qed"Conc_assoc"; |
|
516 |
||
517 |
goal thy "s@@ nil = s"; |
|
518 |
by (res_inst_tac[("x","s")] seq.ind 1); |
|
519 |
by (Simp_tac 1); |
|
520 |
by (Simp_tac 1); |
|
521 |
by (Simp_tac 1); |
|
522 |
by (Asm_full_simp_tac 1); |
|
523 |
qed"nilConc"; |
|
524 |
||
525 |
Addsimps [nilConc]; |
|
526 |
||
3361 | 527 |
(* FIX: should be same as nil_is_Conc2 when all nils are turned to right side !! *) |
528 |
goal thy "(nil = x @@ y) = ((x::'a Seq)= nil & y = nil)"; |
|
529 |
by (Seq_case_simp_tac "x" 1); |
|
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4098
diff
changeset
|
530 |
by Auto_tac; |
3361 | 531 |
qed"nil_is_Conc"; |
532 |
||
533 |
goal thy "(x @@ y = nil) = ((x::'a Seq)= nil & y = nil)"; |
|
534 |
by (Seq_case_simp_tac "x" 1); |
|
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4098
diff
changeset
|
535 |
by Auto_tac; |
3361 | 536 |
qed"nil_is_Conc2"; |
537 |
||
3275 | 538 |
|
3071 | 539 |
(* ------------------------------------------------------------------------------------ *) |
540 |
||
541 |
section "Last"; |
|
542 |
||
3842 | 543 |
goal thy "!! s. Finite s ==> s~=nil --> Last`s~=UU"; |
3071 | 544 |
by (Seq_Finite_induct_tac 1); |
545 |
qed"Finite_Last1"; |
|
546 |
||
547 |
goal thy "!! s. Finite s ==> Last`s=UU --> s=nil"; |
|
548 |
by (Seq_Finite_induct_tac 1); |
|
549 |
by (fast_tac HOL_cs 1); |
|
550 |
qed"Finite_Last2"; |
|
551 |
||
552 |
||
553 |
(* ------------------------------------------------------------------------------------ *) |
|
554 |
||
555 |
||
556 |
section "Filter, Conc"; |
|
557 |
||
558 |
||
559 |
goal thy "Filter P`(Filter Q`s) = Filter (%x. P x & Q x)`s"; |
|
560 |
by (Seq_induct_tac "s" [Filter_def] 1); |
|
561 |
qed"FilterPQ"; |
|
562 |
||
563 |
goal thy "Filter P`(x @@ y) = (Filter P`x @@ Filter P`y)"; |
|
4098 | 564 |
by (simp_tac (simpset() addsimps [Filter_def,sfiltersconc]) 1); |
3071 | 565 |
qed"FilterConc"; |
566 |
||
567 |
(* ------------------------------------------------------------------------------------ *) |
|
568 |
||
569 |
section "Map"; |
|
570 |
||
571 |
goal thy "Map f`(Map g`s) = Map (f o g)`s"; |
|
572 |
by (Seq_induct_tac "s" [] 1); |
|
573 |
qed"MapMap"; |
|
574 |
||
575 |
goal thy "Map f`(x@@y) = (Map f`x) @@ (Map f`y)"; |
|
576 |
by (Seq_induct_tac "x" [] 1); |
|
577 |
qed"MapConc"; |
|
578 |
||
579 |
goal thy "Filter P`(Map f`x) = Map f`(Filter (P o f)`x)"; |
|
580 |
by (Seq_induct_tac "x" [] 1); |
|
581 |
qed"MapFilter"; |
|
582 |
||
3275 | 583 |
goal thy "nil = (Map f`s) --> s= nil"; |
584 |
by (Seq_case_simp_tac "s" 1); |
|
585 |
qed"nilMap"; |
|
586 |
||
3361 | 587 |
|
588 |
goal thy "Forall P (Map f`s) = Forall (P o f) s"; |
|
3275 | 589 |
by (Seq_induct_tac "s" [Forall_def,sforall_def] 1); |
3361 | 590 |
qed"ForallMap"; |
3275 | 591 |
|
592 |
||
593 |
||
3071 | 594 |
|
595 |
(* ------------------------------------------------------------------------------------ *) |
|
596 |
||
3275 | 597 |
section "Forall"; |
3071 | 598 |
|
599 |
||
600 |
goal thy "Forall P ys & (! x. P x --> Q x) \ |
|
601 |
\ --> Forall Q ys"; |
|
602 |
by (Seq_induct_tac "ys" [Forall_def,sforall_def] 1); |
|
603 |
qed"ForallPForallQ1"; |
|
604 |
||
605 |
bind_thm ("ForallPForallQ",impI RSN (2,allI RSN (2,conjI RS (ForallPForallQ1 RS mp)))); |
|
606 |
||
607 |
goal thy "(Forall P x & Forall P y) --> Forall P (x @@ y)"; |
|
608 |
by (Seq_induct_tac "x" [Forall_def,sforall_def] 1); |
|
609 |
qed"Forall_Conc_impl"; |
|
610 |
||
611 |
goal thy "!! x. Finite x ==> Forall P (x @@ y) = (Forall P x & Forall P y)"; |
|
612 |
by (Seq_Finite_induct_tac 1); |
|
613 |
qed"Forall_Conc"; |
|
614 |
||
3275 | 615 |
Addsimps [Forall_Conc]; |
616 |
||
617 |
goal thy "Forall P s --> Forall P (TL`s)"; |
|
618 |
by (Seq_induct_tac "s" [Forall_def,sforall_def] 1); |
|
619 |
qed"ForallTL1"; |
|
620 |
||
621 |
bind_thm ("ForallTL",ForallTL1 RS mp); |
|
622 |
||
623 |
goal thy "Forall P s --> Forall P (Dropwhile Q`s)"; |
|
624 |
by (Seq_induct_tac "s" [Forall_def,sforall_def] 1); |
|
625 |
qed"ForallDropwhile1"; |
|
626 |
||
627 |
bind_thm ("ForallDropwhile",ForallDropwhile1 RS mp); |
|
628 |
||
629 |
||
630 |
(* only admissible in t, not if done in s *) |
|
631 |
||
632 |
goal thy "! s. Forall P s --> t<<s --> Forall P t"; |
|
633 |
by (Seq_induct_tac "t" [Forall_def,sforall_def] 1); |
|
634 |
by (strip_tac 1); |
|
635 |
by (Seq_case_simp_tac "sa" 1); |
|
636 |
by (Asm_full_simp_tac 1); |
|
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4098
diff
changeset
|
637 |
by Auto_tac; |
3275 | 638 |
qed"Forall_prefix"; |
4681 | 639 |
|
3275 | 640 |
bind_thm ("Forall_prefixclosed",Forall_prefix RS spec RS mp RS mp); |
641 |
||
642 |
||
643 |
goal thy "!! h. [| Finite h; Forall P s; s= h @@ t |] ==> Forall P t"; |
|
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4098
diff
changeset
|
644 |
by Auto_tac; |
3275 | 645 |
qed"Forall_postfixclosed"; |
646 |
||
647 |
||
648 |
goal thy "((! x. P x --> (Q x = R x)) & Forall P tr) --> Filter Q`tr = Filter R`tr"; |
|
649 |
by (Seq_induct_tac "tr" [Forall_def,sforall_def] 1); |
|
650 |
qed"ForallPFilterQR1"; |
|
651 |
||
652 |
bind_thm("ForallPFilterQR",allI RS (conjI RS (ForallPFilterQR1 RS mp))); |
|
653 |
||
3071 | 654 |
|
655 |
(* ------------------------------------------------------------------------------------- *) |
|
656 |
||
657 |
section "Forall, Filter"; |
|
658 |
||
659 |
||
660 |
goal thy "Forall P (Filter P`x)"; |
|
4098 | 661 |
by (simp_tac (simpset() addsimps [Filter_def,Forall_def,forallPsfilterP]) 1); |
3071 | 662 |
qed"ForallPFilterP"; |
663 |
||
3275 | 664 |
(* holds also in other direction, then equal to forallPfilterP *) |
3071 | 665 |
goal thy "Forall P x --> Filter P`x = x"; |
666 |
by (Seq_induct_tac "x" [Forall_def,sforall_def,Filter_def] 1); |
|
667 |
qed"ForallPFilterPid1"; |
|
668 |
||
4034 | 669 |
bind_thm("ForallPFilterPid",ForallPFilterPid1 RS mp); |
3071 | 670 |
|
671 |
||
3275 | 672 |
(* holds also in other direction *) |
673 |
goal thy "!! ys . Finite ys ==> \ |
|
674 |
\ Forall (%x. ~P x) ys --> Filter P`ys = nil "; |
|
675 |
by (Seq_Finite_induct_tac 1); |
|
3071 | 676 |
qed"ForallnPFilterPnil1"; |
677 |
||
3275 | 678 |
bind_thm ("ForallnPFilterPnil",ForallnPFilterPnil1 RS mp); |
3071 | 679 |
|
680 |
||
3275 | 681 |
(* holds also in other direction *) |
3071 | 682 |
goal thy "!! P. ~Finite ys & Forall (%x. ~P x) ys \ |
683 |
\ --> Filter P`ys = UU "; |
|
3361 | 684 |
by (Seq_induct_tac "ys" [Forall_def,sforall_def] 1); |
3071 | 685 |
qed"ForallnPFilterPUU1"; |
686 |
||
3275 | 687 |
bind_thm ("ForallnPFilterPUU",conjI RS (ForallnPFilterPUU1 RS mp)); |
688 |
||
689 |
||
690 |
(* inverse of ForallnPFilterPnil *) |
|
691 |
||
692 |
goal thy "!! ys . Filter P`ys = nil --> \ |
|
693 |
\ (Forall (%x. ~P x) ys & Finite ys)"; |
|
694 |
by (res_inst_tac[("x","ys")] Seq_induct 1); |
|
695 |
(* adm *) |
|
3361 | 696 |
(* FIX: not admissible, search other proof!! *) |
3457 | 697 |
by (rtac adm_all 1); |
3275 | 698 |
(* base cases *) |
699 |
by (Simp_tac 1); |
|
700 |
by (Simp_tac 1); |
|
701 |
(* main case *) |
|
4098 | 702 |
by (asm_full_simp_tac (simpset() setloop split_tac [expand_if] ) 1); |
3275 | 703 |
qed"FilternPnilForallP1"; |
704 |
||
705 |
bind_thm ("FilternPnilForallP",FilternPnilForallP1 RS mp); |
|
706 |
||
3361 | 707 |
(* inverse of ForallnPFilterPUU. proved by 2 lemmas because of adm problems *) |
708 |
||
709 |
goal thy "!! ys. Finite ys ==> Filter P`ys ~= UU"; |
|
710 |
by (Seq_Finite_induct_tac 1); |
|
711 |
qed"FilterUU_nFinite_lemma1"; |
|
3275 | 712 |
|
3361 | 713 |
goal thy "~ Forall (%x. ~P x) ys --> Filter P`ys ~= UU"; |
714 |
by (Seq_induct_tac "ys" [Forall_def,sforall_def] 1); |
|
715 |
qed"FilterUU_nFinite_lemma2"; |
|
716 |
||
717 |
goal thy "!! P. Filter P`ys = UU ==> \ |
|
3275 | 718 |
\ (Forall (%x. ~P x) ys & ~Finite ys)"; |
3361 | 719 |
by (rtac conjI 1); |
720 |
by (cut_inst_tac [] (FilterUU_nFinite_lemma2 RS mp COMP rev_contrapos) 1); |
|
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4098
diff
changeset
|
721 |
by Auto_tac; |
4098 | 722 |
by (blast_tac (claset() addSDs [FilterUU_nFinite_lemma1]) 1); |
3361 | 723 |
qed"FilternPUUForallP"; |
3071 | 724 |
|
725 |
||
726 |
goal thy "!! Q P.[| Forall Q ys; Finite ys; !!x. Q x ==> ~P x|] \ |
|
727 |
\ ==> Filter P`ys = nil"; |
|
3457 | 728 |
by (etac ForallnPFilterPnil 1); |
729 |
by (etac ForallPForallQ 1); |
|
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4098
diff
changeset
|
730 |
by Auto_tac; |
3071 | 731 |
qed"ForallQFilterPnil"; |
732 |
||
733 |
goal thy "!! Q P. [| ~Finite ys; Forall Q ys; !!x. Q x ==> ~P x|] \ |
|
734 |
\ ==> Filter P`ys = UU "; |
|
3457 | 735 |
by (etac ForallnPFilterPUU 1); |
736 |
by (etac ForallPForallQ 1); |
|
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4098
diff
changeset
|
737 |
by Auto_tac; |
3071 | 738 |
qed"ForallQFilterPUU"; |
739 |
||
740 |
||
741 |
||
742 |
(* ------------------------------------------------------------------------------------- *) |
|
743 |
||
744 |
section "Takewhile, Forall, Filter"; |
|
745 |
||
746 |
||
747 |
goal thy "Forall P (Takewhile P`x)"; |
|
4098 | 748 |
by (simp_tac (simpset() addsimps [Forall_def,Takewhile_def,sforallPstakewhileP]) 1); |
3071 | 749 |
qed"ForallPTakewhileP"; |
750 |
||
751 |
||
752 |
goal thy"!! P. [| !!x. Q x==> P x |] ==> Forall P (Takewhile Q`x)"; |
|
3457 | 753 |
by (rtac ForallPForallQ 1); |
754 |
by (rtac ForallPTakewhileP 1); |
|
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4098
diff
changeset
|
755 |
by Auto_tac; |
3071 | 756 |
qed"ForallPTakewhileQ"; |
757 |
||
758 |
||
759 |
goal thy "!! Q P.[| Finite (Takewhile Q`ys); !!x. Q x ==> ~P x |] \ |
|
760 |
\ ==> Filter P`(Takewhile Q`ys) = nil"; |
|
3457 | 761 |
by (etac ForallnPFilterPnil 1); |
762 |
by (rtac ForallPForallQ 1); |
|
763 |
by (rtac ForallPTakewhileP 1); |
|
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4098
diff
changeset
|
764 |
by Auto_tac; |
3071 | 765 |
qed"FilterPTakewhileQnil"; |
766 |
||
767 |
goal thy "!! Q P. [| !!x. Q x ==> P x |] ==> \ |
|
768 |
\ Filter P`(Takewhile Q`ys) = (Takewhile Q`ys)"; |
|
3457 | 769 |
by (rtac ForallPFilterPid 1); |
770 |
by (rtac ForallPForallQ 1); |
|
771 |
by (rtac ForallPTakewhileP 1); |
|
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4098
diff
changeset
|
772 |
by Auto_tac; |
3071 | 773 |
qed"FilterPTakewhileQid"; |
774 |
||
775 |
Addsimps [ForallPTakewhileP,ForallPTakewhileQ, |
|
776 |
FilterPTakewhileQnil,FilterPTakewhileQid]; |
|
777 |
||
3275 | 778 |
goal thy "Takewhile P`(Takewhile P`s) = Takewhile P`s"; |
779 |
by (Seq_induct_tac "s" [Forall_def,sforall_def] 1); |
|
780 |
qed"Takewhile_idempotent"; |
|
3071 | 781 |
|
3842 | 782 |
goal thy "Forall P s --> Takewhile (%x. Q x | (~P x))`s = Takewhile Q`s"; |
3275 | 783 |
by (Seq_induct_tac "s" [Forall_def,sforall_def] 1); |
784 |
qed"ForallPTakewhileQnP"; |
|
785 |
||
3842 | 786 |
goal thy "Forall P s --> Dropwhile (%x. Q x | (~P x))`s = Dropwhile Q`s"; |
3275 | 787 |
by (Seq_induct_tac "s" [Forall_def,sforall_def] 1); |
788 |
qed"ForallPDropwhileQnP"; |
|
789 |
||
790 |
Addsimps [ForallPTakewhileQnP RS mp, ForallPDropwhileQnP RS mp]; |
|
791 |
||
792 |
||
793 |
goal thy "Forall P s --> Takewhile P`(s @@ t) = s @@ (Takewhile P`t)"; |
|
794 |
by (Seq_induct_tac "s" [Forall_def,sforall_def] 1); |
|
795 |
qed"TakewhileConc1"; |
|
796 |
||
797 |
bind_thm("TakewhileConc",TakewhileConc1 RS mp); |
|
798 |
||
3842 | 799 |
goal thy "!! s. Finite s ==> Forall P s --> Dropwhile P`(s @@ t) = Dropwhile P`t"; |
3275 | 800 |
by (Seq_Finite_induct_tac 1); |
801 |
qed"DropwhileConc1"; |
|
802 |
||
803 |
bind_thm("DropwhileConc",DropwhileConc1 RS mp); |
|
3071 | 804 |
|
805 |
||
806 |
||
807 |
(* ----------------------------------------------------------------------------------- *) |
|
808 |
||
809 |
section "coinductive characterizations of Filter"; |
|
810 |
||
811 |
||
812 |
goal thy "HD`(Filter P`y) = Def x \ |
|
813 |
\ --> y = ((Takewhile (%x. ~P x)`y) @@ (x >> TL`(Dropwhile (%a.~P a)`y))) \ |
|
814 |
\ & Finite (Takewhile (%x. ~ P x)`y) & P x"; |
|
815 |
||
816 |
(* FIX: pay attention: is only admissible with chain-finite package to be added to |
|
3656 | 817 |
adm test and Finite f x admissibility *) |
3071 | 818 |
by (Seq_induct_tac "y" [] 1); |
3457 | 819 |
by (rtac adm_all 1); |
3071 | 820 |
by (Asm_full_simp_tac 1); |
821 |
by (case_tac "P a" 1); |
|
4681 | 822 |
by (Asm_full_simp_tac 1); |
823 |
by (Blast_tac 1); |
|
3071 | 824 |
(* ~ P a *) |
825 |
by (Asm_full_simp_tac 1); |
|
826 |
qed"divide_Seq_lemma"; |
|
827 |
||
828 |
goal thy "!! x. (x>>xs) << Filter P`y \ |
|
829 |
\ ==> y = ((Takewhile (%a. ~ P a)`y) @@ (x >> TL`(Dropwhile (%a.~P a)`y))) \ |
|
830 |
\ & Finite (Takewhile (%a. ~ P a)`y) & P x"; |
|
3457 | 831 |
by (rtac (divide_Seq_lemma RS mp) 1); |
3071 | 832 |
by (dres_inst_tac [("fo","HD"),("xa","x>>xs")] monofun_cfun_arg 1); |
833 |
by (Asm_full_simp_tac 1); |
|
834 |
qed"divide_Seq"; |
|
835 |
||
3656 | 836 |
|
3071 | 837 |
goal thy "~Forall P y --> (? x. HD`(Filter (%a. ~P a)`y) = Def x)"; |
3656 | 838 |
(* Pay attention: is only admissible with chain-finite package to be added to |
3071 | 839 |
adm test *) |
3656 | 840 |
by (Seq_induct_tac "y" [Forall_def,sforall_def] 1); |
3071 | 841 |
qed"nForall_HDFilter"; |
842 |
||
843 |
||
844 |
goal thy "!!y. ~Forall P y \ |
|
845 |
\ ==> ? x. y= (Takewhile P`y @@ (x >> TL`(Dropwhile P`y))) & \ |
|
846 |
\ Finite (Takewhile P`y) & (~ P x)"; |
|
3457 | 847 |
by (dtac (nForall_HDFilter RS mp) 1); |
3071 | 848 |
by (safe_tac set_cs); |
849 |
by (res_inst_tac [("x","x")] exI 1); |
|
850 |
by (cut_inst_tac [("P1","%x. ~ P x")] (divide_Seq_lemma RS mp) 1); |
|
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4098
diff
changeset
|
851 |
by Auto_tac; |
3071 | 852 |
qed"divide_Seq2"; |
853 |
||
854 |
||
855 |
goal thy "!! y. ~Forall P y \ |
|
856 |
\ ==> ? x bs rs. y= (bs @@ (x>>rs)) & Finite bs & Forall P bs & (~ P x)"; |
|
857 |
by (cut_inst_tac [] divide_Seq2 1); |
|
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4098
diff
changeset
|
858 |
(*Auto_tac no longer proves it*) |
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4098
diff
changeset
|
859 |
by (REPEAT (fast_tac (claset() addss (simpset())) 1)); |
3071 | 860 |
qed"divide_Seq3"; |
861 |
||
3275 | 862 |
Addsimps [FilterPQ,FilterConc,Conc_cong]; |
3071 | 863 |
|
864 |
||
865 |
(* ------------------------------------------------------------------------------------- *) |
|
866 |
||
867 |
||
868 |
section "take_lemma"; |
|
869 |
||
870 |
goal thy "(!n. seq_take n`x = seq_take n`x') = (x = x')"; |
|
871 |
by (rtac iffI 1); |
|
4042 | 872 |
by (resolve_tac seq.take_lemmas 1); |
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4098
diff
changeset
|
873 |
by Auto_tac; |
3071 | 874 |
qed"seq_take_lemma"; |
875 |
||
3275 | 876 |
goal thy |
877 |
" ! n. ((! k. k < n --> seq_take k`y1 = seq_take k`y2) \ |
|
878 |
\ --> seq_take n`(x @@ (t>>y1)) = seq_take n`(x @@ (t>>y2)))"; |
|
879 |
by (Seq_induct_tac "x" [] 1); |
|
880 |
by (strip_tac 1); |
|
881 |
by (res_inst_tac [("n","n")] natE 1); |
|
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4098
diff
changeset
|
882 |
by Auto_tac; |
3275 | 883 |
by (res_inst_tac [("n","n")] natE 1); |
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4098
diff
changeset
|
884 |
by Auto_tac; |
3275 | 885 |
qed"take_reduction1"; |
3071 | 886 |
|
887 |
||
3842 | 888 |
goal thy "!! n.[| x=y; s=t;!! k. k<n ==> seq_take k`y1 = seq_take k`y2|] \ |
3275 | 889 |
\ ==> seq_take n`(x @@ (s>>y1)) = seq_take n`(y @@ (t>>y2))"; |
3071 | 890 |
|
4098 | 891 |
by (auto_tac (claset() addSIs [take_reduction1 RS spec RS mp],simpset())); |
3071 | 892 |
qed"take_reduction"; |
3275 | 893 |
|
3361 | 894 |
(* ------------------------------------------------------------------ |
895 |
take-lemma and take_reduction for << instead of = |
|
896 |
------------------------------------------------------------------ *) |
|
897 |
||
898 |
goal thy |
|
899 |
" ! n. ((! k. k < n --> seq_take k`y1 << seq_take k`y2) \ |
|
900 |
\ --> seq_take n`(x @@ (t>>y1)) << seq_take n`(x @@ (t>>y2)))"; |
|
901 |
by (Seq_induct_tac "x" [] 1); |
|
902 |
by (strip_tac 1); |
|
903 |
by (res_inst_tac [("n","n")] natE 1); |
|
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4098
diff
changeset
|
904 |
by Auto_tac; |
3361 | 905 |
by (res_inst_tac [("n","n")] natE 1); |
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4098
diff
changeset
|
906 |
by Auto_tac; |
3361 | 907 |
qed"take_reduction_less1"; |
908 |
||
909 |
||
3842 | 910 |
goal thy "!! n.[| x=y; s=t;!! k. k<n ==> seq_take k`y1 << seq_take k`y2|] \ |
3361 | 911 |
\ ==> seq_take n`(x @@ (s>>y1)) << seq_take n`(y @@ (t>>y2))"; |
4098 | 912 |
by (auto_tac (claset() addSIs [take_reduction_less1 RS spec RS mp],simpset())); |
3361 | 913 |
qed"take_reduction_less"; |
914 |
||
915 |
||
916 |
val prems = goalw thy [seq.take_def] |
|
917 |
"(!! n. seq_take n`s1 << seq_take n`s2) ==> s1<<s2"; |
|
918 |
||
919 |
by (res_inst_tac [("t","s1")] (seq.reach RS subst) 1); |
|
920 |
by (res_inst_tac [("t","s2")] (seq.reach RS subst) 1); |
|
921 |
by (rtac (fix_def2 RS ssubst ) 1); |
|
3457 | 922 |
by (stac contlub_cfun_fun 1); |
3361 | 923 |
by (rtac is_chain_iterate 1); |
3457 | 924 |
by (stac contlub_cfun_fun 1); |
3361 | 925 |
by (rtac is_chain_iterate 1); |
926 |
by (rtac lub_mono 1); |
|
927 |
by (rtac (is_chain_iterate RS ch2ch_fappL) 1); |
|
928 |
by (rtac (is_chain_iterate RS ch2ch_fappL) 1); |
|
929 |
by (rtac allI 1); |
|
930 |
by (resolve_tac prems 1); |
|
931 |
qed"take_lemma_less1"; |
|
932 |
||
933 |
||
934 |
goal thy "(!n. seq_take n`x << seq_take n`x') = (x << x')"; |
|
935 |
by (rtac iffI 1); |
|
3457 | 936 |
by (rtac take_lemma_less1 1); |
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4098
diff
changeset
|
937 |
by Auto_tac; |
3457 | 938 |
by (etac monofun_cfun_arg 1); |
3361 | 939 |
qed"take_lemma_less"; |
940 |
||
941 |
(* ------------------------------------------------------------------ |
|
942 |
take-lemma proof principles |
|
943 |
------------------------------------------------------------------ *) |
|
3071 | 944 |
|
945 |
goal thy "!! Q. [|!! s. [| Forall Q s; A s |] ==> (f s) = (g s) ; \ |
|
946 |
\ !! s1 s2 y. [| Forall Q s1; Finite s1; ~ Q y; A (s1 @@ y>>s2)|] \ |
|
947 |
\ ==> (f (s1 @@ y>>s2)) = (g (s1 @@ y>>s2)) |] \ |
|
948 |
\ ==> A x --> (f x)=(g x)"; |
|
949 |
by (case_tac "Forall Q x" 1); |
|
4098 | 950 |
by (auto_tac (claset() addSDs [divide_Seq3],simpset())); |
3071 | 951 |
qed"take_lemma_principle1"; |
952 |
||
953 |
goal thy "!! Q. [|!! s. [| Forall Q s; A s |] ==> (f s) = (g s) ; \ |
|
954 |
\ !! s1 s2 y. [| Forall Q s1; Finite s1; ~ Q y; A (s1 @@ y>>s2)|] \ |
|
955 |
\ ==> ! n. seq_take n`(f (s1 @@ y>>s2)) \ |
|
956 |
\ = seq_take n`(g (s1 @@ y>>s2)) |] \ |
|
957 |
\ ==> A x --> (f x)=(g x)"; |
|
958 |
by (case_tac "Forall Q x" 1); |
|
4098 | 959 |
by (auto_tac (claset() addSDs [divide_Seq3],simpset())); |
4042 | 960 |
by (resolve_tac seq.take_lemmas 1); |
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4098
diff
changeset
|
961 |
by Auto_tac; |
3071 | 962 |
qed"take_lemma_principle2"; |
963 |
||
964 |
||
965 |
(* Note: in the following proofs the ordering of proof steps is very |
|
966 |
important, as otherwise either (Forall Q s1) would be in the IH as |
|
967 |
assumption (then rule useless) or it is not possible to strengthen |
|
968 |
the IH by doing a forall closure of the sequence t (then rule also useless). |
|
969 |
This is also the reason why the induction rule (less_induct or nat_induct) has to |
|
970 |
to be imbuilt into the rule, as induction has to be done early and the take lemma |
|
971 |
has to be used in the trivial direction afterwards for the (Forall Q x) case. *) |
|
972 |
||
973 |
goal thy |
|
974 |
"!! Q. [|!! s. [| Forall Q s; A s |] ==> (f s) = (g s) ; \ |
|
975 |
\ !! s1 s2 y n. [| ! t. A t --> seq_take n`(f t) = seq_take n`(g t);\ |
|
976 |
\ Forall Q s1; Finite s1; ~ Q y; A (s1 @@ y>>s2) |] \ |
|
977 |
\ ==> seq_take (Suc n)`(f (s1 @@ y>>s2)) \ |
|
978 |
\ = seq_take (Suc n)`(g (s1 @@ y>>s2)) |] \ |
|
979 |
\ ==> A x --> (f x)=(g x)"; |
|
3457 | 980 |
by (rtac impI 1); |
4042 | 981 |
by (resolve_tac seq.take_lemmas 1); |
3457 | 982 |
by (rtac mp 1); |
983 |
by (assume_tac 2); |
|
3071 | 984 |
by (res_inst_tac [("x","x")] spec 1); |
3457 | 985 |
by (rtac nat_induct 1); |
3071 | 986 |
by (Simp_tac 1); |
3457 | 987 |
by (rtac allI 1); |
3071 | 988 |
by (case_tac "Forall Q xa" 1); |
4098 | 989 |
by (SELECT_GOAL (auto_tac (claset() addSIs [seq_take_lemma RS iffD2 RS spec], |
990 |
simpset())) 1); |
|
991 |
by (auto_tac (claset() addSDs [divide_Seq3],simpset())); |
|
3071 | 992 |
qed"take_lemma_induct"; |
993 |
||
994 |
||
995 |
goal thy |
|
996 |
"!! Q. [|!! s. [| Forall Q s; A s |] ==> (f s) = (g s) ; \ |
|
997 |
\ !! s1 s2 y n. [| ! t m. m < n --> A t --> seq_take m`(f t) = seq_take m`(g t);\ |
|
998 |
\ Forall Q s1; Finite s1; ~ Q y; A (s1 @@ y>>s2) |] \ |
|
999 |
\ ==> seq_take n`(f (s1 @@ y>>s2)) \ |
|
1000 |
\ = seq_take n`(g (s1 @@ y>>s2)) |] \ |
|
1001 |
\ ==> A x --> (f x)=(g x)"; |
|
3457 | 1002 |
by (rtac impI 1); |
4042 | 1003 |
by (resolve_tac seq.take_lemmas 1); |
3457 | 1004 |
by (rtac mp 1); |
1005 |
by (assume_tac 2); |
|
3071 | 1006 |
by (res_inst_tac [("x","x")] spec 1); |
3457 | 1007 |
by (rtac less_induct 1); |
1008 |
by (rtac allI 1); |
|
3071 | 1009 |
by (case_tac "Forall Q xa" 1); |
4098 | 1010 |
by (SELECT_GOAL (auto_tac (claset() addSIs [seq_take_lemma RS iffD2 RS spec], |
1011 |
simpset())) 1); |
|
1012 |
by (auto_tac (claset() addSDs [divide_Seq3],simpset())); |
|
3071 | 1013 |
qed"take_lemma_less_induct"; |
1014 |
||
3275 | 1015 |
|
1016 |
(* |
|
3521 | 1017 |
local |
1018 |
||
1019 |
fun qnt_tac i (tac, var) = tac THEN res_inst_tac [("x", var)] spec i; |
|
1020 |
||
1021 |
fun add_frees tsig = |
|
1022 |
let |
|
1023 |
fun add (Free (x, T), vars) = |
|
1024 |
if Type.of_sort tsig (T, HOLogic.termS) then x ins vars |
|
1025 |
else vars |
|
1026 |
| add (Abs (_, _, t), vars) = add (t, vars) |
|
1027 |
| add (t $ u, vars) = add (t, add (u, vars)) |
|
1028 |
| add (_, vars) = vars; |
|
1029 |
in add end; |
|
1030 |
||
1031 |
||
1032 |
in |
|
1033 |
||
1034 |
(*Generalizes over all free variables, with the named var outermost.*) |
|
1035 |
fun all_frees_tac x i thm = |
|
1036 |
let |
|
1037 |
val tsig = #tsig (Sign.rep_sg (#sign (rep_thm thm))); |
|
1038 |
val frees = add_frees tsig (nth_elem (i - 1, prems_of thm), [x]); |
|
1039 |
val frees' = sort (op >) (frees \ x) @ [x]; |
|
1040 |
in |
|
1041 |
foldl (qnt_tac i) (all_tac, frees') thm |
|
1042 |
end; |
|
1043 |
||
1044 |
end; |
|
1045 |
||
3275 | 1046 |
|
1047 |
goal thy |
|
1048 |
"!! Q. [|!! s h1 h2. [| Forall Q s; A s h1 h2|] ==> (f s h1 h2) = (g s h1 h2) ; \ |
|
1049 |
\ !! s1 s2 y n. [| ! t h1 h2 m. m < n --> (A t h1 h2) --> seq_take m`(f t h1 h2) = seq_take m`(g t h1 h2);\ |
|
1050 |
\ Forall Q s1; Finite s1; ~ Q y; A (s1 @@ y>>s2) h1 h2|] \ |
|
1051 |
\ ==> seq_take n`(f (s1 @@ y>>s2) h1 h2) \ |
|
1052 |
\ = seq_take n`(g (s1 @@ y>>s2) h1 h2) |] \ |
|
1053 |
\ ==> ! h1 h2. (A x h1 h2) --> (f x h1 h2)=(g x h1 h2)"; |
|
1054 |
by (strip_tac 1); |
|
4042 | 1055 |
by (resolve_tac seq.take_lemmas 1); |
3457 | 1056 |
by (rtac mp 1); |
1057 |
by (assume_tac 2); |
|
3275 | 1058 |
by (res_inst_tac [("x","h2a")] spec 1); |
1059 |
by (res_inst_tac [("x","h1a")] spec 1); |
|
1060 |
by (res_inst_tac [("x","x")] spec 1); |
|
3457 | 1061 |
by (rtac less_induct 1); |
1062 |
by (rtac allI 1); |
|
3275 | 1063 |
by (case_tac "Forall Q xa" 1); |
4098 | 1064 |
by (SELECT_GOAL (auto_tac (claset() addSIs [seq_take_lemma RS iffD2 RS spec], |
1065 |
simpset())) 1); |
|
1066 |
by (auto_tac (claset() addSDs [divide_Seq3],simpset())); |
|
3275 | 1067 |
qed"take_lemma_less_induct"; |
1068 |
||
1069 |
||
1070 |
||
1071 |
goal thy |
|
1072 |
"!! Q. [|!! s. Forall Q s ==> P ((f s) = (g s)) ; \ |
|
1073 |
\ !! s1 s2 y n. [| ! t m. m < n --> P (seq_take m`(f t) = seq_take m`(g t));\ |
|
1074 |
\ Forall Q s1; Finite s1; ~ Q y|] \ |
|
1075 |
\ ==> P (seq_take n`(f (s1 @@ y>>s2)) \ |
|
1076 |
\ = seq_take n`(g (s1 @@ y>>s2))) |] \ |
|
1077 |
\ ==> P ((f x)=(g x))"; |
|
1078 |
||
1079 |
by (res_inst_tac [("t","f x = g x"), |
|
1080 |
("s","!n. seq_take n`(f x) = seq_take n`(g x)")] subst 1); |
|
3457 | 1081 |
by (rtac seq_take_lemma 1); |
3275 | 1082 |
|
1083 |
wie ziehe ich n durch P, d.h. evtl. ns in P muessen umbenannt werden..... |
|
1084 |
||
1085 |
||
1086 |
FIX |
|
1087 |
||
3457 | 1088 |
by (rtac less_induct 1); |
1089 |
by (rtac allI 1); |
|
3275 | 1090 |
by (case_tac "Forall Q xa" 1); |
4098 | 1091 |
by (SELECT_GOAL (auto_tac (claset() addSIs [seq_take_lemma RS iffD2 RS spec], |
1092 |
simpset())) 1); |
|
1093 |
by (auto_tac (claset() addSDs [divide_Seq3],simpset())); |
|
3275 | 1094 |
qed"take_lemma_less_induct"; |
1095 |
||
1096 |
||
1097 |
*) |
|
1098 |
||
1099 |
||
3071 | 1100 |
goal thy |
1101 |
"!! Q. [| A UU ==> (f UU) = (g UU) ; \ |
|
1102 |
\ A nil ==> (f nil) = (g nil) ; \ |
|
1103 |
\ !! s y n. [| ! t. A t --> seq_take n`(f t) = seq_take n`(g t);\ |
|
1104 |
\ A (y>>s) |] \ |
|
1105 |
\ ==> seq_take (Suc n)`(f (y>>s)) \ |
|
1106 |
\ = seq_take (Suc n)`(g (y>>s)) |] \ |
|
1107 |
\ ==> A x --> (f x)=(g x)"; |
|
3457 | 1108 |
by (rtac impI 1); |
4042 | 1109 |
by (resolve_tac seq.take_lemmas 1); |
3457 | 1110 |
by (rtac mp 1); |
1111 |
by (assume_tac 2); |
|
3071 | 1112 |
by (res_inst_tac [("x","x")] spec 1); |
3457 | 1113 |
by (rtac nat_induct 1); |
3071 | 1114 |
by (Simp_tac 1); |
3457 | 1115 |
by (rtac allI 1); |
3071 | 1116 |
by (Seq_case_simp_tac "xa" 1); |
1117 |
qed"take_lemma_in_eq_out"; |
|
1118 |
||
1119 |
||
1120 |
(* ------------------------------------------------------------------------------------ *) |
|
1121 |
||
1122 |
section "alternative take_lemma proofs"; |
|
1123 |
||
1124 |
||
1125 |
(* --------------------------------------------------------------- *) |
|
1126 |
(* Alternative Proof of FilterPQ *) |
|
1127 |
(* --------------------------------------------------------------- *) |
|
1128 |
||
1129 |
Delsimps [FilterPQ]; |
|
1130 |
||
1131 |
||
1132 |
(* In general: How to do this case without the same adm problems |
|
1133 |
as for the entire proof ? *) |
|
1134 |
goal thy "Forall (%x.~(P x & Q x)) s \ |
|
1135 |
\ --> Filter P`(Filter Q`s) =\ |
|
1136 |
\ Filter (%x. P x & Q x)`s"; |
|
1137 |
||
1138 |
by (Seq_induct_tac "s" [Forall_def,sforall_def] 1); |
|
1139 |
qed"Filter_lemma1"; |
|
1140 |
||
1141 |
goal thy "!! s. Finite s ==> \ |
|
1142 |
\ (Forall (%x. (~P x) | (~ Q x)) s \ |
|
1143 |
\ --> Filter P`(Filter Q`s) = nil)"; |
|
1144 |
by (Seq_Finite_induct_tac 1); |
|
1145 |
qed"Filter_lemma2"; |
|
1146 |
||
1147 |
goal thy "!! s. Finite s ==> \ |
|
1148 |
\ Forall (%x. (~P x) | (~ Q x)) s \ |
|
3842 | 1149 |
\ --> Filter (%x. P x & Q x)`s = nil"; |
3071 | 1150 |
by (Seq_Finite_induct_tac 1); |
1151 |
qed"Filter_lemma3"; |
|
1152 |
||
1153 |
||
1154 |
goal thy "Filter P`(Filter Q`s) = Filter (%x. P x & Q x)`s"; |
|
3842 | 1155 |
by (res_inst_tac [("A1","%x. True") |
3275 | 1156 |
,("Q1","%x.~(P x & Q x)"),("x1","s")] |
3071 | 1157 |
(take_lemma_induct RS mp) 1); |
3842 | 1158 |
(* FIX: better support for A = %x. True *) |
3071 | 1159 |
by (Fast_tac 3); |
4098 | 1160 |
by (asm_full_simp_tac (simpset() addsimps [Filter_lemma1]) 1); |
1161 |
by (asm_full_simp_tac (simpset() addsimps [Filter_lemma2,Filter_lemma3] |
|
3071 | 1162 |
setloop split_tac [expand_if]) 1); |
1163 |
qed"FilterPQ_takelemma"; |
|
1164 |
||
1165 |
Addsimps [FilterPQ]; |
|
1166 |
||
1167 |
||
1168 |
(* --------------------------------------------------------------- *) |
|
1169 |
(* Alternative Proof of MapConc *) |
|
1170 |
(* --------------------------------------------------------------- *) |
|
1171 |
||
3275 | 1172 |
|
3071 | 1173 |
|
1174 |
goal thy "Map f`(x@@y) = (Map f`x) @@ (Map f`y)"; |
|
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4098
diff
changeset
|
1175 |
by (res_inst_tac [("A1","%x. True"), ("x1","x")] |
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4098
diff
changeset
|
1176 |
(take_lemma_in_eq_out RS mp) 1); |
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4098
diff
changeset
|
1177 |
by Auto_tac; |
3071 | 1178 |
qed"MapConc_takelemma"; |
1179 |
||
1180 |