src/HOL/Hilbert_Choice.thy
author paulson
Fri Sep 26 10:34:57 2003 +0200 (2003-09-26)
changeset 14208 144f45277d5a
parent 14115 65ec3f73d00b
child 14399 dc677b35e54f
permissions -rw-r--r--
misc tidying
     1 (*  Title:      HOL/Hilbert_Choice.thy
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson
     4     Copyright   2001  University of Cambridge
     5 *)
     6 
     7 header {* Hilbert's epsilon-operator and everything to do with the Axiom of Choice *}
     8 
     9 theory Hilbert_Choice = NatArith
    10 files ("Hilbert_Choice_lemmas.ML") ("meson_lemmas.ML") ("Tools/meson.ML") ("Tools/specification_package.ML"):
    11 
    12 
    13 subsection {* Hilbert's epsilon *}
    14 
    15 consts
    16   Eps           :: "('a => bool) => 'a"
    17 
    18 syntax (input)
    19   "_Eps"        :: "[pttrn, bool] => 'a"    ("(3\<epsilon>_./ _)" [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" == "Eps (%x. P)"
    26 
    27 print_translation {*
    28 (* to avoid eta-contraction of body *)
    29 [("Eps", fn [Abs abs] =>
    30      let val (x,t) = atomic_abs_tr' abs
    31      in Syntax.const "_Eps" $ x $ t end)]
    32 *}
    33 
    34 axioms
    35   someI: "P (x::'a) ==> P (SOME x. P x)"
    36 
    37 
    38 constdefs
    39   inv :: "('a => 'b) => ('b => 'a)"
    40   "inv(f :: 'a => 'b) == %y. SOME x. f x = y"
    41 
    42   Inv :: "'a set => ('a => 'b) => ('b => 'a)"
    43   "Inv A f == %x. SOME y. y : A & f y = x"
    44 
    45 
    46 use "Hilbert_Choice_lemmas.ML"
    47 declare someI_ex [elim?];
    48 
    49 lemma Inv_mem: "[| f ` A = B;  x \<in> B |] ==> Inv A f x \<in> A"
    50 apply (unfold Inv_def)
    51 apply (fast intro: someI2)
    52 done
    53 
    54 lemma tfl_some: "\<forall>P x. P x --> P (Eps P)"
    55   -- {* dynamically-scoped fact for TFL *}
    56   by (blast intro: someI)
    57 
    58 
    59 subsection {* Least value operator *}
    60 
    61 constdefs
    62   LeastM :: "['a => 'b::ord, 'a => bool] => 'a"
    63   "LeastM m P == SOME x. P x & (ALL y. P y --> m x <= m y)"
    64 
    65 syntax
    66   "_LeastM" :: "[pttrn, 'a => 'b::ord, bool] => 'a"    ("LEAST _ WRT _. _" [0, 4, 10] 10)
    67 translations
    68   "LEAST x WRT m. P" == "LeastM m (%x. P)"
    69 
    70 lemma LeastMI2:
    71   "P x ==> (!!y. P y ==> m x <= m y)
    72     ==> (!!x. P x ==> \<forall>y. P y --> m x \<le> m y ==> Q x)
    73     ==> Q (LeastM m P)"
    74   apply (unfold LeastM_def)
    75   apply (rule someI2_ex, blast, blast)
    76   done
    77 
    78 lemma LeastM_equality:
    79   "P k ==> (!!x. P x ==> m k <= m x)
    80     ==> m (LEAST x WRT m. P x) = (m k::'a::order)"
    81   apply (rule LeastMI2, assumption, blast)
    82   apply (blast intro!: order_antisym)
    83   done
    84 
    85 lemma wf_linord_ex_has_least:
    86   "wf r ==> ALL x y. ((x,y):r^+) = ((y,x)~:r^*) ==> P k
    87     ==> EX x. P x & (!y. P y --> (m x,m y):r^*)"
    88   apply (drule wf_trancl [THEN wf_eq_minimal [THEN iffD1]])
    89   apply (drule_tac x = "m`Collect P" in spec, force)
    90   done
    91 
    92 lemma ex_has_least_nat:
    93     "P k ==> EX x. P x & (ALL y. P y --> m x <= (m y::nat))"
    94   apply (simp only: pred_nat_trancl_eq_le [symmetric])
    95   apply (rule wf_pred_nat [THEN wf_linord_ex_has_least])
    96    apply (simp add: less_eq not_le_iff_less pred_nat_trancl_eq_le, assumption)
    97   done
    98 
    99 lemma LeastM_nat_lemma:
   100     "P k ==> P (LeastM m P) & (ALL y. P y --> m (LeastM m P) <= (m y::nat))"
   101   apply (unfold LeastM_def)
   102   apply (rule someI_ex)
   103   apply (erule ex_has_least_nat)
   104   done
   105 
   106 lemmas LeastM_natI = LeastM_nat_lemma [THEN conjunct1, standard]
   107 
   108 lemma LeastM_nat_le: "P x ==> m (LeastM m P) <= (m x::nat)"
   109 by (rule LeastM_nat_lemma [THEN conjunct2, THEN spec, THEN mp], assumption, assumption)
   110 
   111 
   112 subsection {* Greatest value operator *}
   113 
   114 constdefs
   115   GreatestM :: "['a => 'b::ord, 'a => bool] => 'a"
   116   "GreatestM m P == SOME x. P x & (ALL y. P y --> m y <= m x)"
   117 
   118   Greatest :: "('a::ord => bool) => 'a"    (binder "GREATEST " 10)
   119   "Greatest == GreatestM (%x. x)"
   120 
   121 syntax
   122   "_GreatestM" :: "[pttrn, 'a=>'b::ord, bool] => 'a"
   123       ("GREATEST _ WRT _. _" [0, 4, 10] 10)
   124 
   125 translations
   126   "GREATEST x WRT m. P" == "GreatestM m (%x. P)"
   127 
   128 lemma GreatestMI2:
   129   "P x ==> (!!y. P y ==> m y <= m x)
   130     ==> (!!x. P x ==> \<forall>y. P y --> m y \<le> m x ==> Q x)
   131     ==> Q (GreatestM m P)"
   132   apply (unfold GreatestM_def)
   133   apply (rule someI2_ex, blast, blast)
   134   done
   135 
   136 lemma GreatestM_equality:
   137  "P k ==> (!!x. P x ==> m x <= m k)
   138     ==> m (GREATEST x WRT m. P x) = (m k::'a::order)"
   139   apply (rule_tac m = m in GreatestMI2, assumption, blast)
   140   apply (blast intro!: order_antisym)
   141   done
   142 
   143 lemma Greatest_equality:
   144   "P (k::'a::order) ==> (!!x. P x ==> x <= k) ==> (GREATEST x. P x) = k"
   145   apply (unfold Greatest_def)
   146   apply (erule GreatestM_equality, blast)
   147   done
   148 
   149 lemma ex_has_greatest_nat_lemma:
   150   "P k ==> ALL x. P x --> (EX y. P y & ~ ((m y::nat) <= m x))
   151     ==> EX y. P y & ~ (m y < m k + n)"
   152   apply (induct_tac n, force)
   153   apply (force simp add: le_Suc_eq)
   154   done
   155 
   156 lemma ex_has_greatest_nat:
   157   "P k ==> ALL y. P y --> m y < b
   158     ==> EX x. P x & (ALL y. P y --> (m y::nat) <= m x)"
   159   apply (rule ccontr)
   160   apply (cut_tac P = P and n = "b - m k" in ex_has_greatest_nat_lemma)
   161     apply (subgoal_tac [3] "m k <= b", auto)
   162   done
   163 
   164 lemma GreatestM_nat_lemma:
   165   "P k ==> ALL y. P y --> m y < b
   166     ==> P (GreatestM m P) & (ALL y. P y --> (m y::nat) <= m (GreatestM m P))"
   167   apply (unfold GreatestM_def)
   168   apply (rule someI_ex)
   169   apply (erule ex_has_greatest_nat, assumption)
   170   done
   171 
   172 lemmas GreatestM_natI = GreatestM_nat_lemma [THEN conjunct1, standard]
   173 
   174 lemma GreatestM_nat_le:
   175   "P x ==> ALL y. P y --> m y < b
   176     ==> (m x::nat) <= m (GreatestM m P)"
   177   apply (blast dest: GreatestM_nat_lemma [THEN conjunct2, THEN spec])
   178   done
   179 
   180 
   181 text {* \medskip Specialization to @{text GREATEST}. *}
   182 
   183 lemma GreatestI: "P (k::nat) ==> ALL y. P y --> y < b ==> P (GREATEST x. P x)"
   184   apply (unfold Greatest_def)
   185   apply (rule GreatestM_natI, auto)
   186   done
   187 
   188 lemma Greatest_le:
   189     "P x ==> ALL y. P y --> y < b ==> (x::nat) <= (GREATEST x. P x)"
   190   apply (unfold Greatest_def)
   191   apply (rule GreatestM_nat_le, auto)
   192   done
   193 
   194 
   195 subsection {* The Meson proof procedure *}
   196 
   197 subsubsection {* Negation Normal Form *}
   198 
   199 text {* de Morgan laws *}
   200 
   201 lemma meson_not_conjD: "~(P&Q) ==> ~P | ~Q"
   202   and meson_not_disjD: "~(P|Q) ==> ~P & ~Q"
   203   and meson_not_notD: "~~P ==> P"
   204   and meson_not_allD: "!!P. ~(ALL x. P(x)) ==> EX x. ~P(x)"
   205   and meson_not_exD: "!!P. ~(EX x. P(x)) ==> ALL x. ~P(x)"
   206   by fast+
   207 
   208 text {* Removal of @{text "-->"} and @{text "<->"} (positive and
   209 negative occurrences) *}
   210 
   211 lemma meson_imp_to_disjD: "P-->Q ==> ~P | Q"
   212   and meson_not_impD: "~(P-->Q) ==> P & ~Q"
   213   and meson_iff_to_disjD: "P=Q ==> (~P | Q) & (~Q | P)"
   214   and meson_not_iffD: "~(P=Q) ==> (P | Q) & (~P | ~Q)"
   215     -- {* Much more efficient than @{prop "(P & ~Q) | (Q & ~P)"} for computing CNF *}
   216   by fast+
   217 
   218 
   219 subsubsection {* Pulling out the existential quantifiers *}
   220 
   221 text {* Conjunction *}
   222 
   223 lemma meson_conj_exD1: "!!P Q. (EX x. P(x)) & Q ==> EX x. P(x) & Q"
   224   and meson_conj_exD2: "!!P Q. P & (EX x. Q(x)) ==> EX x. P & Q(x)"
   225   by fast+
   226 
   227 
   228 text {* Disjunction *}
   229 
   230 lemma meson_disj_exD: "!!P Q. (EX x. P(x)) | (EX x. Q(x)) ==> EX x. P(x) | Q(x)"
   231   -- {* DO NOT USE with forall-Skolemization: makes fewer schematic variables!! *}
   232   -- {* With ex-Skolemization, makes fewer Skolem constants *}
   233   and meson_disj_exD1: "!!P Q. (EX x. P(x)) | Q ==> EX x. P(x) | Q"
   234   and meson_disj_exD2: "!!P Q. P | (EX x. Q(x)) ==> EX x. P | Q(x)"
   235   by fast+
   236 
   237 
   238 subsubsection {* Generating clauses for the Meson Proof Procedure *}
   239 
   240 text {* Disjunctions *}
   241 
   242 lemma meson_disj_assoc: "(P|Q)|R ==> P|(Q|R)"
   243   and meson_disj_comm: "P|Q ==> Q|P"
   244   and meson_disj_FalseD1: "False|P ==> P"
   245   and meson_disj_FalseD2: "P|False ==> P"
   246   by fast+
   247 
   248 use "meson_lemmas.ML"
   249 use "Tools/meson.ML"
   250 setup meson_setup
   251 
   252 use "Tools/specification_package.ML"
   253 
   254 end