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