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