src/HOL/Hilbert_Choice.thy
 author skalberg Thu Jul 17 15:23:20 2003 +0200 (2003-07-17) changeset 14115 65ec3f73d00b parent 13764 3e180bf68496 child 14208 144f45277d5a permissions -rw-r--r--
Added package for definition by specification.
```     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)
```
```    76    apply blast
```
```    77   apply blast
```
```    78   done
```
```    79
```
```    80 lemma LeastM_equality:
```
```    81   "P k ==> (!!x. P x ==> m k <= m x)
```
```    82     ==> m (LEAST x WRT m. P x) = (m k::'a::order)"
```
```    83   apply (rule LeastMI2)
```
```    84     apply assumption
```
```    85    apply blast
```
```    86   apply (blast intro!: order_antisym)
```
```    87   done
```
```    88
```
```    89 lemma wf_linord_ex_has_least:
```
```    90   "wf r ==> ALL x y. ((x,y):r^+) = ((y,x)~:r^*) ==> P k
```
```    91     ==> EX x. P x & (!y. P y --> (m x,m y):r^*)"
```
```    92   apply (drule wf_trancl [THEN wf_eq_minimal [THEN iffD1]])
```
```    93   apply (drule_tac x = "m`Collect P" in spec)
```
```    94   apply force
```
```    95   done
```
```    96
```
```    97 lemma ex_has_least_nat:
```
```    98     "P k ==> EX x. P x & (ALL y. P y --> m x <= (m y::nat))"
```
```    99   apply (simp only: pred_nat_trancl_eq_le [symmetric])
```
```   100   apply (rule wf_pred_nat [THEN wf_linord_ex_has_least])
```
```   101    apply (simp add: less_eq not_le_iff_less pred_nat_trancl_eq_le)
```
```   102   apply assumption
```
```   103   done
```
```   104
```
```   105 lemma LeastM_nat_lemma:
```
```   106     "P k ==> P (LeastM m P) & (ALL y. P y --> m (LeastM m P) <= (m y::nat))"
```
```   107   apply (unfold LeastM_def)
```
```   108   apply (rule someI_ex)
```
```   109   apply (erule ex_has_least_nat)
```
```   110   done
```
```   111
```
```   112 lemmas LeastM_natI = LeastM_nat_lemma [THEN conjunct1, standard]
```
```   113
```
```   114 lemma LeastM_nat_le: "P x ==> m (LeastM m P) <= (m x::nat)"
```
```   115   apply (rule LeastM_nat_lemma [THEN conjunct2, THEN spec, THEN mp])
```
```   116    apply assumption
```
```   117   apply assumption
```
```   118   done
```
```   119
```
```   120
```
```   121 subsection {* Greatest value operator *}
```
```   122
```
```   123 constdefs
```
```   124   GreatestM :: "['a => 'b::ord, 'a => bool] => 'a"
```
```   125   "GreatestM m P == SOME x. P x & (ALL y. P y --> m y <= m x)"
```
```   126
```
```   127   Greatest :: "('a::ord => bool) => 'a"    (binder "GREATEST " 10)
```
```   128   "Greatest == GreatestM (%x. x)"
```
```   129
```
```   130 syntax
```
```   131   "_GreatestM" :: "[pttrn, 'a=>'b::ord, bool] => 'a"
```
```   132       ("GREATEST _ WRT _. _" [0, 4, 10] 10)
```
```   133
```
```   134 translations
```
```   135   "GREATEST x WRT m. P" == "GreatestM m (%x. P)"
```
```   136
```
```   137 lemma GreatestMI2:
```
```   138   "P x ==> (!!y. P y ==> m y <= m x)
```
```   139     ==> (!!x. P x ==> \<forall>y. P y --> m y \<le> m x ==> Q x)
```
```   140     ==> Q (GreatestM m P)"
```
```   141   apply (unfold GreatestM_def)
```
```   142   apply (rule someI2_ex)
```
```   143    apply blast
```
```   144   apply blast
```
```   145   done
```
```   146
```
```   147 lemma GreatestM_equality:
```
```   148  "P k ==> (!!x. P x ==> m x <= m k)
```
```   149     ==> m (GREATEST x WRT m. P x) = (m k::'a::order)"
```
```   150   apply (rule_tac m = m in GreatestMI2)
```
```   151     apply assumption
```
```   152    apply blast
```
```   153   apply (blast intro!: order_antisym)
```
```   154   done
```
```   155
```
```   156 lemma Greatest_equality:
```
```   157   "P (k::'a::order) ==> (!!x. P x ==> x <= k) ==> (GREATEST x. P x) = k"
```
```   158   apply (unfold Greatest_def)
```
```   159   apply (erule GreatestM_equality)
```
```   160   apply blast
```
```   161   done
```
```   162
```
```   163 lemma ex_has_greatest_nat_lemma:
```
```   164   "P k ==> ALL x. P x --> (EX y. P y & ~ ((m y::nat) <= m x))
```
```   165     ==> EX y. P y & ~ (m y < m k + n)"
```
```   166   apply (induct_tac n)
```
```   167    apply force
```
```   168   apply (force simp add: le_Suc_eq)
```
```   169   done
```
```   170
```
```   171 lemma ex_has_greatest_nat:
```
```   172   "P k ==> ALL y. P y --> m y < b
```
```   173     ==> EX x. P x & (ALL y. P y --> (m y::nat) <= m x)"
```
```   174   apply (rule ccontr)
```
```   175   apply (cut_tac P = P and n = "b - m k" in ex_has_greatest_nat_lemma)
```
```   176     apply (subgoal_tac [3] "m k <= b")
```
```   177      apply auto
```
```   178   done
```
```   179
```
```   180 lemma GreatestM_nat_lemma:
```
```   181   "P k ==> ALL y. P y --> m y < b
```
```   182     ==> P (GreatestM m P) & (ALL y. P y --> (m y::nat) <= m (GreatestM m P))"
```
```   183   apply (unfold GreatestM_def)
```
```   184   apply (rule someI_ex)
```
```   185   apply (erule ex_has_greatest_nat)
```
```   186   apply assumption
```
```   187   done
```
```   188
```
```   189 lemmas GreatestM_natI = GreatestM_nat_lemma [THEN conjunct1, standard]
```
```   190
```
```   191 lemma GreatestM_nat_le:
```
```   192   "P x ==> ALL y. P y --> m y < b
```
```   193     ==> (m x::nat) <= m (GreatestM m P)"
```
```   194   apply (blast dest: GreatestM_nat_lemma [THEN conjunct2, THEN spec])
```
```   195   done
```
```   196
```
```   197
```
```   198 text {* \medskip Specialization to @{text GREATEST}. *}
```
```   199
```
```   200 lemma GreatestI: "P (k::nat) ==> ALL y. P y --> y < b ==> P (GREATEST x. P x)"
```
```   201   apply (unfold Greatest_def)
```
```   202   apply (rule GreatestM_natI)
```
```   203    apply auto
```
```   204   done
```
```   205
```
```   206 lemma Greatest_le:
```
```   207     "P x ==> ALL y. P y --> y < b ==> (x::nat) <= (GREATEST x. P x)"
```
```   208   apply (unfold Greatest_def)
```
```   209   apply (rule GreatestM_nat_le)
```
```   210    apply auto
```
```   211   done
```
```   212
```
```   213
```
```   214 subsection {* The Meson proof procedure *}
```
```   215
```
```   216 subsubsection {* Negation Normal Form *}
```
```   217
```
```   218 text {* de Morgan laws *}
```
```   219
```
```   220 lemma meson_not_conjD: "~(P&Q) ==> ~P | ~Q"
```
```   221   and meson_not_disjD: "~(P|Q) ==> ~P & ~Q"
```
```   222   and meson_not_notD: "~~P ==> P"
```
```   223   and meson_not_allD: "!!P. ~(ALL x. P(x)) ==> EX x. ~P(x)"
```
```   224   and meson_not_exD: "!!P. ~(EX x. P(x)) ==> ALL x. ~P(x)"
```
```   225   by fast+
```
```   226
```
```   227 text {* Removal of @{text "-->"} and @{text "<->"} (positive and
```
```   228 negative occurrences) *}
```
```   229
```
```   230 lemma meson_imp_to_disjD: "P-->Q ==> ~P | Q"
```
```   231   and meson_not_impD: "~(P-->Q) ==> P & ~Q"
```
```   232   and meson_iff_to_disjD: "P=Q ==> (~P | Q) & (~Q | P)"
```
```   233   and meson_not_iffD: "~(P=Q) ==> (P | Q) & (~P | ~Q)"
```
```   234     -- {* Much more efficient than @{prop "(P & ~Q) | (Q & ~P)"} for computing CNF *}
```
```   235   by fast+
```
```   236
```
```   237
```
```   238 subsubsection {* Pulling out the existential quantifiers *}
```
```   239
```
```   240 text {* Conjunction *}
```
```   241
```
```   242 lemma meson_conj_exD1: "!!P Q. (EX x. P(x)) & Q ==> EX x. P(x) & Q"
```
```   243   and meson_conj_exD2: "!!P Q. P & (EX x. Q(x)) ==> EX x. P & Q(x)"
```
```   244   by fast+
```
```   245
```
```   246
```
```   247 text {* Disjunction *}
```
```   248
```
```   249 lemma meson_disj_exD: "!!P Q. (EX x. P(x)) | (EX x. Q(x)) ==> EX x. P(x) | Q(x)"
```
```   250   -- {* DO NOT USE with forall-Skolemization: makes fewer schematic variables!! *}
```
```   251   -- {* With ex-Skolemization, makes fewer Skolem constants *}
```
```   252   and meson_disj_exD1: "!!P Q. (EX x. P(x)) | Q ==> EX x. P(x) | Q"
```
```   253   and meson_disj_exD2: "!!P Q. P | (EX x. Q(x)) ==> EX x. P | Q(x)"
```
```   254   by fast+
```
```   255
```
```   256
```
```   257 subsubsection {* Generating clauses for the Meson Proof Procedure *}
```
```   258
```
```   259 text {* Disjunctions *}
```
```   260
```
```   261 lemma meson_disj_assoc: "(P|Q)|R ==> P|(Q|R)"
```
```   262   and meson_disj_comm: "P|Q ==> Q|P"
```
```   263   and meson_disj_FalseD1: "False|P ==> P"
```
```   264   and meson_disj_FalseD2: "P|False ==> P"
```
```   265   by fast+
```
```   266
```
```   267 use "meson_lemmas.ML"
```
```   268 use "Tools/meson.ML"
```
```   269 setup meson_setup
```
```   270
```
```   271 use "Tools/specification_package.ML"
```
```   272
```
```   273 end
```