src/HOL/Hilbert_Choice.thy
changeset 65952 dec96cb3fbe0
parent 65815 416aa3b00cbe
child 65954 431024edc9cf
equal deleted inserted replaced
65951:32b3feb6f965 65952:dec96cb3fbe0
   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 
   525 
   526 subsection \<open>Least value operator\<close>
       
   527 
       
   528 definition LeastM :: "('a \<Rightarrow> 'b::ord) \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> 'a"
       
   529   where "LeastM m P \<equiv> (SOME x. P x \<and> (\<forall>y. P y \<longrightarrow> m x \<le> m y))"
       
   530 
       
   531 syntax
       
   532   "_LeastM" :: "pttrn \<Rightarrow> ('a \<Rightarrow> 'b::ord) \<Rightarrow> bool \<Rightarrow> 'a"  ("LEAST _ WRT _. _" [0, 4, 10] 10)
       
   533 translations
       
   534   "LEAST x WRT m. P" \<rightleftharpoons> "CONST LeastM m (\<lambda>x. P)"
       
   535 
       
   536 lemma LeastMI2:
       
   537   "P x \<Longrightarrow>
       
   538     (\<And>y. P y \<Longrightarrow> m x \<le> m y) \<Longrightarrow>
       
   539     (\<And>x. P x \<Longrightarrow> \<forall>y. P y \<longrightarrow> m x \<le> m y \<Longrightarrow> Q x) \<Longrightarrow>
       
   540     Q (LeastM m P)"
       
   541   apply (simp add: LeastM_def)
       
   542   apply (rule someI2_ex)
       
   543    apply blast
       
   544   apply blast
       
   545   done
       
   546 
       
   547 lemma LeastM_equality: "P k \<Longrightarrow> (\<And>x. P x \<Longrightarrow> m k \<le> m x) \<Longrightarrow> m (LEAST x WRT m. P x) = m k"
       
   548   for m :: "_ \<Rightarrow> 'a::order"
       
   549   apply (rule LeastMI2)
       
   550     apply assumption
       
   551    apply blast
       
   552   apply (blast intro!: order_antisym)
       
   553   done
       
   554 
       
   555 lemma wf_linord_ex_has_least:
       
   556   "wf r \<Longrightarrow> \<forall>x y. (x, y) \<in> r\<^sup>+ \<longleftrightarrow> (y, x) \<notin> r\<^sup>* \<Longrightarrow> P k \<Longrightarrow> \<exists>x. P x \<and> (\<forall>y. P y \<longrightarrow> (m x, m y) \<in> r\<^sup>*)"
       
   557   apply (drule wf_trancl [THEN wf_eq_minimal [THEN iffD1]])
       
   558   apply (drule_tac x = "m ` Collect P" in spec)
       
   559   apply force
       
   560   done
       
   561 
       
   562 lemma ex_has_least_nat: "P k \<Longrightarrow> \<exists>x. P x \<and> (\<forall>y. P y \<longrightarrow> m x \<le> m y)"
       
   563   for m :: "'a \<Rightarrow> nat"
       
   564   apply (simp only: pred_nat_trancl_eq_le [symmetric])
       
   565   apply (rule wf_pred_nat [THEN wf_linord_ex_has_least])
       
   566    apply (simp add: less_eq linorder_not_le pred_nat_trancl_eq_le)
       
   567   apply assumption
       
   568   done
       
   569 
       
   570 lemma LeastM_nat_lemma: "P k \<Longrightarrow> P (LeastM m P) \<and> (\<forall>y. P y \<longrightarrow> m (LeastM m P) \<le> m y)"
       
   571   for m :: "'a \<Rightarrow> nat"
       
   572   apply (simp add: LeastM_def)
       
   573   apply (rule someI_ex)
       
   574   apply (erule ex_has_least_nat)
       
   575   done
       
   576 
       
   577 lemmas LeastM_natI = LeastM_nat_lemma [THEN conjunct1]
       
   578 
       
   579 lemma LeastM_nat_le: "P x \<Longrightarrow> m (LeastM m P) \<le> m x"
       
   580   for m :: "'a \<Rightarrow> nat"
       
   581   by (rule LeastM_nat_lemma [THEN conjunct2, THEN spec, THEN mp])
       
   582 
       
   583 
       
   584 subsection \<open>Greatest value operator\<close>
   526 subsection \<open>Greatest value operator\<close>
   585 
   527 
   586 definition GreatestM :: "('a \<Rightarrow> 'b::ord) \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> 'a"
   528 definition GreatestM :: "('a \<Rightarrow> 'b::ord) \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> 'a"
   587   where "GreatestM m P \<equiv> SOME x. P x \<and> (\<forall>y. P y \<longrightarrow> m y \<le> m x)"
   529   where "GreatestM m P \<equiv> SOME x. P x \<and> (\<forall>y. P y \<longrightarrow> m y \<le> m x)"
   588 
   530