
paulson@11451: (*  Title:      HOL/Hilbert_Choice.thy
nipkow@32988:     Author:     Lawrence C Paulson, Tobias Nipkow
paulson@11451:     Copyright   2001  University of Cambridge
wenzelm@12023: *)
paulson@11451: 
paulson@14760: header {* Hilbert's Epsilon-Operator and the Axiom of Choice *}
paulson@11451: 
nipkow@15131: theory Hilbert_Choice
haftmann@29655: imports Nat Wellfounded Plain
haftmann@31723: uses ("Tools/meson.ML") ("Tools/choice_specification.ML")
nipkow@15131: begin
wenzelm@12298: 
wenzelm@12298: subsection {* Hilbert's epsilon *}
wenzelm@12298: 
haftmann@31454: axiomatization Eps :: "('a => bool) => 'a" where
wenzelm@22690:   someI: "P x ==> P (Eps P)"
paulson@11451: 
wenzelm@14872: syntax (epsilon)
wenzelm@14872:   "_Eps"        :: "[pttrn, bool] => 'a"    ("(3\<some>_./ _)" [0, 10] 10)
paulson@11451: syntax (HOL)
wenzelm@12298:   "_Eps"        :: "[pttrn, bool] => 'a"    ("(3@ _./ _)" [0, 10] 10)
paulson@11451: syntax
wenzelm@12298:   "_Eps"        :: "[pttrn, bool] => 'a"    ("(3SOME _./ _)" [0, 10] 10)
paulson@11451: translations
wenzelm@22690:   "SOME x. P" == "CONST Eps (%x. P)"
nipkow@13763: 
nipkow@13763: print_translation {*
nipkow@13763: (* to avoid eta-contraction of body *)
wenzelm@22690: [(@{const_syntax Eps}, fn [Abs abs] =>
nipkow@13763:      let val (x,t) = atomic_abs_tr' abs
nipkow@13763:      in Syntax.const "_Eps" $ x $ t end)]
nipkow@13763: *}
paulson@11451: 
nipkow@32988: definition inv_onto :: "'a set => ('a => 'b) => ('b => 'a)" where
nipkow@32988: "inv_onto A f == %x. SOME y. y : A & f y = x"
paulson@11454: 
nipkow@32988: abbreviation inv :: "('a => 'b) => ('b => 'a)" where
nipkow@32988: "inv == inv_onto UNIV"
paulson@14760: 
paulson@14760: 
paulson@14760: subsection {*Hilbert's Epsilon-operator*}
paulson@14760: 
paulson@14760: text{*Easier to apply than @{text someI} if the witness comes from an
paulson@14760: existential formula*}
paulson@14760: lemma someI_ex [elim?]: "\<exists>x. P x ==> P (SOME x. P x)"
paulson@14760: apply (erule exE)
paulson@14760: apply (erule someI)
paulson@14760: done
paulson@14760: 
paulson@14760: text{*Easier to apply than @{text someI} because the conclusion has only one
paulson@14760: occurrence of @{term P}.*}
paulson@14760: lemma someI2: "[| P a;  !!x. P x ==> Q x |] ==> Q (SOME x. P x)"
paulson@14760: by (blast intro: someI)
paulson@14760: 
paulson@14760: text{*Easier to apply than @{text someI2} if the witness comes from an
paulson@14760: existential formula*}
paulson@14760: lemma someI2_ex: "[| \<exists>a. P a; !!x. P x ==> Q x |] ==> Q (SOME x. P x)"
paulson@14760: by (blast intro: someI2)
paulson@14760: 
paulson@14760: lemma some_equality [intro]:
paulson@14760:      "[| P a;  !!x. P x ==> x=a |] ==> (SOME x. P x) = a"
paulson@14760: by (blast intro: someI2)
paulson@14760: 
paulson@14760: lemma some1_equality: "[| EX!x. P x; P a |] ==> (SOME x. P x) = a"
paulson@14760: by (blast intro: some_equality)
paulson@14760: 
paulson@14760: lemma some_eq_ex: "P (SOME x. P x) =  (\<exists>x. P x)"
paulson@14760: by (blast intro: someI)
paulson@14760: 
paulson@14760: lemma some_eq_trivial [simp]: "(SOME y. y=x) = x"
paulson@14760: apply (rule some_equality)
paulson@14760: apply (rule refl, assumption)
paulson@14760: done
paulson@14760: 
paulson@14760: lemma some_sym_eq_trivial [simp]: "(SOME y. x=y) = x"
paulson@14760: apply (rule some_equality)
paulson@14760: apply (rule refl)
paulson@14760: apply (erule sym)
paulson@14760: done
paulson@14760: 
paulson@14760: 
paulson@14760: subsection{*Axiom of Choice, Proved Using the Description Operator*}
paulson@14760: 
paulson@14760: text{*Used in @{text "Tools/meson.ML"}*}
paulson@14760: lemma choice: "\<forall>x. \<exists>y. Q x y ==> \<exists>f. \<forall>x. Q x (f x)"
paulson@14760: by (fast elim: someI)
paulson@14760: 
paulson@14760: lemma bchoice: "\<forall>x\<in>S. \<exists>y. Q x y ==> \<exists>f. \<forall>x\<in>S. Q x (f x)"
paulson@14760: by (fast elim: someI)
paulson@14760: 
paulson@14760: 
paulson@14760: subsection {*Function Inverse*}
paulson@14760: 
nipkow@32988: lemma inv_onto_into: "x : f ` A ==> inv_onto A f x : A"
nipkow@32988: apply (simp add: inv_onto_def)
nipkow@32988: apply (fast intro: someI2)
nipkow@32988: done
paulson@14760: 
nipkow@32988: lemma inv_id [simp]: "inv id = id"
nipkow@32988: by (simp add: inv_onto_def id_def)
paulson@14760: 
nipkow@32988: lemma inv_onto_f_f [simp]:
nipkow@32988:   "[| inj_on f A;  x : A |] ==> inv_onto A f (f x) = x"
nipkow@32988: apply (simp add: inv_onto_def inj_on_def)
nipkow@32988: apply (blast intro: someI2)
paulson@14760: done
paulson@14760: 
nipkow@32988: lemma inv_f_f: "inj f ==> inv f (f x) = x"
nipkow@32988: by (simp add: inv_onto_f_f)
nipkow@32988: 
nipkow@32988: lemma f_inv_onto_f: "y : f`A  ==> f (inv_onto A f y) = y"
nipkow@32988: apply (simp add: inv_onto_def)
nipkow@32988: apply (fast intro: someI2)
nipkow@32988: done
nipkow@32988: 
nipkow@32988: lemma inv_onto_f_eq: "[| inj_on f A; x : A; f x = y |] ==> inv_onto A f y = x"
nipkow@32988: apply (erule subst)
nipkow@32988: apply (fast intro: inv_onto_f_f)
nipkow@32988: done
nipkow@32988: 
nipkow@32988: lemma inv_f_eq: "[| inj f; f x = y |] ==> inv f y = x"
nipkow@32988: by (simp add:inv_onto_f_eq)
nipkow@32988: 
nipkow@32988: lemma inj_imp_inv_eq: "[| inj f; ALL x. f(g x) = x |] ==> inv f = g"
nipkow@32988: by (blast intro: ext inv_onto_f_eq)
paulson@14760: 
paulson@14760: text{*But is it useful?*}
paulson@14760: lemma inj_transfer:
paulson@14760:   assumes injf: "inj f" and minor: "!!y. y \<in> range(f) ==> P(inv f y)"
paulson@14760:   shows "P x"
paulson@14760: proof -
paulson@14760:   have "f x \<in> range f" by auto
paulson@14760:   hence "P(inv f (f x))" by (rule minor)
nipkow@32988:   thus "P x" by (simp add: inv_onto_f_f [OF injf])
paulson@14760: qed
paulson@11451: 
paulson@14760: lemma inj_iff: "(inj f) = (inv f o f = id)"
paulson@14760: apply (simp add: o_def expand_fun_eq)
nipkow@32988: apply (blast intro: inj_on_inverseI inv_onto_f_f)
paulson@14760: done
paulson@14760: 
nipkow@23433: lemma inv_o_cancel[simp]: "inj f ==> inv f o f = id"
nipkow@23433: by (simp add: inj_iff)
nipkow@23433: 
nipkow@23433: lemma o_inv_o_cancel[simp]: "inj f ==> g o inv f o f = g"
nipkow@23433: by (simp add: o_assoc[symmetric])
nipkow@23433: 
nipkow@32988: lemma inv_onto_image_cancel[simp]:
nipkow@32988:   "inj_on f A ==> S <= A ==> inv_onto A f ` f ` S = S"
nipkow@32988: by(fastsimp simp: image_def)
nipkow@32988: 
paulson@14760: lemma inj_imp_surj_inv: "inj f ==> surj (inv f)"
nipkow@32988: by (blast intro: surjI inv_onto_f_f)
paulson@14760: 
paulson@14760: lemma surj_f_inv_f: "surj f ==> f(inv f y) = y"
nipkow@32988: by (simp add: f_inv_onto_f surj_range)
paulson@14760: 
nipkow@32988: lemma inv_onto_injective:
nipkow@32988:   assumes eq: "inv_onto A f x = inv_onto A f y"
nipkow@32988:       and x: "x: f`A"
nipkow@32988:       and y: "y: f`A"
paulson@14760:   shows "x=y"
paulson@14760: proof -
nipkow@32988:   have "f (inv_onto A f x) = f (inv_onto A f y)" using eq by simp
nipkow@32988:   thus ?thesis by (simp add: f_inv_onto_f x y)
paulson@14760: qed
paulson@14760: 
nipkow@32988: lemma inj_on_inv_onto: "B <= f`A ==> inj_on (inv_onto A f) B"
nipkow@32988: by (blast intro: inj_onI dest: inv_onto_injective injD)
nipkow@32988: 
nipkow@32988: lemma bij_betw_inv_onto: "bij_betw f A B ==> bij_betw (inv_onto A f) B A"
nipkow@32988: by (auto simp add: bij_betw_def inj_on_inv_onto)
paulson@14760: 
paulson@14760: lemma surj_imp_inj_inv: "surj f ==> inj (inv f)"
nipkow@32988: by (simp add: inj_on_inv_onto surj_range)
paulson@14760: 
paulson@14760: lemma surj_iff: "(surj f) = (f o inv f = id)"
paulson@14760: apply (simp add: o_def expand_fun_eq)
paulson@14760: apply (blast intro: surjI surj_f_inv_f)
paulson@14760: done
paulson@14760: 
paulson@14760: lemma surj_imp_inv_eq: "[| surj f; \<forall>x. g(f x) = x |] ==> inv f = g"
paulson@14760: apply (rule ext)
paulson@14760: apply (drule_tac x = "inv f x" in spec)
paulson@14760: apply (simp add: surj_f_inv_f)
paulson@14760: done
paulson@14760: 
paulson@14760: lemma bij_imp_bij_inv: "bij f ==> bij (inv f)"
paulson@14760: by (simp add: bij_def inj_imp_surj_inv surj_imp_inj_inv)
wenzelm@12372: 
paulson@14760: lemma inv_equality: "[| !!x. g (f x) = x;  !!y. f (g y) = y |] ==> inv f = g"
paulson@14760: apply (rule ext)
nipkow@32988: apply (auto simp add: inv_onto_def)
paulson@14760: done
paulson@14760: 
paulson@14760: lemma inv_inv_eq: "bij f ==> inv (inv f) = f"
paulson@14760: apply (rule inv_equality)
paulson@14760: apply (auto simp add: bij_def surj_f_inv_f)
paulson@14760: done
paulson@14760: 
paulson@14760: (** bij(inv f) implies little about f.  Consider f::bool=>bool such that
paulson@14760:     f(True)=f(False)=True.  Then it's consistent with axiom someI that
paulson@14760:     inv f could be any function at all, including the identity function.
paulson@14760:     If inv f=id then inv f is a bijection, but inj f, surj(f) and
paulson@14760:     inv(inv f)=f all fail.
paulson@14760: **)
paulson@14760: 
nipkow@32988: lemma inv_onto_comp:
nipkow@32988:   "[| inj_on f (g ` A); inj_on g A; x : f ` g ` A |] ==>
nipkow@32988:   inv_onto A (f o g) x = (inv_onto A g o inv_onto (g ` A) f) x"
nipkow@32988: apply (rule inv_onto_f_eq)
nipkow@32988:   apply (fast intro: comp_inj_on)
nipkow@32988:  apply (simp add: inv_onto_into)
nipkow@32988: apply (simp add: f_inv_onto_f inv_onto_into)
nipkow@32988: done
nipkow@32988: 
paulson@14760: lemma o_inv_distrib: "[| bij f; bij g |] ==> inv (f o g) = inv g o inv f"
paulson@14760: apply (rule inv_equality)
paulson@14760: apply (auto simp add: bij_def surj_f_inv_f)
paulson@14760: done
paulson@14760: 
paulson@14760: lemma image_surj_f_inv_f: "surj f ==> f ` (inv f ` A) = A"
paulson@14760: by (simp add: image_eq_UN surj_f_inv_f)
paulson@14760: 
paulson@14760: lemma image_inv_f_f: "inj f ==> (inv f) ` (f ` A) = A"
paulson@14760: by (simp add: image_eq_UN)
paulson@14760: 
paulson@14760: lemma inv_image_comp: "inj f ==> inv f ` (f`X) = X"
paulson@14760: by (auto simp add: image_def)
paulson@14760: 
paulson@14760: lemma bij_image_Collect_eq: "bij f ==> f ` Collect P = {y. P (inv f y)}"
paulson@14760: apply auto
paulson@14760: apply (force simp add: bij_is_inj)
paulson@14760: apply (blast intro: bij_is_surj [THEN surj_f_inv_f, symmetric])
paulson@14760: done
paulson@14760: 
paulson@14760: lemma bij_vimage_eq_inv_image: "bij f ==> f -` A = inv f ` A" 
paulson@14760: apply (auto simp add: bij_is_surj [THEN surj_f_inv_f])
nipkow@32988: apply (blast intro: bij_is_inj [THEN inv_onto_f_f, symmetric])
paulson@14760: done
paulson@14760: 
haftmann@31380: lemma finite_fun_UNIVD1:
haftmann@31380:   assumes fin: "finite (UNIV :: ('a \<Rightarrow> 'b) set)"
haftmann@31380:   and card: "card (UNIV :: 'b set) \<noteq> Suc 0"
haftmann@31380:   shows "finite (UNIV :: 'a set)"
haftmann@31380: proof -
haftmann@31380:   from fin have finb: "finite (UNIV :: 'b set)" by (rule finite_fun_UNIVD2)
haftmann@31380:   with card have "card (UNIV :: 'b set) \<ge> Suc (Suc 0)"
haftmann@31380:     by (cases "card (UNIV :: 'b set)") (auto simp add: card_eq_0_iff)
haftmann@31380:   then obtain n where "card (UNIV :: 'b set) = Suc (Suc n)" "n = card (UNIV :: 'b set) - Suc (Suc 0)" by auto
haftmann@31380:   then obtain b1 b2 where b1b2: "(b1 :: 'b) \<noteq> (b2 :: 'b)" by (auto simp add: card_Suc_eq)
haftmann@31380:   from fin have "finite (range (\<lambda>f :: 'a \<Rightarrow> 'b. inv f b1))" by (rule finite_imageI)
haftmann@31380:   moreover have "UNIV = range (\<lambda>f :: 'a \<Rightarrow> 'b. inv f b1)"
haftmann@31380:   proof (rule UNIV_eq_I)
haftmann@31380:     fix x :: 'a
nipkow@32988:     from b1b2 have "x = inv (\<lambda>y. if y = x then b1 else b2) b1" by (simp add: inv_onto_def)
haftmann@31380:     thus "x \<in> range (\<lambda>f\<Colon>'a \<Rightarrow> 'b. inv f b1)" by blast
haftmann@31380:   qed
haftmann@31380:   ultimately show "finite (UNIV :: 'a set)" by simp
haftmann@31380: qed
paulson@14760: 
paulson@14760: 
paulson@14760: subsection {*Other Consequences of Hilbert's Epsilon*}
paulson@14760: 
paulson@14760: text {*Hilbert's Epsilon and the @{term split} Operator*}
paulson@14760: 
paulson@14760: text{*Looping simprule*}
paulson@14760: lemma split_paired_Eps: "(SOME x. P x) = (SOME (a,b). P(a,b))"
haftmann@26347:   by simp
paulson@14760: 
paulson@14760: lemma Eps_split: "Eps (split P) = (SOME xy. P (fst xy) (snd xy))"
haftmann@26347:   by (simp add: split_def)
paulson@14760: 
paulson@14760: lemma Eps_split_eq [simp]: "(@(x',y'). x = x' & y = y') = (x,y)"
haftmann@26347:   by blast
paulson@14760: 
paulson@14760: 
paulson@14760: text{*A relation is wellfounded iff it has no infinite descending chain*}
paulson@14760: lemma wf_iff_no_infinite_down_chain:
paulson@14760:   "wf r = (~(\<exists>f. \<forall>i. (f(Suc i),f i) \<in> r))"
paulson@14760: apply (simp only: wf_eq_minimal)
paulson@14760: apply (rule iffI)
paulson@14760:  apply (rule notI)
paulson@14760:  apply (erule exE)
paulson@14760:  apply (erule_tac x = "{w. \<exists>i. w=f i}" in allE, blast)
paulson@14760: apply (erule contrapos_np, simp, clarify)
paulson@14760: apply (subgoal_tac "\<forall>n. nat_rec x (%i y. @z. z:Q & (z,y) :r) n \<in> Q")
paulson@14760:  apply (rule_tac x = "nat_rec x (%i y. @z. z:Q & (z,y) :r)" in exI)
paulson@14760:  apply (rule allI, simp)
paulson@14760:  apply (rule someI2_ex, blast, blast)
paulson@14760: apply (rule allI)
paulson@14760: apply (induct_tac "n", simp_all)
paulson@14760: apply (rule someI2_ex, blast+)
paulson@14760: done
paulson@14760: 
nipkow@27760: lemma wf_no_infinite_down_chainE:
nipkow@27760:   assumes "wf r" obtains k where "(f (Suc k), f k) \<notin> r"
nipkow@27760: using `wf r` wf_iff_no_infinite_down_chain[of r] by blast
nipkow@27760: 
nipkow@27760: 
paulson@14760: text{*A dynamically-scoped fact for TFL *}
wenzelm@12298: lemma tfl_some: "\<forall>P x. P x --> P (Eps P)"
wenzelm@12298:   by (blast intro: someI)
paulson@11451: 
wenzelm@12298: 
wenzelm@12298: subsection {* Least value operator *}
paulson@11451: 
paulson@11451: constdefs
wenzelm@12298:   LeastM :: "['a => 'b::ord, 'a => bool] => 'a"
paulson@14760:   "LeastM m P == SOME x. P x & (\<forall>y. P y --> m x <= m y)"
paulson@11451: 
paulson@11451: syntax
wenzelm@12298:   "_LeastM" :: "[pttrn, 'a => 'b::ord, bool] => 'a"    ("LEAST _ WRT _. _" [0, 4, 10] 10)
paulson@11451: translations
wenzelm@12298:   "LEAST x WRT m. P" == "LeastM m (%x. P)"
paulson@11451: 
paulson@11451: lemma LeastMI2:
wenzelm@12298:   "P x ==> (!!y. P y ==> m x <= m y)
wenzelm@12298:     ==> (!!x. P x ==> \<forall>y. P y --> m x \<le> m y ==> Q x)
wenzelm@12298:     ==> Q (LeastM m P)"
paulson@14760:   apply (simp add: LeastM_def)
paulson@14208:   apply (rule someI2_ex, blast, blast)
wenzelm@12298:   done
paulson@11451: 
paulson@11451: lemma LeastM_equality:
wenzelm@12298:   "P k ==> (!!x. P x ==> m k <= m x)
wenzelm@12298:     ==> m (LEAST x WRT m. P x) = (m k::'a::order)"
paulson@14208:   apply (rule LeastMI2, assumption, blast)
wenzelm@12298:   apply (blast intro!: order_antisym)
wenzelm@12298:   done
paulson@11451: 
paulson@11454: lemma wf_linord_ex_has_least:
paulson@14760:   "wf r ==> \<forall>x y. ((x,y):r^+) = ((y,x)~:r^*) ==> P k
paulson@14760:     ==> \<exists>x. P x & (!y. P y --> (m x,m y):r^*)"
wenzelm@12298:   apply (drule wf_trancl [THEN wf_eq_minimal [THEN iffD1]])
paulson@14208:   apply (drule_tac x = "m`Collect P" in spec, force)
wenzelm@12298:   done
paulson@11454: 
paulson@11454: lemma ex_has_least_nat:
paulson@14760:     "P k ==> \<exists>x. P x & (\<forall>y. P y --> m x <= (m y::nat))"
wenzelm@12298:   apply (simp only: pred_nat_trancl_eq_le [symmetric])
wenzelm@12298:   apply (rule wf_pred_nat [THEN wf_linord_ex_has_least])
paulson@16796:    apply (simp add: less_eq linorder_not_le pred_nat_trancl_eq_le, assumption)
wenzelm@12298:   done
paulson@11454: 
wenzelm@12298: lemma LeastM_nat_lemma:
paulson@14760:     "P k ==> P (LeastM m P) & (\<forall>y. P y --> m (LeastM m P) <= (m y::nat))"
paulson@14760:   apply (simp add: LeastM_def)
wenzelm@12298:   apply (rule someI_ex)
wenzelm@12298:   apply (erule ex_has_least_nat)
wenzelm@12298:   done
paulson@11454: 
paulson@11454: lemmas LeastM_natI = LeastM_nat_lemma [THEN conjunct1, standard]
paulson@11454: 
paulson@11454: lemma LeastM_nat_le: "P x ==> m (LeastM m P) <= (m x::nat)"
paulson@14208: by (rule LeastM_nat_lemma [THEN conjunct2, THEN spec, THEN mp], assumption, assumption)
paulson@11454: 
paulson@11451: 
wenzelm@12298: subsection {* Greatest value operator *}
paulson@11451: 
paulson@11451: constdefs
wenzelm@12298:   GreatestM :: "['a => 'b::ord, 'a => bool] => 'a"
paulson@14760:   "GreatestM m P == SOME x. P x & (\<forall>y. P y --> m y <= m x)"
wenzelm@12298: 
wenzelm@12298:   Greatest :: "('a::ord => bool) => 'a"    (binder "GREATEST " 10)
wenzelm@12298:   "Greatest == GreatestM (%x. x)"
paulson@11451: 
paulson@11451: syntax
wenzelm@12298:   "_GreatestM" :: "[pttrn, 'a=>'b::ord, bool] => 'a"
wenzelm@12298:       ("GREATEST _ WRT _. _" [0, 4, 10] 10)
paulson@11451: 
paulson@11451: translations
wenzelm@12298:   "GREATEST x WRT m. P" == "GreatestM m (%x. P)"
paulson@11451: 
paulson@11451: lemma GreatestMI2:
wenzelm@12298:   "P x ==> (!!y. P y ==> m y <= m x)
wenzelm@12298:     ==> (!!x. P x ==> \<forall>y. P y --> m y \<le> m x ==> Q x)
wenzelm@12298:     ==> Q (GreatestM m P)"
paulson@14760:   apply (simp add: GreatestM_def)
paulson@14208:   apply (rule someI2_ex, blast, blast)
wenzelm@12298:   done
paulson@11451: 
paulson@11451: lemma GreatestM_equality:
wenzelm@12298:  "P k ==> (!!x. P x ==> m x <= m k)
wenzelm@12298:     ==> m (GREATEST x WRT m. P x) = (m k::'a::order)"
paulson@14208:   apply (rule_tac m = m in GreatestMI2, assumption, blast)
wenzelm@12298:   apply (blast intro!: order_antisym)
wenzelm@12298:   done
paulson@11451: 
paulson@11451: lemma Greatest_equality:
wenzelm@12298:   "P (k::'a::order) ==> (!!x. P x ==> x <= k) ==> (GREATEST x. P x) = k"
paulson@14760:   apply (simp add: Greatest_def)
paulson@14208:   apply (erule GreatestM_equality, blast)
wenzelm@12298:   done
paulson@11451: 
paulson@11451: lemma ex_has_greatest_nat_lemma:
paulson@14760:   "P k ==> \<forall>x. P x --> (\<exists>y. P y & ~ ((m y::nat) <= m x))
paulson@14760:     ==> \<exists>y. P y & ~ (m y < m k + n)"
paulson@15251:   apply (induct n, force)
wenzelm@12298:   apply (force simp add: le_Suc_eq)
wenzelm@12298:   done
paulson@11451: 
wenzelm@12298: lemma ex_has_greatest_nat:
paulson@14760:   "P k ==> \<forall>y. P y --> m y < b
paulson@14760:     ==> \<exists>x. P x & (\<forall>y. P y --> (m y::nat) <= m x)"
wenzelm@12298:   apply (rule ccontr)
wenzelm@12298:   apply (cut_tac P = P and n = "b - m k" in ex_has_greatest_nat_lemma)
paulson@14208:     apply (subgoal_tac [3] "m k <= b", auto)
wenzelm@12298:   done
paulson@11451: 
wenzelm@12298: lemma GreatestM_nat_lemma:
paulson@14760:   "P k ==> \<forall>y. P y --> m y < b
paulson@14760:     ==> P (GreatestM m P) & (\<forall>y. P y --> (m y::nat) <= m (GreatestM m P))"
paulson@14760:   apply (simp add: GreatestM_def)
wenzelm@12298:   apply (rule someI_ex)
paulson@14208:   apply (erule ex_has_greatest_nat, assumption)
wenzelm@12298:   done
paulson@11451: 
paulson@11451: lemmas GreatestM_natI = GreatestM_nat_lemma [THEN conjunct1, standard]
paulson@11451: 
wenzelm@12298: lemma GreatestM_nat_le:
paulson@14760:   "P x ==> \<forall>y. P y --> m y < b
wenzelm@12298:     ==> (m x::nat) <= m (GreatestM m P)"
berghofe@21020:   apply (blast dest: GreatestM_nat_lemma [THEN conjunct2, THEN spec, of P])
wenzelm@12298:   done
wenzelm@12298: 
wenzelm@12298: 
wenzelm@12298: text {* \medskip Specialization to @{text GREATEST}. *}
wenzelm@12298: 
paulson@14760: lemma GreatestI: "P (k::nat) ==> \<forall>y. P y --> y < b ==> P (GREATEST x. P x)"
paulson@14760:   apply (simp add: Greatest_def)
paulson@14208:   apply (rule GreatestM_natI, auto)
wenzelm@12298:   done
paulson@11451: 
wenzelm@12298: lemma Greatest_le:
paulson@14760:     "P x ==> \<forall>y. P y --> y < b ==> (x::nat) <= (GREATEST x. P x)"
paulson@14760:   apply (simp add: Greatest_def)
paulson@14208:   apply (rule GreatestM_nat_le, auto)
wenzelm@12298:   done
wenzelm@12298: 
wenzelm@12298: 
wenzelm@12298: subsection {* The Meson proof procedure *}
paulson@11451: 
wenzelm@12298: subsubsection {* Negation Normal Form *}
wenzelm@12298: 
wenzelm@12298: text {* de Morgan laws *}
wenzelm@12298: 
wenzelm@12298: lemma meson_not_conjD: "~(P&Q) ==> ~P | ~Q"
wenzelm@12298:   and meson_not_disjD: "~(P|Q) ==> ~P & ~Q"
wenzelm@12298:   and meson_not_notD: "~~P ==> P"
paulson@14760:   and meson_not_allD: "!!P. ~(\<forall>x. P(x)) ==> \<exists>x. ~P(x)"
paulson@14760:   and meson_not_exD: "!!P. ~(\<exists>x. P(x)) ==> \<forall>x. ~P(x)"
wenzelm@12298:   by fast+
paulson@11451: 
wenzelm@12298: text {* Removal of @{text "-->"} and @{text "<->"} (positive and
wenzelm@12298: negative occurrences) *}
wenzelm@12298: 
wenzelm@12298: lemma meson_imp_to_disjD: "P-->Q ==> ~P | Q"
wenzelm@12298:   and meson_not_impD: "~(P-->Q) ==> P & ~Q"
wenzelm@12298:   and meson_iff_to_disjD: "P=Q ==> (~P | Q) & (~Q | P)"
wenzelm@12298:   and meson_not_iffD: "~(P=Q) ==> (P | Q) & (~P | ~Q)"
wenzelm@12298:     -- {* Much more efficient than @{prop "(P & ~Q) | (Q & ~P)"} for computing CNF *}
paulson@18389:   and meson_not_refl_disj_D: "x ~= x | P ==> P"
wenzelm@12298:   by fast+
wenzelm@12298: 
wenzelm@12298: 
wenzelm@12298: subsubsection {* Pulling out the existential quantifiers *}
wenzelm@12298: 
wenzelm@12298: text {* Conjunction *}
wenzelm@12298: 
paulson@14760: lemma meson_conj_exD1: "!!P Q. (\<exists>x. P(x)) & Q ==> \<exists>x. P(x) & Q"
paulson@14760:   and meson_conj_exD2: "!!P Q. P & (\<exists>x. Q(x)) ==> \<exists>x. P & Q(x)"
wenzelm@12298:   by fast+
wenzelm@12298: 
paulson@11451: 
wenzelm@12298: text {* Disjunction *}
wenzelm@12298: 
paulson@14760: lemma meson_disj_exD: "!!P Q. (\<exists>x. P(x)) | (\<exists>x. Q(x)) ==> \<exists>x. P(x) | Q(x)"
wenzelm@12298:   -- {* DO NOT USE with forall-Skolemization: makes fewer schematic variables!! *}
wenzelm@12298:   -- {* With ex-Skolemization, makes fewer Skolem constants *}
paulson@14760:   and meson_disj_exD1: "!!P Q. (\<exists>x. P(x)) | Q ==> \<exists>x. P(x) | Q"
paulson@14760:   and meson_disj_exD2: "!!P Q. P | (\<exists>x. Q(x)) ==> \<exists>x. P | Q(x)"
wenzelm@12298:   by fast+
wenzelm@12298: 
paulson@11451: 
wenzelm@12298: subsubsection {* Generating clauses for the Meson Proof Procedure *}
wenzelm@12298: 
wenzelm@12298: text {* Disjunctions *}
wenzelm@12298: 
wenzelm@12298: lemma meson_disj_assoc: "(P|Q)|R ==> P|(Q|R)"
wenzelm@12298:   and meson_disj_comm: "P|Q ==> Q|P"
wenzelm@12298:   and meson_disj_FalseD1: "False|P ==> P"
wenzelm@12298:   and meson_disj_FalseD2: "P|False ==> P"
wenzelm@12298:   by fast+
paulson@11451: 
paulson@14760: 
paulson@14760: subsection{*Lemmas for Meson, the Model Elimination Procedure*}
paulson@14760: 
paulson@14760: text{* Generation of contrapositives *}
paulson@14760: 
paulson@14760: text{*Inserts negated disjunct after removing the negation; P is a literal.
paulson@14760:   Model elimination requires assuming the negation of every attempted subgoal,
paulson@14760:   hence the negated disjuncts.*}
paulson@14760: lemma make_neg_rule: "~P|Q ==> ((~P==>P) ==> Q)"
paulson@14760: by blast
paulson@14760: 
paulson@14760: text{*Version for Plaisted's "Postive refinement" of the Meson procedure*}
paulson@14760: lemma make_refined_neg_rule: "~P|Q ==> (P ==> Q)"
paulson@14760: by blast
paulson@14760: 
paulson@14760: text{*@{term P} should be a literal*}
paulson@14760: lemma make_pos_rule: "P|Q ==> ((P==>~P) ==> Q)"
paulson@14760: by blast
paulson@14760: 
paulson@14760: text{*Versions of @{text make_neg_rule} and @{text make_pos_rule} that don't
paulson@14760: insert new assumptions, for ordinary resolution.*}
paulson@14760: 
paulson@14760: lemmas make_neg_rule' = make_refined_neg_rule
paulson@14760: 
paulson@14760: lemma make_pos_rule': "[|P|Q; ~P|] ==> Q"
paulson@14760: by blast
paulson@14760: 
paulson@14760: text{* Generation of a goal clause -- put away the final literal *}
paulson@14760: 
paulson@14760: lemma make_neg_goal: "~P ==> ((~P==>P) ==> False)"
paulson@14760: by blast
paulson@14760: 
paulson@14760: lemma make_pos_goal: "P ==> ((P==>~P) ==> False)"
paulson@14760: by blast
paulson@14760: 
paulson@14760: 
paulson@14760: subsubsection{* Lemmas for Forward Proof*}
paulson@14760: 
paulson@14760: text{*There is a similarity to congruence rules*}
paulson@14760: 
paulson@14760: (*NOTE: could handle conjunctions (faster?) by
paulson@14760:     nf(th RS conjunct2) RS (nf(th RS conjunct1) RS conjI) *)
paulson@14760: lemma conj_forward: "[| P'&Q';  P' ==> P;  Q' ==> Q |] ==> P&Q"
paulson@14760: by blast
paulson@14760: 
paulson@14760: lemma disj_forward: "[| P'|Q';  P' ==> P;  Q' ==> Q |] ==> P|Q"
paulson@14760: by blast
paulson@14760: 
paulson@14760: (*Version of @{text disj_forward} for removal of duplicate literals*)
paulson@14760: lemma disj_forward2:
paulson@14760:     "[| P'|Q';  P' ==> P;  [| Q'; P==>False |] ==> Q |] ==> P|Q"
paulson@14760: apply blast 
paulson@14760: done
paulson@14760: 
paulson@14760: lemma all_forward: "[| \<forall>x. P'(x);  !!x. P'(x) ==> P(x) |] ==> \<forall>x. P(x)"
paulson@14760: by blast
paulson@14760: 
paulson@14760: lemma ex_forward: "[| \<exists>x. P'(x);  !!x. P'(x) ==> P(x) |] ==> \<exists>x. P(x)"
paulson@14760: by blast
paulson@14760: 
paulson@17420: 
paulson@21999: subsection {* Meson package *}
wenzelm@17893: 
paulson@11451: use "Tools/meson.ML"
paulson@11451: 
paulson@26562: setup Meson.setup
paulson@26562: 
wenzelm@17893: 
wenzelm@17893: subsection {* Specification package -- Hilbertized version *}
wenzelm@17893: 
wenzelm@17893: lemma exE_some: "[| Ex P ; c == Eps P |] ==> P c"
wenzelm@17893:   by (simp only: someI_ex)
wenzelm@17893: 
haftmann@31723: use "Tools/choice_specification.ML"
skalberg@14115: 
haftmann@31454: 
paulson@11451: end




