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