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