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