520 |
520 |
521 text \<open>A dynamically-scoped fact for TFL\<close> |
521 text \<open>A dynamically-scoped fact for TFL\<close> |
522 lemma tfl_some: "\<forall>P x. P x \<longrightarrow> P (Eps P)" |
522 lemma tfl_some: "\<forall>P x. P x \<longrightarrow> P (Eps P)" |
523 by (blast intro: someI) |
523 by (blast intro: someI) |
524 |
524 |
525 (* |
|
526 subsection \<open>Greatest value operator\<close> |
|
527 |
|
528 definition GreatestM :: "('a \<Rightarrow> 'b::ord) \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> 'a" |
|
529 where "GreatestM m P \<equiv> SOME x. P x \<and> (\<forall>y. P y \<longrightarrow> m y \<le> m x)" |
|
530 |
|
531 definition Greatest :: "('a::ord \<Rightarrow> bool) \<Rightarrow> 'a" (binder "GREATEST " 10) |
|
532 where "Greatest \<equiv> GreatestM (\<lambda>x. x)" |
|
533 |
|
534 syntax |
|
535 "_GreatestM" :: "pttrn \<Rightarrow> ('a \<Rightarrow> 'b::ord) \<Rightarrow> bool \<Rightarrow> 'a" ("GREATEST _ WRT _. _" [0, 4, 10] 10) |
|
536 translations |
|
537 "GREATEST x WRT m. P" \<rightleftharpoons> "CONST GreatestM m (\<lambda>x. P)" |
|
538 |
|
539 lemma GreatestMI2: |
|
540 "P x \<Longrightarrow> |
|
541 (\<And>y. P y \<Longrightarrow> m y \<le> m x) \<Longrightarrow> |
|
542 (\<And>x. P x \<Longrightarrow> \<forall>y. P y \<longrightarrow> m y \<le> m x \<Longrightarrow> Q x) \<Longrightarrow> |
|
543 Q (GreatestM m P)" |
|
544 apply (simp add: GreatestM_def) |
|
545 apply (rule someI2_ex) |
|
546 apply blast |
|
547 apply blast |
|
548 done |
|
549 |
|
550 lemma GreatestM_equality: "P k \<Longrightarrow> (\<And>x. P x \<Longrightarrow> m x \<le> m k) \<Longrightarrow> m (GREATEST x WRT m. P x) = m k" |
|
551 for m :: "_ \<Rightarrow> 'a::order" |
|
552 apply (rule GreatestMI2 [where m = m]) |
|
553 apply assumption |
|
554 apply blast |
|
555 apply (blast intro!: order_antisym) |
|
556 done |
|
557 |
|
558 lemma Greatest_equality: "P k \<Longrightarrow> (\<And>x. P x \<Longrightarrow> x \<le> k) \<Longrightarrow> (GREATEST x. P x) = k" |
|
559 for k :: "'a::order" |
|
560 apply (simp add: Greatest_def) |
|
561 apply (erule GreatestM_equality) |
|
562 apply blast |
|
563 done |
|
564 |
|
565 lemma ex_has_greatest_nat_lemma: |
|
566 "P k \<Longrightarrow> \<forall>x. P x \<longrightarrow> (\<exists>y. P y \<and> \<not> m y \<le> m x) \<Longrightarrow> \<exists>y. P y \<and> \<not> m y < m k + n" |
|
567 for m :: "'a \<Rightarrow> nat" |
|
568 by (induct n) (force simp: le_Suc_eq)+ |
|
569 |
|
570 lemma ex_has_greatest_nat: |
|
571 "P k \<Longrightarrow> \<forall>y. P y \<longrightarrow> m y < b \<Longrightarrow> \<exists>x. P x \<and> (\<forall>y. P y \<longrightarrow> m y \<le> m x)" |
|
572 for m :: "'a \<Rightarrow> nat" |
|
573 apply (rule ccontr) |
|
574 apply (cut_tac P = P and n = "b - m k" in ex_has_greatest_nat_lemma) |
|
575 apply (subgoal_tac [3] "m k \<le> b") |
|
576 apply auto |
|
577 done |
|
578 |
|
579 lemma GreatestM_nat_lemma: |
|
580 "P k \<Longrightarrow> \<forall>y. P y \<longrightarrow> m y < b \<Longrightarrow> P (GreatestM m P) \<and> (\<forall>y. P y \<longrightarrow> m y \<le> m (GreatestM m P))" |
|
581 for m :: "'a \<Rightarrow> nat" |
|
582 apply (simp add: GreatestM_def) |
|
583 apply (rule someI_ex) |
|
584 apply (erule ex_has_greatest_nat) |
|
585 apply assumption |
|
586 done |
|
587 |
|
588 lemmas GreatestM_natI = GreatestM_nat_lemma [THEN conjunct1] |
|
589 |
|
590 lemma GreatestM_nat_le: "P x \<Longrightarrow> \<forall>y. P y \<longrightarrow> m y < b \<Longrightarrow> m x \<le> m (GreatestM m P)" |
|
591 for m :: "'a \<Rightarrow> nat" |
|
592 by (blast dest: GreatestM_nat_lemma [THEN conjunct2, THEN spec, of P]) |
|
593 |
|
594 |
|
595 text \<open>\<^medskip> Specialization to \<open>GREATEST\<close>.\<close> |
|
596 |
|
597 lemma GreatestI: "P k \<Longrightarrow> \<forall>y. P y \<longrightarrow> y < b \<Longrightarrow> P (GREATEST x. P x)" |
|
598 for k :: nat |
|
599 unfolding Greatest_def by (rule GreatestM_natI) auto |
|
600 |
|
601 lemma Greatest_le: "P x \<Longrightarrow> \<forall>y. P y \<longrightarrow> y < b \<Longrightarrow> x \<le> (GREATEST x. P x)" |
|
602 for x :: nat |
|
603 unfolding Greatest_def by (rule GreatestM_nat_le) auto |
|
604 |
|
605 lemma GreatestI_ex: "\<exists>k::nat. P k \<Longrightarrow> \<forall>y. P y \<longrightarrow> y < b \<Longrightarrow> P (GREATEST x. P x)" |
|
606 apply (erule exE) |
|
607 apply (rule GreatestI) |
|
608 apply assumption+ |
|
609 done |
|
610 *) |
|
611 |
525 |
612 subsection \<open>An aside: bounded accessible part\<close> |
526 subsection \<open>An aside: bounded accessible part\<close> |
613 |
527 |
614 text \<open>Finite monotone eventually stable sequences\<close> |
528 text \<open>Finite monotone eventually stable sequences\<close> |
615 |
529 |