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