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