src/HOL/Hilbert_Choice.thy
author nipkow
Mon Sep 13 11:13:15 2010 +0200 (2010-09-13)
changeset 39302 d7728f65b353
parent 39198 f967a16dfcdd
child 39900 549c00e0e89b
permissions -rw-r--r--
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
     1 (*  Title:      HOL/Hilbert_Choice.thy
     2     Author:     Lawrence C Paulson, Tobias Nipkow
     3     Copyright   2001  University of Cambridge
     4 *)
     5 
     6 header {* Hilbert's Epsilon-Operator and the Axiom of Choice *}
     7 
     8 theory Hilbert_Choice
     9 imports Nat Wellfounded Plain
    10 uses ("Tools/meson.ML")
    11      ("Tools/choice_specification.ML")
    12 begin
    13 
    14 subsection {* Hilbert's epsilon *}
    15 
    16 axiomatization Eps :: "('a => bool) => 'a" where
    17   someI: "P x ==> P (Eps P)"
    18 
    19 syntax (epsilon)
    20   "_Eps"        :: "[pttrn, bool] => 'a"    ("(3\<some>_./ _)" [0, 10] 10)
    21 syntax (HOL)
    22   "_Eps"        :: "[pttrn, bool] => 'a"    ("(3@ _./ _)" [0, 10] 10)
    23 syntax
    24   "_Eps"        :: "[pttrn, bool] => 'a"    ("(3SOME _./ _)" [0, 10] 10)
    25 translations
    26   "SOME x. P" == "CONST Eps (%x. P)"
    27 
    28 print_translation {*
    29   [(@{const_syntax Eps}, fn [Abs abs] =>
    30       let val (x, t) = atomic_abs_tr' abs
    31       in Syntax.const @{syntax_const "_Eps"} $ x $ t end)]
    32 *} -- {* to avoid eta-contraction of body *}
    33 
    34 definition inv_into :: "'a set => ('a => 'b) => ('b => 'a)" where
    35 "inv_into A f == %x. SOME y. y : A & f y = x"
    36 
    37 abbreviation inv :: "('a => 'b) => ('b => 'a)" where
    38 "inv == inv_into UNIV"
    39 
    40 
    41 subsection {*Hilbert's Epsilon-operator*}
    42 
    43 text{*Easier to apply than @{text someI} if the witness comes from an
    44 existential formula*}
    45 lemma someI_ex [elim?]: "\<exists>x. P x ==> P (SOME x. P x)"
    46 apply (erule exE)
    47 apply (erule someI)
    48 done
    49 
    50 text{*Easier to apply than @{text someI} because the conclusion has only one
    51 occurrence of @{term P}.*}
    52 lemma someI2: "[| P a;  !!x. P x ==> Q x |] ==> Q (SOME x. P x)"
    53 by (blast intro: someI)
    54 
    55 text{*Easier to apply than @{text someI2} if the witness comes from an
    56 existential formula*}
    57 lemma someI2_ex: "[| \<exists>a. P a; !!x. P x ==> Q x |] ==> Q (SOME x. P x)"
    58 by (blast intro: someI2)
    59 
    60 lemma some_equality [intro]:
    61      "[| P a;  !!x. P x ==> x=a |] ==> (SOME x. P x) = a"
    62 by (blast intro: someI2)
    63 
    64 lemma some1_equality: "[| EX!x. P x; P a |] ==> (SOME x. P x) = a"
    65 by blast
    66 
    67 lemma some_eq_ex: "P (SOME x. P x) =  (\<exists>x. P x)"
    68 by (blast intro: someI)
    69 
    70 lemma some_eq_trivial [simp]: "(SOME y. y=x) = x"
    71 apply (rule some_equality)
    72 apply (rule refl, assumption)
    73 done
    74 
    75 lemma some_sym_eq_trivial [simp]: "(SOME y. x=y) = x"
    76 apply (rule some_equality)
    77 apply (rule refl)
    78 apply (erule sym)
    79 done
    80 
    81 
    82 subsection{*Axiom of Choice, Proved Using the Description Operator*}
    83 
    84 text{*Used in @{text "Tools/meson.ML"}*}
    85 lemma choice: "\<forall>x. \<exists>y. Q x y ==> \<exists>f. \<forall>x. Q x (f x)"
    86 by (fast elim: someI)
    87 
    88 lemma bchoice: "\<forall>x\<in>S. \<exists>y. Q x y ==> \<exists>f. \<forall>x\<in>S. Q x (f x)"
    89 by (fast elim: someI)
    90 
    91 
    92 subsection {*Function Inverse*}
    93 
    94 lemma inv_def: "inv f = (%y. SOME x. f x = y)"
    95 by(simp add: inv_into_def)
    96 
    97 lemma inv_into_into: "x : f ` A ==> inv_into A f x : A"
    98 apply (simp add: inv_into_def)
    99 apply (fast intro: someI2)
   100 done
   101 
   102 lemma inv_id [simp]: "inv id = id"
   103 by (simp add: inv_into_def id_def)
   104 
   105 lemma inv_into_f_f [simp]:
   106   "[| inj_on f A;  x : A |] ==> inv_into A f (f x) = x"
   107 apply (simp add: inv_into_def inj_on_def)
   108 apply (blast intro: someI2)
   109 done
   110 
   111 lemma inv_f_f: "inj f ==> inv f (f x) = x"
   112 by simp
   113 
   114 lemma f_inv_into_f: "y : f`A  ==> f (inv_into A f y) = y"
   115 apply (simp add: inv_into_def)
   116 apply (fast intro: someI2)
   117 done
   118 
   119 lemma inv_into_f_eq: "[| inj_on f A; x : A; f x = y |] ==> inv_into A f y = x"
   120 apply (erule subst)
   121 apply (fast intro: inv_into_f_f)
   122 done
   123 
   124 lemma inv_f_eq: "[| inj f; f x = y |] ==> inv f y = x"
   125 by (simp add:inv_into_f_eq)
   126 
   127 lemma inj_imp_inv_eq: "[| inj f; ALL x. f(g x) = x |] ==> inv f = g"
   128 by (blast intro: ext inv_into_f_eq)
   129 
   130 text{*But is it useful?*}
   131 lemma inj_transfer:
   132   assumes injf: "inj f" and minor: "!!y. y \<in> range(f) ==> P(inv f y)"
   133   shows "P x"
   134 proof -
   135   have "f x \<in> range f" by auto
   136   hence "P(inv f (f x))" by (rule minor)
   137   thus "P x" by (simp add: inv_into_f_f [OF injf])
   138 qed
   139 
   140 lemma inj_iff: "(inj f) = (inv f o f = id)"
   141 apply (simp add: o_def fun_eq_iff)
   142 apply (blast intro: inj_on_inverseI inv_into_f_f)
   143 done
   144 
   145 lemma inv_o_cancel[simp]: "inj f ==> inv f o f = id"
   146 by (simp add: inj_iff)
   147 
   148 lemma o_inv_o_cancel[simp]: "inj f ==> g o inv f o f = g"
   149 by (simp add: o_assoc[symmetric])
   150 
   151 lemma inv_into_image_cancel[simp]:
   152   "inj_on f A ==> S <= A ==> inv_into A f ` f ` S = S"
   153 by(fastsimp simp: image_def)
   154 
   155 lemma inj_imp_surj_inv: "inj f ==> surj (inv f)"
   156 by (blast intro: surjI inv_into_f_f)
   157 
   158 lemma surj_f_inv_f: "surj f ==> f(inv f y) = y"
   159 by (simp add: f_inv_into_f surj_range)
   160 
   161 lemma inv_into_injective:
   162   assumes eq: "inv_into A f x = inv_into A f y"
   163       and x: "x: f`A"
   164       and y: "y: f`A"
   165   shows "x=y"
   166 proof -
   167   have "f (inv_into A f x) = f (inv_into A f y)" using eq by simp
   168   thus ?thesis by (simp add: f_inv_into_f x y)
   169 qed
   170 
   171 lemma inj_on_inv_into: "B <= f`A ==> inj_on (inv_into A f) B"
   172 by (blast intro: inj_onI dest: inv_into_injective injD)
   173 
   174 lemma bij_betw_inv_into: "bij_betw f A B ==> bij_betw (inv_into A f) B A"
   175 by (auto simp add: bij_betw_def inj_on_inv_into)
   176 
   177 lemma surj_imp_inj_inv: "surj f ==> inj (inv f)"
   178 by (simp add: inj_on_inv_into surj_range)
   179 
   180 lemma surj_iff: "(surj f) = (f o inv f = id)"
   181 apply (simp add: o_def fun_eq_iff)
   182 apply (blast intro: surjI surj_f_inv_f)
   183 done
   184 
   185 lemma surj_imp_inv_eq: "[| surj f; \<forall>x. g(f x) = x |] ==> inv f = g"
   186 apply (rule ext)
   187 apply (drule_tac x = "inv f x" in spec)
   188 apply (simp add: surj_f_inv_f)
   189 done
   190 
   191 lemma bij_imp_bij_inv: "bij f ==> bij (inv f)"
   192 by (simp add: bij_def inj_imp_surj_inv surj_imp_inj_inv)
   193 
   194 lemma inv_equality: "[| !!x. g (f x) = x;  !!y. f (g y) = y |] ==> inv f = g"
   195 apply (rule ext)
   196 apply (auto simp add: inv_into_def)
   197 done
   198 
   199 lemma inv_inv_eq: "bij f ==> inv (inv f) = f"
   200 apply (rule inv_equality)
   201 apply (auto simp add: bij_def surj_f_inv_f)
   202 done
   203 
   204 (** bij(inv f) implies little about f.  Consider f::bool=>bool such that
   205     f(True)=f(False)=True.  Then it's consistent with axiom someI that
   206     inv f could be any function at all, including the identity function.
   207     If inv f=id then inv f is a bijection, but inj f, surj(f) and
   208     inv(inv f)=f all fail.
   209 **)
   210 
   211 lemma inv_into_comp:
   212   "[| inj_on f (g ` A); inj_on g A; x : f ` g ` A |] ==>
   213   inv_into A (f o g) x = (inv_into A g o inv_into (g ` A) f) x"
   214 apply (rule inv_into_f_eq)
   215   apply (fast intro: comp_inj_on)
   216  apply (simp add: inv_into_into)
   217 apply (simp add: f_inv_into_f inv_into_into)
   218 done
   219 
   220 lemma o_inv_distrib: "[| bij f; bij g |] ==> inv (f o g) = inv g o inv f"
   221 apply (rule inv_equality)
   222 apply (auto simp add: bij_def surj_f_inv_f)
   223 done
   224 
   225 lemma image_surj_f_inv_f: "surj f ==> f ` (inv f ` A) = A"
   226 by (simp add: image_eq_UN surj_f_inv_f)
   227 
   228 lemma image_inv_f_f: "inj f ==> (inv f) ` (f ` A) = A"
   229 by (simp add: image_eq_UN)
   230 
   231 lemma inv_image_comp: "inj f ==> inv f ` (f`X) = X"
   232 by (auto simp add: image_def)
   233 
   234 lemma bij_image_Collect_eq: "bij f ==> f ` Collect P = {y. P (inv f y)}"
   235 apply auto
   236 apply (force simp add: bij_is_inj)
   237 apply (blast intro: bij_is_surj [THEN surj_f_inv_f, symmetric])
   238 done
   239 
   240 lemma bij_vimage_eq_inv_image: "bij f ==> f -` A = inv f ` A" 
   241 apply (auto simp add: bij_is_surj [THEN surj_f_inv_f])
   242 apply (blast intro: bij_is_inj [THEN inv_into_f_f, symmetric])
   243 done
   244 
   245 lemma finite_fun_UNIVD1:
   246   assumes fin: "finite (UNIV :: ('a \<Rightarrow> 'b) set)"
   247   and card: "card (UNIV :: 'b set) \<noteq> Suc 0"
   248   shows "finite (UNIV :: 'a set)"
   249 proof -
   250   from fin have finb: "finite (UNIV :: 'b set)" by (rule finite_fun_UNIVD2)
   251   with card have "card (UNIV :: 'b set) \<ge> Suc (Suc 0)"
   252     by (cases "card (UNIV :: 'b set)") (auto simp add: card_eq_0_iff)
   253   then obtain n where "card (UNIV :: 'b set) = Suc (Suc n)" "n = card (UNIV :: 'b set) - Suc (Suc 0)" by auto
   254   then obtain b1 b2 where b1b2: "(b1 :: 'b) \<noteq> (b2 :: 'b)" by (auto simp add: card_Suc_eq)
   255   from fin have "finite (range (\<lambda>f :: 'a \<Rightarrow> 'b. inv f b1))" by (rule finite_imageI)
   256   moreover have "UNIV = range (\<lambda>f :: 'a \<Rightarrow> 'b. inv f b1)"
   257   proof (rule UNIV_eq_I)
   258     fix x :: 'a
   259     from b1b2 have "x = inv (\<lambda>y. if y = x then b1 else b2) b1" by (simp add: inv_into_def)
   260     thus "x \<in> range (\<lambda>f\<Colon>'a \<Rightarrow> 'b. inv f b1)" by blast
   261   qed
   262   ultimately show "finite (UNIV :: 'a set)" by simp
   263 qed
   264 
   265 
   266 subsection {*Other Consequences of Hilbert's Epsilon*}
   267 
   268 text {*Hilbert's Epsilon and the @{term split} Operator*}
   269 
   270 text{*Looping simprule*}
   271 lemma split_paired_Eps: "(SOME x. P x) = (SOME (a,b). P(a,b))"
   272   by simp
   273 
   274 lemma Eps_split: "Eps (split P) = (SOME xy. P (fst xy) (snd xy))"
   275   by (simp add: split_def)
   276 
   277 lemma Eps_split_eq [simp]: "(@(x',y'). x = x' & y = y') = (x,y)"
   278   by blast
   279 
   280 
   281 text{*A relation is wellfounded iff it has no infinite descending chain*}
   282 lemma wf_iff_no_infinite_down_chain:
   283   "wf r = (~(\<exists>f. \<forall>i. (f(Suc i),f i) \<in> r))"
   284 apply (simp only: wf_eq_minimal)
   285 apply (rule iffI)
   286  apply (rule notI)
   287  apply (erule exE)
   288  apply (erule_tac x = "{w. \<exists>i. w=f i}" in allE, blast)
   289 apply (erule contrapos_np, simp, clarify)
   290 apply (subgoal_tac "\<forall>n. nat_rec x (%i y. @z. z:Q & (z,y) :r) n \<in> Q")
   291  apply (rule_tac x = "nat_rec x (%i y. @z. z:Q & (z,y) :r)" in exI)
   292  apply (rule allI, simp)
   293  apply (rule someI2_ex, blast, blast)
   294 apply (rule allI)
   295 apply (induct_tac "n", simp_all)
   296 apply (rule someI2_ex, blast+)
   297 done
   298 
   299 lemma wf_no_infinite_down_chainE:
   300   assumes "wf r" obtains k where "(f (Suc k), f k) \<notin> r"
   301 using `wf r` wf_iff_no_infinite_down_chain[of r] by blast
   302 
   303 
   304 text{*A dynamically-scoped fact for TFL *}
   305 lemma tfl_some: "\<forall>P x. P x --> P (Eps P)"
   306   by (blast intro: someI)
   307 
   308 
   309 subsection {* Least value operator *}
   310 
   311 definition
   312   LeastM :: "['a => 'b::ord, 'a => bool] => 'a" where
   313   "LeastM m P == SOME x. P x & (\<forall>y. P y --> m x <= m y)"
   314 
   315 syntax
   316   "_LeastM" :: "[pttrn, 'a => 'b::ord, bool] => 'a"    ("LEAST _ WRT _. _" [0, 4, 10] 10)
   317 translations
   318   "LEAST x WRT m. P" == "CONST LeastM m (%x. P)"
   319 
   320 lemma LeastMI2:
   321   "P x ==> (!!y. P y ==> m x <= m y)
   322     ==> (!!x. P x ==> \<forall>y. P y --> m x \<le> m y ==> Q x)
   323     ==> Q (LeastM m P)"
   324   apply (simp add: LeastM_def)
   325   apply (rule someI2_ex, blast, blast)
   326   done
   327 
   328 lemma LeastM_equality:
   329   "P k ==> (!!x. P x ==> m k <= m x)
   330     ==> m (LEAST x WRT m. P x) = (m k::'a::order)"
   331   apply (rule LeastMI2, assumption, blast)
   332   apply (blast intro!: order_antisym)
   333   done
   334 
   335 lemma wf_linord_ex_has_least:
   336   "wf r ==> \<forall>x y. ((x,y):r^+) = ((y,x)~:r^*) ==> P k
   337     ==> \<exists>x. P x & (!y. P y --> (m x,m y):r^*)"
   338   apply (drule wf_trancl [THEN wf_eq_minimal [THEN iffD1]])
   339   apply (drule_tac x = "m`Collect P" in spec, force)
   340   done
   341 
   342 lemma ex_has_least_nat:
   343     "P k ==> \<exists>x. P x & (\<forall>y. P y --> m x <= (m y::nat))"
   344   apply (simp only: pred_nat_trancl_eq_le [symmetric])
   345   apply (rule wf_pred_nat [THEN wf_linord_ex_has_least])
   346    apply (simp add: less_eq linorder_not_le pred_nat_trancl_eq_le, assumption)
   347   done
   348 
   349 lemma LeastM_nat_lemma:
   350     "P k ==> P (LeastM m P) & (\<forall>y. P y --> m (LeastM m P) <= (m y::nat))"
   351   apply (simp add: LeastM_def)
   352   apply (rule someI_ex)
   353   apply (erule ex_has_least_nat)
   354   done
   355 
   356 lemmas LeastM_natI = LeastM_nat_lemma [THEN conjunct1, standard]
   357 
   358 lemma LeastM_nat_le: "P x ==> m (LeastM m P) <= (m x::nat)"
   359 by (rule LeastM_nat_lemma [THEN conjunct2, THEN spec, THEN mp], assumption, assumption)
   360 
   361 
   362 subsection {* Greatest value operator *}
   363 
   364 definition
   365   GreatestM :: "['a => 'b::ord, 'a => bool] => 'a" where
   366   "GreatestM m P == SOME x. P x & (\<forall>y. P y --> m y <= m x)"
   367 
   368 definition
   369   Greatest :: "('a::ord => bool) => 'a" (binder "GREATEST " 10) where
   370   "Greatest == GreatestM (%x. x)"
   371 
   372 syntax
   373   "_GreatestM" :: "[pttrn, 'a => 'b::ord, bool] => 'a"
   374       ("GREATEST _ WRT _. _" [0, 4, 10] 10)
   375 translations
   376   "GREATEST x WRT m. P" == "CONST GreatestM m (%x. P)"
   377 
   378 lemma GreatestMI2:
   379   "P x ==> (!!y. P y ==> m y <= m x)
   380     ==> (!!x. P x ==> \<forall>y. P y --> m y \<le> m x ==> Q x)
   381     ==> Q (GreatestM m P)"
   382   apply (simp add: GreatestM_def)
   383   apply (rule someI2_ex, blast, blast)
   384   done
   385 
   386 lemma GreatestM_equality:
   387  "P k ==> (!!x. P x ==> m x <= m k)
   388     ==> m (GREATEST x WRT m. P x) = (m k::'a::order)"
   389   apply (rule_tac m = m in GreatestMI2, assumption, blast)
   390   apply (blast intro!: order_antisym)
   391   done
   392 
   393 lemma Greatest_equality:
   394   "P (k::'a::order) ==> (!!x. P x ==> x <= k) ==> (GREATEST x. P x) = k"
   395   apply (simp add: Greatest_def)
   396   apply (erule GreatestM_equality, blast)
   397   done
   398 
   399 lemma ex_has_greatest_nat_lemma:
   400   "P k ==> \<forall>x. P x --> (\<exists>y. P y & ~ ((m y::nat) <= m x))
   401     ==> \<exists>y. P y & ~ (m y < m k + n)"
   402   apply (induct n, force)
   403   apply (force simp add: le_Suc_eq)
   404   done
   405 
   406 lemma ex_has_greatest_nat:
   407   "P k ==> \<forall>y. P y --> m y < b
   408     ==> \<exists>x. P x & (\<forall>y. P y --> (m y::nat) <= m x)"
   409   apply (rule ccontr)
   410   apply (cut_tac P = P and n = "b - m k" in ex_has_greatest_nat_lemma)
   411     apply (subgoal_tac [3] "m k <= b", auto)
   412   done
   413 
   414 lemma GreatestM_nat_lemma:
   415   "P k ==> \<forall>y. P y --> m y < b
   416     ==> P (GreatestM m P) & (\<forall>y. P y --> (m y::nat) <= m (GreatestM m P))"
   417   apply (simp add: GreatestM_def)
   418   apply (rule someI_ex)
   419   apply (erule ex_has_greatest_nat, assumption)
   420   done
   421 
   422 lemmas GreatestM_natI = GreatestM_nat_lemma [THEN conjunct1, standard]
   423 
   424 lemma GreatestM_nat_le:
   425   "P x ==> \<forall>y. P y --> m y < b
   426     ==> (m x::nat) <= m (GreatestM m P)"
   427   apply (blast dest: GreatestM_nat_lemma [THEN conjunct2, THEN spec, of P])
   428   done
   429 
   430 
   431 text {* \medskip Specialization to @{text GREATEST}. *}
   432 
   433 lemma GreatestI: "P (k::nat) ==> \<forall>y. P y --> y < b ==> P (GREATEST x. P x)"
   434   apply (simp add: Greatest_def)
   435   apply (rule GreatestM_natI, auto)
   436   done
   437 
   438 lemma Greatest_le:
   439     "P x ==> \<forall>y. P y --> y < b ==> (x::nat) <= (GREATEST x. P x)"
   440   apply (simp add: Greatest_def)
   441   apply (rule GreatestM_nat_le, auto)
   442   done
   443 
   444 
   445 subsection {* The Meson proof procedure *}
   446 
   447 subsubsection {* Negation Normal Form *}
   448 
   449 text {* de Morgan laws *}
   450 
   451 lemma meson_not_conjD: "~(P&Q) ==> ~P | ~Q"
   452   and meson_not_disjD: "~(P|Q) ==> ~P & ~Q"
   453   and meson_not_notD: "~~P ==> P"
   454   and meson_not_allD: "!!P. ~(\<forall>x. P(x)) ==> \<exists>x. ~P(x)"
   455   and meson_not_exD: "!!P. ~(\<exists>x. P(x)) ==> \<forall>x. ~P(x)"
   456   by fast+
   457 
   458 text {* Removal of @{text "-->"} and @{text "<->"} (positive and
   459 negative occurrences) *}
   460 
   461 lemma meson_imp_to_disjD: "P-->Q ==> ~P | Q"
   462   and meson_not_impD: "~(P-->Q) ==> P & ~Q"
   463   and meson_iff_to_disjD: "P=Q ==> (~P | Q) & (~Q | P)"
   464   and meson_not_iffD: "~(P=Q) ==> (P | Q) & (~P | ~Q)"
   465     -- {* Much more efficient than @{prop "(P & ~Q) | (Q & ~P)"} for computing CNF *}
   466   and meson_not_refl_disj_D: "x ~= x | P ==> P"
   467   by fast+
   468 
   469 
   470 subsubsection {* Pulling out the existential quantifiers *}
   471 
   472 text {* Conjunction *}
   473 
   474 lemma meson_conj_exD1: "!!P Q. (\<exists>x. P(x)) & Q ==> \<exists>x. P(x) & Q"
   475   and meson_conj_exD2: "!!P Q. P & (\<exists>x. Q(x)) ==> \<exists>x. P & Q(x)"
   476   by fast+
   477 
   478 
   479 text {* Disjunction *}
   480 
   481 lemma meson_disj_exD: "!!P Q. (\<exists>x. P(x)) | (\<exists>x. Q(x)) ==> \<exists>x. P(x) | Q(x)"
   482   -- {* DO NOT USE with forall-Skolemization: makes fewer schematic variables!! *}
   483   -- {* With ex-Skolemization, makes fewer Skolem constants *}
   484   and meson_disj_exD1: "!!P Q. (\<exists>x. P(x)) | Q ==> \<exists>x. P(x) | Q"
   485   and meson_disj_exD2: "!!P Q. P | (\<exists>x. Q(x)) ==> \<exists>x. P | Q(x)"
   486   by fast+
   487 
   488 
   489 subsubsection {* Generating clauses for the Meson Proof Procedure *}
   490 
   491 text {* Disjunctions *}
   492 
   493 lemma meson_disj_assoc: "(P|Q)|R ==> P|(Q|R)"
   494   and meson_disj_comm: "P|Q ==> Q|P"
   495   and meson_disj_FalseD1: "False|P ==> P"
   496   and meson_disj_FalseD2: "P|False ==> P"
   497   by fast+
   498 
   499 
   500 subsection{*Lemmas for Meson, the Model Elimination Procedure*}
   501 
   502 text{* Generation of contrapositives *}
   503 
   504 text{*Inserts negated disjunct after removing the negation; P is a literal.
   505   Model elimination requires assuming the negation of every attempted subgoal,
   506   hence the negated disjuncts.*}
   507 lemma make_neg_rule: "~P|Q ==> ((~P==>P) ==> Q)"
   508 by blast
   509 
   510 text{*Version for Plaisted's "Postive refinement" of the Meson procedure*}
   511 lemma make_refined_neg_rule: "~P|Q ==> (P ==> Q)"
   512 by blast
   513 
   514 text{*@{term P} should be a literal*}
   515 lemma make_pos_rule: "P|Q ==> ((P==>~P) ==> Q)"
   516 by blast
   517 
   518 text{*Versions of @{text make_neg_rule} and @{text make_pos_rule} that don't
   519 insert new assumptions, for ordinary resolution.*}
   520 
   521 lemmas make_neg_rule' = make_refined_neg_rule
   522 
   523 lemma make_pos_rule': "[|P|Q; ~P|] ==> Q"
   524 by blast
   525 
   526 text{* Generation of a goal clause -- put away the final literal *}
   527 
   528 lemma make_neg_goal: "~P ==> ((~P==>P) ==> False)"
   529 by blast
   530 
   531 lemma make_pos_goal: "P ==> ((P==>~P) ==> False)"
   532 by blast
   533 
   534 
   535 subsubsection{* Lemmas for Forward Proof*}
   536 
   537 text{*There is a similarity to congruence rules*}
   538 
   539 (*NOTE: could handle conjunctions (faster?) by
   540     nf(th RS conjunct2) RS (nf(th RS conjunct1) RS conjI) *)
   541 lemma conj_forward: "[| P'&Q';  P' ==> P;  Q' ==> Q |] ==> P&Q"
   542 by blast
   543 
   544 lemma disj_forward: "[| P'|Q';  P' ==> P;  Q' ==> Q |] ==> P|Q"
   545 by blast
   546 
   547 (*Version of @{text disj_forward} for removal of duplicate literals*)
   548 lemma disj_forward2:
   549     "[| P'|Q';  P' ==> P;  [| Q'; P==>False |] ==> Q |] ==> P|Q"
   550 apply blast 
   551 done
   552 
   553 lemma all_forward: "[| \<forall>x. P'(x);  !!x. P'(x) ==> P(x) |] ==> \<forall>x. P(x)"
   554 by blast
   555 
   556 lemma ex_forward: "[| \<exists>x. P'(x);  !!x. P'(x) ==> P(x) |] ==> \<exists>x. P(x)"
   557 by blast
   558 
   559 
   560 subsection {* Meson package *}
   561 
   562 use "Tools/meson.ML"
   563 
   564 setup Meson.setup
   565 
   566 
   567 subsection {* Specification package -- Hilbertized version *}
   568 
   569 lemma exE_some: "[| Ex P ; c == Eps P |] ==> P c"
   570   by (simp only: someI_ex)
   571 
   572 use "Tools/choice_specification.ML"
   573 
   574 
   575 end