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