57 Goal "b ~= UU ==> x << b && z = \ |
58 Goal "b ~= UU ==> x << b && z = \ |
58 \ (x = UU | (EX a y. x = a && y & a ~= UU & a << b & y << z))"; |
59 \ (x = UU | (EX a y. x = a && y & a ~= UU & a << b & y << z))"; |
59 by Safe_tac; |
60 by Safe_tac; |
60 by (stream_case_tac "x" 1); |
61 by (stream_case_tac "x" 1); |
61 by (safe_tac (claset() addSDs stream.inverts |
62 by (safe_tac (claset() addSDs stream.inverts |
62 addSIs [minimal, monofun_cfun, monofun_cfun_arg])); |
63 addSIs [monofun_cfun, monofun_cfun_arg])); |
63 by (Fast_tac 1); |
64 by (Fast_tac 1); |
64 qed "stream_prefix'"; |
65 qed "stream_prefix'"; |
65 |
66 |
66 Goal "[| a ~= UU; b ~= UU |] ==> (a && s = b && t) = (a = b & s = t)"; |
67 Goal "[| a ~= UU; b ~= UU |] ==> (a && s = b && t) = (a = b & s = t)"; |
67 by (best_tac (claset() addSEs stream.injects) 1); |
68 by (best_tac (claset() addSEs stream.injects) 1); |
68 qed "stream_inject_eq"; |
69 qed "stream_inject_eq"; |
|
70 Addsimps [stream_inject_eq]; |
69 |
71 |
70 |
72 |
71 (* ----------------------------------------------------------------------- *) |
73 (* ----------------------------------------------------------------------- *) |
72 (* theorems about stream_when *) |
74 (* theorems about stream_when *) |
73 (* ----------------------------------------------------------------------- *) |
75 (* ----------------------------------------------------------------------- *) |
74 |
76 |
75 section "stream_when"; |
77 section "stream_when"; |
76 |
78 |
77 Goal "stream_when$UU$s=UU"; |
79 Goal "stream_when$UU$s=UU"; |
78 by (stream_case_tac "s" 1); |
80 by (stream_case_tac "s" 1); |
79 by (ALLGOALS(asm_simp_tac (simpset() addsimps [strict_Rep_CFun1]))); |
81 by (ALLGOALS Asm_simp_tac); |
80 qed "stream_when_strictf"; |
82 qed "stream_when_strictf"; |
81 |
83 |
82 |
84 |
83 (* ----------------------------------------------------------------------- *) |
85 (* ----------------------------------------------------------------------- *) |
84 (* theorems about ft and rt *) |
86 (* theorems about ft and rt *) |
291 by (res_inst_tac [("x","ft$x")] exI 1); |
293 by (res_inst_tac [("x","ft$x")] exI 1); |
292 by (res_inst_tac [("x","rt$x")] exI 1); |
294 by (res_inst_tac [("x","rt$x")] exI 1); |
293 by (res_inst_tac [("x","rt$x'")] exI 1); |
295 by (res_inst_tac [("x","rt$x'")] exI 1); |
294 by (rtac conjI 1); |
296 by (rtac conjI 1); |
295 by (etac ft_defin 1); |
297 by (etac ft_defin 1); |
296 by (asm_simp_tac (simpset() addsimps stream.rews addsimps [surjectiv_scons]) 1); |
298 by (asm_simp_tac (simpset() addsimps [surjectiv_scons]) 1); |
297 by (eres_inst_tac [("s","ft$x"),("t","ft$x'")] subst 1); |
299 by (eres_inst_tac [("s","ft$x"),("t","ft$x'")] subst 1); |
298 by (simp_tac (simpset() addsimps stream.rews addsimps [surjectiv_scons]) 1); |
300 by (simp_tac (simpset() addsimps [surjectiv_scons]) 1); |
299 by (res_inst_tac [("x","ft$x'")] exI 1); |
301 by (res_inst_tac [("x","ft$x'")] exI 1); |
300 by (res_inst_tac [("x","rt$x")] exI 1); |
302 by (res_inst_tac [("x","rt$x")] exI 1); |
301 by (res_inst_tac [("x","rt$x'")] exI 1); |
303 by (res_inst_tac [("x","rt$x'")] exI 1); |
302 by (rtac conjI 1); |
304 by (rtac conjI 1); |
303 by (etac ft_defin 1); |
305 by (etac ft_defin 1); |
304 by (asm_simp_tac (simpset() addsimps stream.rews addsimps [surjectiv_scons]) 1); |
306 by (asm_simp_tac (simpset() addsimps [surjectiv_scons]) 1); |
305 by (res_inst_tac [("s","ft$x"),("t","ft$x'")] ssubst 1); |
307 by (res_inst_tac [("s","ft$x"),("t","ft$x'")] ssubst 1); |
306 by (etac sym 1); |
308 by (etac sym 1); |
307 by (simp_tac (simpset() addsimps stream.rews addsimps [surjectiv_scons]) 1); |
309 by (simp_tac (simpset() addsimps [surjectiv_scons]) 1); |
308 qed "stream_coind_lemma2"; |
310 qed "stream_coind_lemma2"; |
309 |
311 |
310 (* ----------------------------------------------------------------------- *) |
312 (* ----------------------------------------------------------------------- *) |
311 (* theorems about stream_finite *) |
313 (* theorems about stream_finite *) |
312 (* ----------------------------------------------------------------------- *) |
314 (* ----------------------------------------------------------------------- *) |
352 |
354 |
353 Goal "adm (%x. ~ stream_finite x)"; |
355 Goal "adm (%x. ~ stream_finite x)"; |
354 by (rtac admI2 1); |
356 by (rtac admI2 1); |
355 by (best_tac (claset() addIs [stream_finite_less, is_ub_thelub]) 1); |
357 by (best_tac (claset() addIs [stream_finite_less, is_ub_thelub]) 1); |
356 qed "adm_not_stream_finite"; |
358 qed "adm_not_stream_finite"; |
|
359 |
|
360 section "smap"; |
|
361 |
|
362 bind_thm ("smap_unfold", fix_prover2 thy smap_def |
|
363 "smap = (\\<Lambda>f s. case s of x && l => f\\<cdot>x && smap\\<cdot>f\\<cdot>l)"); |
|
364 |
|
365 Goal "smap\\<cdot>f\\<cdot>\\<bottom> = \\<bottom>"; |
|
366 by (stac smap_unfold 1); |
|
367 by (Simp_tac 1); |
|
368 qed "smap_empty"; |
|
369 |
|
370 Goal "x~=\\<bottom> ==> smap\\<cdot>f\\<cdot>(x&&xs) = (f\\<cdot>x)&&(smap\\<cdot>f\\<cdot>xs)"; |
|
371 by (rtac trans 1); |
|
372 by (stac smap_unfold 1); |
|
373 by (Asm_simp_tac 1); |
|
374 by (rtac refl 1); |
|
375 qed "smap_scons"; |
|
376 |
|
377 Addsimps [smap_empty, smap_scons]; |
|
378 |
|
379 (* ------------------------------------------------------------------------- *) |
|
380 |
|
381 section "slen"; |
|
382 |
|
383 Goalw [slen_def, stream.finite_def] "#\\<bottom> = 0"; |
|
384 by (Simp_tac 1); |
|
385 by (stac Least_equality 1); |
|
386 by Auto_tac; |
|
387 by (simp_tac(simpset() addsimps [Fin_0]) 1); |
|
388 qed "slen_empty"; |
|
389 |
|
390 Goalw [slen_def] "x ~= \\<bottom> ==> #(x&&xs) = iSuc (#xs)"; |
|
391 by (res_inst_tac [("Q1","stream_finite (x && xs)")] (split_if RS iffD2) 1); |
|
392 by Safe_tac; |
|
393 by (rtac (split_if RS iffD2) 2); |
|
394 by Safe_tac; |
|
395 by (fast_tac (claset() addIs [stream_finite_lemma1]) 2); |
|
396 by (rtac (iSuc_Infty RS sym) 2); |
|
397 by (rtac (split_if RS iffD2) 1); |
|
398 by (Simp_tac 1); |
|
399 by Safe_tac; |
|
400 by (eatac stream_finite_lemma2 1 2); |
|
401 by (rewtac stream.finite_def); |
|
402 by (Clarify_tac 1); |
|
403 by (eatac Least_Suc2 1 1); |
|
404 by (rtac not_sym 1); |
|
405 by Auto_tac; |
|
406 qed "slen_scons"; |
|
407 |
|
408 Addsimps [slen_empty, slen_scons]; |
|
409 |
|
410 Goal "#x < Fin 1 = (x = UU)"; |
|
411 by (stream_case_tac "x" 1); |
|
412 by (auto_tac (claset(), simpset() delsimps [iSuc_Fin] addsimps |
|
413 [Fin_0, iSuc_Fin RS sym,i0_iless_iSuc, iSuc_mono])); |
|
414 qed "slen_less_1_eq"; |
|
415 |
|
416 Goal "(#x = 0) = (x = \\<bottom>)"; |
|
417 by Auto_tac; |
|
418 by (stream_case_tac "x" 1); |
|
419 by (rotate_tac ~1 2); |
|
420 by Auto_tac; |
|
421 qed "slen_empty_eq"; |
|
422 |
|
423 Goal "Fin (Suc n) < #x = (? a y. x = a && y & a ~= \\<bottom> & Fin n < #y)"; |
|
424 by (stream_case_tac "x" 1); |
|
425 by (auto_tac (claset(), simpset() delsimps [iSuc_Fin] addsimps |
|
426 [iSuc_Fin RS sym, iSuc_mono])); |
|
427 by (dtac sym 1); |
|
428 by (rotate_tac 2 2); |
|
429 by Auto_tac; |
|
430 qed "slen_scons_eq"; |
|
431 |
|
432 |
|
433 Goal "#x = iSuc n --> (? a y. x = a&&y & a ~= \\<bottom> & #y = n)"; |
|
434 by (stream_case_tac "x" 1); |
|
435 by Auto_tac; |
|
436 qed_spec_mp "slen_iSuc"; |
|
437 |
|
438 |
|
439 Goal |
|
440 "#x < Fin (Suc (Suc n)) = (!a y. x ~= a && y | a = \\<bottom> | #y < Fin (Suc n))"; |
|
441 by (stac (iSuc_Fin RS sym) 1); |
|
442 by (stac (iSuc_Fin RS sym) 1); |
|
443 by (safe_tac HOL_cs); |
|
444 by (rotate_tac ~1 1); |
|
445 by (asm_full_simp_tac (HOL_ss addsimps [slen_scons, iSuc_mono]) 1); |
|
446 by (Asm_full_simp_tac 1); |
|
447 by (stream_case_tac "x" 1); |
|
448 by ( simp_tac (HOL_ss addsimps [slen_empty, i0_iless_iSuc]) 1); |
|
449 by (asm_simp_tac (HOL_ss addsimps [slen_scons, iSuc_mono]) 1); |
|
450 by (etac allE 1); |
|
451 by (etac allE 1); |
|
452 by (safe_tac HOL_cs); |
|
453 by ( contr_tac 2); |
|
454 by ( fast_tac HOL_cs 1); |
|
455 by (Asm_full_simp_tac 1); |
|
456 qed "slen_scons_eq_rev"; |
|
457 |
|
458 Goal "!x. Fin n < #x = (stream_take n\\<cdot>x ~= x)"; |
|
459 by (nat_ind_tac "n" 1); |
|
460 by (simp_tac(simpset() addsimps [slen_empty_eq, Fin_0]) 1); |
|
461 by (Fast_tac 1); |
|
462 by (rtac allI 1); |
|
463 by (asm_simp_tac (simpset() addsimps [slen_scons_eq]) 1); |
|
464 by (etac thin_rl 1); |
|
465 by (safe_tac HOL_cs); |
|
466 by (Asm_full_simp_tac 1); |
|
467 by (stream_case_tac "x" 1); |
|
468 by (rotate_tac ~1 2); |
|
469 by Auto_tac; |
|
470 qed_spec_mp "slen_take_eq"; |
|
471 |
|
472 Goalw [ile_def] "#x <= Fin n = (stream_take n\\<cdot>x = x)"; |
|
473 by (simp_tac (simpset() addsimps [slen_take_eq]) 1); |
|
474 qed "slen_take_eq_rev"; |
|
475 |
|
476 Goal "#x = Fin n ==> stream_take n\\<cdot>x = x"; |
|
477 by (asm_simp_tac (simpset() addsimps [slen_take_eq_rev RS sym]) 1); |
|
478 qed "slen_take_lemma1"; |
|
479 |
|
480 Goal "!x. ~stream_finite x --> #(stream_take i\\<cdot>x) = Fin i"; |
|
481 by (nat_ind_tac "i" 1); |
|
482 by (simp_tac(simpset() addsimps [Fin_0]) 1); |
|
483 by (rtac allI 1); |
|
484 by (stream_case_tac "x" 1); |
|
485 by (auto_tac (claset()addSIs [stream_finite_lemma1], simpset() delsimps [iSuc_Fin] addsimps [iSuc_Fin RS sym])); |
|
486 by (force_tac (claset(), simpset() addsimps [stream.finite_def]) 1); |
|
487 qed_spec_mp "slen_take_lemma2"; |
|
488 |
|
489 Goal "stream_finite x = (#x ~= Infty)"; |
|
490 by (rtac iffI 1); |
|
491 by (etac stream_finite_ind 1); |
|
492 by (Simp_tac 1); |
|
493 by (etac (slen_scons RS ssubst) 1); |
|
494 by (stac (iSuc_Infty RS sym) 1); |
|
495 by (etac contrapos_nn 1); |
|
496 by (etac (iSuc_inject RS iffD1) 1); |
|
497 by (case_tac "#x" 1); |
|
498 by (auto_tac (claset()addSDs [slen_take_lemma1], |
|
499 simpset() addsimps [stream.finite_def])); |
|
500 qed "slen_infinite"; |
|
501 |
|
502 Goal "s << t ==> #s <= #t"; |
|
503 by (case_tac "stream_finite t" 1); |
|
504 by (EVERY'[dtac (slen_infinite RS subst), dtac notnotD] 2); |
|
505 by (Asm_simp_tac 2); |
|
506 by (etac rev_mp 1); |
|
507 by (res_inst_tac [("x","s")] allE 1); |
|
508 by (atac 2); |
|
509 by (etac (stream_finite_ind) 1); |
|
510 by (Simp_tac 1); |
|
511 by (rtac allI 1); |
|
512 by (stream_case_tac "x" 1); |
|
513 by (asm_simp_tac (HOL_ss addsimps [slen_empty, i0_lb]) 1); |
|
514 by (asm_simp_tac (HOL_ss addsimps [slen_scons]) 1); |
|
515 by (fast_tac(claset() addSIs [iSuc_ile_mono RS iffD2] addSDs stream.inverts) 1); |
|
516 qed "slen_mono"; |
|
517 |
|
518 Goal "!(x::'a::flat stream) y. Fin n <= #x --> x << y --> \ |
|
519 \ stream_take n\\<cdot>x = stream_take n\\<cdot>y"; |
|
520 by (nat_ind_tac "n" 1); |
|
521 by ( simp_tac(simpset() addsimps [slen_empty_eq]) 1); |
|
522 by (strip_tac 1); |
|
523 by (stream_case_tac "x" 1); |
|
524 by (asm_full_simp_tac (HOL_ss addsimps [slen_empty, |
|
525 iSuc_Fin RS sym, not_iSuc_ilei0]) 1); |
|
526 by (fatac stream_prefix 1 1); |
|
527 by (safe_tac (claset() addSDs [stream_flat_prefix])); |
|
528 by (Simp_tac 1); |
|
529 by (rtac cfun_arg_cong 1); |
|
530 by (rotate_tac 3 1); |
|
531 by (asm_full_simp_tac (simpset() delsimps [iSuc_Fin] addsimps |
|
532 [iSuc_Fin RS sym, iSuc_ile_mono]) 1); |
|
533 qed_spec_mp "slen_take_lemma3"; |
|
534 |
|
535 Goal "stream_finite t ==> \ |
|
536 \!s. #(s::'a::flat stream) = #t & s << t --> s = t"; |
|
537 by (etac stream_finite_ind 1); |
|
538 by (fast_tac (claset() addDs [eq_UU_iff RS iffD2]) 1); |
|
539 by (Safe_tac); |
|
540 by (stream_case_tac "sa" 1); |
|
541 by (dtac sym 1); |
|
542 by (Asm_full_simp_tac 1); |
|
543 by (safe_tac (claset() addSDs [stream_flat_prefix])); |
|
544 by (rtac cfun_arg_cong 1); |
|
545 by (etac allE 1); |
|
546 by (etac mp 1); |
|
547 by (Asm_full_simp_tac 1); |
|
548 qed "slen_strict_mono_lemma"; |
|
549 |
|
550 Goal "[|stream_finite t; s ~= t; s << (t::'a::flat stream) |] ==> #s < #t"; |
|
551 by (rtac ilessI1 1); |
|
552 by (etac slen_mono 1); |
|
553 by (dtac slen_strict_mono_lemma 1); |
|
554 by (Fast_tac 1); |
|
555 qed "slen_strict_mono"; |
|
556 |
|
557 Goal "!x. Fin (i + j) <= #x --> Fin j <= #(iterate i rt x)"; |
|
558 by (nat_ind_tac "i" 1); |
|
559 by (Simp_tac 1); |
|
560 by (strip_tac 1); |
|
561 by (stream_case_tac "x" 1); |
|
562 by (asm_full_simp_tac (simpset() delsimps [iSuc_Fin] |
|
563 addsimps [iSuc_Fin RS sym]) 1); |
|
564 by (stac iterate_Suc2 1); |
|
565 by (rotate_tac 2 1); |
|
566 by (asm_full_simp_tac (simpset() delsimps [iSuc_Fin] |
|
567 addsimps [iSuc_Fin RS sym, iSuc_ile_mono]) 1); |
|
568 qed_spec_mp "slen_rt_mult"; |
|
569 |
|
570 |
|
571 (* ------------------------------------------------------------------------- *) |
|
572 |
|
573 section "sfilter"; |
|
574 |
|
575 bind_thm ("sfilter_unfold", fix_prover2 thy sfilter_def |
|
576 "sfilter = (\\<Lambda>p s. case s of x && xs => \ |
|
577 \ If p\\<cdot>x then x && sfilter\\<cdot>p\\<cdot>xs else sfilter\\<cdot>p\\<cdot>xs fi)"); |
|
578 |
|
579 Goal "sfilter\\<cdot>\\<bottom> = \\<bottom>"; |
|
580 by (rtac ext_cfun 1); |
|
581 by (stac sfilter_unfold 1); |
|
582 by (stream_case_tac "x" 1); |
|
583 by Auto_tac; |
|
584 qed "strict_sfilter"; |
|
585 |
|
586 Goal "sfilter\\<cdot>f\\<cdot>\\<bottom> = \\<bottom>"; |
|
587 by (stac sfilter_unfold 1); |
|
588 by (Simp_tac 1); |
|
589 qed "sfilter_empty"; |
|
590 |
|
591 Goal "x ~= \\<bottom> ==> sfilter\\<cdot>f\\<cdot>(x && xs) = \ |
|
592 \ If f\\<cdot>x then x && sfilter\\<cdot>f\\<cdot>xs else sfilter\\<cdot>f\\<cdot>xs fi"; |
|
593 by (rtac trans 1); |
|
594 by (stac sfilter_unfold 1); |
|
595 by (Asm_simp_tac 1); |
|
596 by (rtac refl 1); |
|
597 qed "sfilter_scons"; |
|
598 |