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