src/HOL/Library/Zorn.thy
changeset 26272 d63776c3be97
parent 26191 ae537f315b34
child 26295 afc43168ed85
equal deleted inserted replaced
26271:e324f8918c98 26272:d63776c3be97
     6 *)
     6 *)
     7 
     7 
     8 header {* Zorn's Lemma *}
     8 header {* Zorn's Lemma *}
     9 
     9 
    10 theory Zorn
    10 theory Zorn
    11 imports ATP_Linkup Hilbert_Choice
    11 imports Order_Relation
    12 begin
    12 begin
       
    13 
       
    14 (* Define globally? In Set.thy? *)
       
    15 definition chain_subset :: "'a set set \<Rightarrow> bool" ("chain\<^bsub>\<subseteq>\<^esub>") where
       
    16 "chain\<^bsub>\<subseteq>\<^esub> C \<equiv> \<forall>A\<in>C.\<forall>B\<in>C. A \<subseteq> B \<or> B \<subseteq> A"
    13 
    17 
    14 text{*
    18 text{*
    15   The lemma and section numbers refer to an unpublished article
    19   The lemma and section numbers refer to an unpublished article
    16   \cite{Abrial-Laffitte}.
    20   \cite{Abrial-Laffitte}.
    17 *}
    21 *}
    18 
    22 
    19 definition
    23 definition
    20   chain     ::  "'a set set => 'a set set set" where
    24   chain     ::  "'a set set => 'a set set set" where
    21   "chain S  = {F. F \<subseteq> S & (\<forall>x \<in> F. \<forall>y \<in> F. x \<subseteq> y | y \<subseteq> x)}"
    25   "chain S  = {F. F \<subseteq> S & chain\<^bsub>\<subseteq>\<^esub> F}"
    22 
    26 
    23 definition
    27 definition
    24   super     ::  "['a set set,'a set set] => 'a set set set" where
    28   super     ::  "['a set set,'a set set] => 'a set set set" where
    25   "super S c = {d. d \<in> chain S & c \<subset> d}"
    29   "super S c = {d. d \<in> chain S & c \<subset> d}"
    26 
    30 
   143 
   147 
   144 text{*NB: We assume the partial ordering is @{text "\<subseteq>"},
   148 text{*NB: We assume the partial ordering is @{text "\<subseteq>"},
   145  the subset relation!*}
   149  the subset relation!*}
   146 
   150 
   147 lemma empty_set_mem_chain: "({} :: 'a set set) \<in> chain S"
   151 lemma empty_set_mem_chain: "({} :: 'a set set) \<in> chain S"
   148   by (unfold chain_def) auto
   152 by (unfold chain_def chain_subset_def) auto
   149 
   153 
   150 lemma super_subset_chain: "super S c \<subseteq> chain S"
   154 lemma super_subset_chain: "super S c \<subseteq> chain S"
   151   by (unfold super_def) blast
   155   by (unfold super_def) blast
   152 
   156 
   153 lemma maxchain_subset_chain: "maxchain S \<subseteq> chain S"
   157 lemma maxchain_subset_chain: "maxchain S \<subseteq> chain S"
   179   done
   183   done
   180 
   184 
   181 lemma TFin_chain_lemma4: "c \<in> TFin S ==> (c :: 'a set set): chain S"
   185 lemma TFin_chain_lemma4: "c \<in> TFin S ==> (c :: 'a set set): chain S"
   182   apply (erule TFin_induct)
   186   apply (erule TFin_induct)
   183    apply (simp add: succ_def select_super [THEN super_subset_chain[THEN subsetD]])
   187    apply (simp add: succ_def select_super [THEN super_subset_chain[THEN subsetD]])
   184   apply (unfold chain_def)
   188   apply (unfold chain_def chain_subset_def)
   185   apply (rule CollectI, safe)
   189   apply (rule CollectI, safe)
   186    apply (drule bspec, assumption)
   190    apply (drule bspec, assumption)
   187    apply (rule_tac [2] m1 = Xa and n1 = X in TFin_subset_linear [THEN disjE],
   191    apply (rule_tac [2] m1 = Xa and n1 = X in TFin_subset_linear [THEN disjE],
   188      blast+)
   192      blast+)
   189   done
   193   done
   201 
   205 
   202 subsection{*Zorn's Lemma: If All Chains Have Upper Bounds Then
   206 subsection{*Zorn's Lemma: If All Chains Have Upper Bounds Then
   203                                There Is  a Maximal Element*}
   207                                There Is  a Maximal Element*}
   204 
   208 
   205 lemma chain_extend:
   209 lemma chain_extend:
   206     "[| c \<in> chain S; z \<in> S;
   210   "[| c \<in> chain S; z \<in> S; \<forall>x \<in> c. x \<subseteq> (z:: 'a set) |] ==> {z} Un c \<in> chain S"
   207         \<forall>x \<in> c. x \<subseteq> (z:: 'a set) |] ==> {z} Un c \<in> chain S"
   211 by (unfold chain_def chain_subset_def) blast
   208   by (unfold chain_def) blast
       
   209 
   212 
   210 lemma chain_Union_upper: "[| c \<in> chain S; x \<in> c |] ==> x \<subseteq> Union(c)"
   213 lemma chain_Union_upper: "[| c \<in> chain S; x \<in> c |] ==> x \<subseteq> Union(c)"
   211   by (unfold chain_def) auto
   214 by auto
   212 
   215 
   213 lemma chain_ball_Union_upper: "c \<in> chain S ==> \<forall>x \<in> c. x \<subseteq> Union(c)"
   216 lemma chain_ball_Union_upper: "c \<in> chain S ==> \<forall>x \<in> c. x \<subseteq> Union(c)"
   214   by (unfold chain_def) auto
   217 by auto
   215 
   218 
   216 lemma maxchain_Zorn:
   219 lemma maxchain_Zorn:
   217      "[| c \<in> maxchain S; u \<in> S; Union(c) \<subseteq> u |] ==> Union(c) = u"
   220   "[| c \<in> maxchain S; u \<in> S; Union(c) \<subseteq> u |] ==> Union(c) = u"
   218   apply (rule ccontr)
   221 apply (rule ccontr)
   219   apply (simp add: maxchain_def)
   222 apply (simp add: maxchain_def)
   220   apply (erule conjE)
   223 apply (erule conjE)
   221   apply (subgoal_tac "({u} Un c) \<in> super S c")
   224 apply (subgoal_tac "({u} Un c) \<in> super S c")
   222    apply simp
   225  apply simp
   223   apply (unfold super_def psubset_def)
   226 apply (unfold super_def psubset_def)
   224   apply (blast intro: chain_extend dest: chain_Union_upper)
   227 apply (blast intro: chain_extend dest: chain_Union_upper)
   225   done
   228 done
   226 
   229 
   227 theorem Zorn_Lemma:
   230 theorem Zorn_Lemma:
   228     "\<forall>c \<in> chain S. Union(c): S ==> \<exists>y \<in> S. \<forall>z \<in> S. y \<subseteq> z --> y = z"
   231   "\<forall>c \<in> chain S. Union(c): S ==> \<exists>y \<in> S. \<forall>z \<in> S. y \<subseteq> z --> y = z"
   229   apply (cut_tac Hausdorff maxchain_subset_chain)
   232 apply (cut_tac Hausdorff maxchain_subset_chain)
   230   apply (erule exE)
   233 apply (erule exE)
   231   apply (drule subsetD, assumption)
   234 apply (drule subsetD, assumption)
   232   apply (drule bspec, assumption)
   235 apply (drule bspec, assumption)
   233   apply (rule_tac x = "Union(c)" in bexI)
   236 apply (rule_tac x = "Union(c)" in bexI)
   234    apply (rule ballI, rule impI)
   237  apply (rule ballI, rule impI)
   235    apply (blast dest!: maxchain_Zorn, assumption)
   238  apply (blast dest!: maxchain_Zorn, assumption)
   236   done
   239 done
   237 
   240 
   238 subsection{*Alternative version of Zorn's Lemma*}
   241 subsection{*Alternative version of Zorn's Lemma*}
   239 
   242 
   240 lemma Zorn_Lemma2:
   243 lemma Zorn_Lemma2:
   241   "\<forall>c \<in> chain S. \<exists>y \<in> S. \<forall>x \<in> c. x \<subseteq> y
   244   "\<forall>c \<in> chain S. \<exists>y \<in> S. \<forall>x \<in> c. x \<subseteq> y
   242     ==> \<exists>y \<in> S. \<forall>x \<in> S. (y :: 'a set) \<subseteq> x --> y = x"
   245     ==> \<exists>y \<in> S. \<forall>x \<in> S. (y :: 'a set) \<subseteq> x --> y = x"
   243   apply (cut_tac Hausdorff maxchain_subset_chain)
   246 apply (cut_tac Hausdorff maxchain_subset_chain)
   244   apply (erule exE)
   247 apply (erule exE)
   245   apply (drule subsetD, assumption)
   248 apply (drule subsetD, assumption)
   246   apply (drule bspec, assumption, erule bexE)
   249 apply (drule bspec, assumption, erule bexE)
   247   apply (rule_tac x = y in bexI)
   250 apply (rule_tac x = y in bexI)
   248    prefer 2 apply assumption
   251  prefer 2 apply assumption
   249   apply clarify
   252 apply clarify
   250   apply (rule ccontr)
   253 apply (rule ccontr)
   251   apply (frule_tac z = x in chain_extend)
   254 apply (frule_tac z = x in chain_extend)
   252     apply (assumption, blast)
   255   apply (assumption, blast)
   253   apply (unfold maxchain_def super_def psubset_def)
   256 apply (unfold maxchain_def super_def psubset_def)
   254   apply (blast elim!: equalityCE)
   257 apply (blast elim!: equalityCE)
   255   done
   258 done
   256 
   259 
   257 text{*Various other lemmas*}
   260 text{*Various other lemmas*}
   258 
   261 
   259 lemma chainD: "[| c \<in> chain S; x \<in> c; y \<in> c |] ==> x \<subseteq> y | y \<subseteq> x"
   262 lemma chainD: "[| c \<in> chain S; x \<in> c; y \<in> c |] ==> x \<subseteq> y | y \<subseteq> x"
   260   by (unfold chain_def) blast
   263 by (unfold chain_def chain_subset_def) blast
   261 
   264 
   262 lemma chainD2: "!!(c :: 'a set set). c \<in> chain S ==> c \<subseteq> S"
   265 lemma chainD2: "!!(c :: 'a set set). c \<in> chain S ==> c \<subseteq> S"
   263   by (unfold chain_def) blast
   266 by (unfold chain_def) blast
   264 
   267 
   265 
       
   266 (* FIXME into Relation.thy *)
       
   267 
       
   268 lemma mono_Field: "r \<subseteq> s \<Longrightarrow> Field r \<subseteq> Field s"
       
   269 by(auto simp:Field_def Domain_def Range_def)
       
   270 
       
   271 lemma Field_empty[simp]: "Field {} = {}"
       
   272 by(auto simp:Field_def)
       
   273 
       
   274 lemma Field_insert[simp]: "Field (insert (a,b) r) = {a,b} \<union> Field r"
       
   275 by(auto simp:Field_def)
       
   276 
       
   277 lemma Field_Un[simp]: "Field (r \<union> s) = Field r \<union> Field s"
       
   278 by(auto simp:Field_def)
       
   279 
       
   280 lemma Field_Union[simp]: "Field (\<Union>R) = \<Union>(Field ` R)"
       
   281 by(auto simp:Field_def)
       
   282 
       
   283 lemma Domain_converse[simp]: "Domain(r^-1) = Range r"
       
   284 by blast
       
   285 
       
   286 lemma Range_converse[simp]: "Range(r^-1) = Domain r"
       
   287 by blast
       
   288 
       
   289 lemma Field_converse[simp]: "Field(r^-1) = Field r"
       
   290 by(auto simp:Field_def)
       
   291 
       
   292 lemma reflexive_reflcl[simp]: "reflexive(r^=)"
       
   293 by(simp add:refl_def)
       
   294 
       
   295 lemma antisym_reflcl[simp]: "antisym(r^=) = antisym r"
       
   296 by(simp add:antisym_def)
       
   297 
       
   298 lemma trans_reflclI[simp]: "trans r \<Longrightarrow> trans(r^=)"
       
   299 unfolding trans_def by blast
       
   300 
       
   301 (*********************************************************)
       
   302 
       
   303 (* Define globally? In Set.thy?
       
   304    Use in def of chain at the beginning *)
       
   305 definition "subset_chain C \<equiv> \<forall>A\<in>C.\<forall>B\<in>C. A \<subseteq> B \<or> B \<subseteq> A"
       
   306 
   268 
   307 (* Define globally? In Relation.thy? *)
   269 (* Define globally? In Relation.thy? *)
   308 definition Chain :: "('a*'a)set \<Rightarrow> 'a set set" where
   270 definition Chain :: "('a*'a)set \<Rightarrow> 'a set set" where
   309 "Chain r \<equiv> {A. \<forall>a\<in>A.\<forall>b\<in>A. (a,b) : r \<or> (b,a) \<in> r}"
   271 "Chain r \<equiv> {A. \<forall>a\<in>A.\<forall>b\<in>A. (a,b) : r \<or> (b,a) \<in> r}"
   310 
   272 
   311 lemma mono_Chain: "r \<subseteq> s \<Longrightarrow> Chain r \<subseteq> Chain s"
   273 lemma mono_Chain: "r \<subseteq> s \<Longrightarrow> Chain r \<subseteq> Chain s"
   312 unfolding Chain_def by blast
   274 unfolding Chain_def by blast
   313 
       
   314 (* Are the following definitions the "right" ones?
       
   315 
       
   316 Key point: should the set appear as an explicit argument,
       
   317 (as currently in "refl A r") or should it remain implicitly the Field
       
   318 (as in Refl below)? I use refl/Refl merely to illusrate the point.
       
   319 
       
   320 The notation "refl A r" is closer to the usual (A,<=) in the literature
       
   321 whereas "Refl r" is shorter and avoids naming the set.
       
   322 Note that "refl A r \<Longrightarrow> A = Field r & Refl r" and "Refl r \<Longrightarrow> refl (Field r) r"
       
   323 This makes the A look redundant.
       
   324 
       
   325 A slight advantage of having the A around is that one can write "a:A"
       
   326 rather than "a:Field r". A disavantage is the multiple occurrences of
       
   327 "refl (Field r) r" (etc) in the proof of the well-ordering thm.
       
   328 
       
   329 I propose to move the definitions into Main, either as they are or
       
   330 with an additional A argument.
       
   331 
       
   332 Naming: The capital letters were chosen to distinguish them from
       
   333 versions on the whole type we have (eg reflexive) or may want to have
       
   334 (eg preorder). In case of an additional A argument one could append
       
   335 "_on" to distinguish the relativized versions.
       
   336 *)
       
   337 
       
   338 definition "Refl r \<equiv> \<forall>x \<in> Field r. (x,x) \<in> r"
       
   339 definition "Preorder r \<equiv> Refl r \<and> trans r"
       
   340 definition "Partial_order r \<equiv> Preorder r \<and> antisym r"
       
   341 definition "Total r \<equiv> \<forall>x\<in>Field r.\<forall>y\<in>Field r. x\<noteq>y \<longrightarrow> (x,y)\<in>r \<or> (y,x)\<in>r"
       
   342 definition "Linear_order r \<equiv> Partial_order r \<and> Total r"
       
   343 definition "Well_order r \<equiv> Linear_order r \<and> wf(r - Id)"
       
   344 
       
   345 lemmas Order_defs =
       
   346   Preorder_def Partial_order_def Linear_order_def Well_order_def
       
   347 
       
   348 lemma Refl_empty[simp]: "Refl {}"
       
   349 by(simp add:Refl_def)
       
   350 lemma Preorder_empty[simp]: "Preorder {}"
       
   351 by(simp add:Preorder_def trans_def)
       
   352 lemma Partial_order_empty[simp]: "Partial_order {}"
       
   353 by(simp add:Partial_order_def)
       
   354 lemma Total_empty[simp]: "Total {}"
       
   355 by(simp add:Total_def)
       
   356 lemma Linear_order_empty[simp]: "Linear_order {}"
       
   357 by(simp add:Linear_order_def)
       
   358 lemma Well_order_empty[simp]: "Well_order {}"
       
   359 by(simp add:Well_order_def)
       
   360 
       
   361 lemma Refl_converse[simp]: "Refl(r^-1) = Refl r"
       
   362 by(simp add:Refl_def)
       
   363 
       
   364 lemma Preorder_converse[simp]: "Preorder (r^-1) = Preorder r"
       
   365 by (simp add:Preorder_def)
       
   366 
       
   367 lemma Partial_order_converse[simp]:
       
   368   "Partial_order (r^-1) = Partial_order r"
       
   369 by (simp add: Partial_order_def)
       
   370 
       
   371 lemma subset_Image_Image_iff:
       
   372   "\<lbrakk> Preorder r; A \<subseteq> Field r; B \<subseteq> Field r\<rbrakk> \<Longrightarrow>
       
   373    r `` A \<subseteq> r `` B \<longleftrightarrow> (\<forall>a\<in>A.\<exists>b\<in>B. (b,a):r)"
       
   374 apply(auto simp add:subset_def Preorder_def Refl_def Image_def)
       
   375 apply metis
       
   376 by(metis trans_def)
       
   377 
       
   378 lemma subset_Image1_Image1_iff:
       
   379   "\<lbrakk> Preorder r; a : Field r; b : Field r\<rbrakk> \<Longrightarrow> r `` {a} \<subseteq> r `` {b} \<longleftrightarrow> (b,a):r"
       
   380 by(simp add:subset_Image_Image_iff)
       
   381 
       
   382 lemma Refl_antisym_eq_Image1_Image1_iff:
       
   383   "\<lbrakk>Refl r; antisym r; a:Field r; b:Field r\<rbrakk> \<Longrightarrow> r `` {a} = r `` {b} \<longleftrightarrow> a=b"
       
   384 by(simp add:Preorder_def expand_set_eq Partial_order_def antisym_def Refl_def)
       
   385   metis
       
   386 
       
   387 lemma Partial_order_eq_Image1_Image1_iff:
       
   388   "\<lbrakk>Partial_order r; a:Field r; b:Field r\<rbrakk> \<Longrightarrow> r `` {a} = r `` {b} \<longleftrightarrow> a=b"
       
   389 by(auto simp:Preorder_def Partial_order_def Refl_antisym_eq_Image1_Image1_iff)
       
   390 
   275 
   391 text{* Zorn's lemma for partial orders: *}
   276 text{* Zorn's lemma for partial orders: *}
   392 
   277 
   393 lemma Zorns_po_lemma:
   278 lemma Zorns_po_lemma:
   394 assumes po: "Partial_order r" and u: "\<forall>C\<in>Chain r. \<exists>u\<in>Field r. \<forall>a\<in>C. (a,u):r"
   279 assumes po: "Partial_order r" and u: "\<forall>C\<in>Chain r. \<exists>u\<in>Field r. \<forall>a\<in>C. (a,u):r"
   396 proof-
   281 proof-
   397   have "Preorder r" using po by(simp add:Partial_order_def)
   282   have "Preorder r" using po by(simp add:Partial_order_def)
   398 --{* Mirror r in the set of subsets below (wrt r) elements of A*}
   283 --{* Mirror r in the set of subsets below (wrt r) elements of A*}
   399   let ?B = "%x. r^-1 `` {x}" let ?S = "?B ` Field r"
   284   let ?B = "%x. r^-1 `` {x}" let ?S = "?B ` Field r"
   400   have "\<forall>C \<in> chain ?S. EX U:?S. ALL A:C. A\<subseteq>U"
   285   have "\<forall>C \<in> chain ?S. EX U:?S. ALL A:C. A\<subseteq>U"
   401   proof (auto simp:chain_def)
   286   proof (auto simp:chain_def chain_subset_def)
   402     fix C assume 1: "C \<subseteq> ?S" and 2: "\<forall>A\<in>C.\<forall>B\<in>C. A\<subseteq>B | B\<subseteq>A"
   287     fix C assume 1: "C \<subseteq> ?S" and 2: "\<forall>A\<in>C.\<forall>B\<in>C. A\<subseteq>B | B\<subseteq>A"
   403     let ?A = "{x\<in>Field r. \<exists>M\<in>C. M = ?B x}"
   288     let ?A = "{x\<in>Field r. \<exists>M\<in>C. M = ?B x}"
   404     have "C = ?B ` ?A" using 1 by(auto simp: image_def)
   289     have "C = ?B ` ?A" using 1 by(auto simp: image_def)
   405     have "?A\<in>Chain r"
   290     have "?A\<in>Chain r"
   406     proof (simp add:Chain_def, intro allI impI, elim conjE)
   291     proof (simp add:Chain_def, intro allI impI, elim conjE)
   455 
   340 
   456 lemma Chain_init_seg_of_Union:
   341 lemma Chain_init_seg_of_Union:
   457   "R \<in> Chain init_seg_of \<Longrightarrow> r\<in>R \<Longrightarrow> r initial_segment_of \<Union>R"
   342   "R \<in> Chain init_seg_of \<Longrightarrow> r\<in>R \<Longrightarrow> r initial_segment_of \<Union>R"
   458 by(auto simp add:init_seg_of_def Chain_def Ball_def) blast
   343 by(auto simp add:init_seg_of_def Chain_def Ball_def) blast
   459 
   344 
   460 lemma subset_chain_trans_Union:
   345 lemma chain_subset_trans_Union:
   461   "subset_chain R \<Longrightarrow> \<forall>r\<in>R. trans r \<Longrightarrow> trans(\<Union>R)"
   346   "chain\<^bsub>\<subseteq>\<^esub> R \<Longrightarrow> \<forall>r\<in>R. trans r \<Longrightarrow> trans(\<Union>R)"
   462 apply(auto simp add:subset_chain_def)
   347 apply(auto simp add:chain_subset_def)
   463 apply(simp (no_asm_use) add:trans_def)
   348 apply(simp (no_asm_use) add:trans_def)
   464 apply (metis subsetD)
   349 apply (metis subsetD)
   465 done
   350 done
   466 
   351 
   467 lemma subset_chain_antisym_Union:
   352 lemma chain_subset_antisym_Union:
   468   "subset_chain R \<Longrightarrow> \<forall>r\<in>R. antisym r \<Longrightarrow> antisym(\<Union>R)"
   353   "chain\<^bsub>\<subseteq>\<^esub> R \<Longrightarrow> \<forall>r\<in>R. antisym r \<Longrightarrow> antisym(\<Union>R)"
   469 apply(auto simp add:subset_chain_def antisym_def)
   354 apply(auto simp add:chain_subset_def antisym_def)
   470 apply (metis subsetD)
   355 apply (metis subsetD)
   471 done
   356 done
   472 
   357 
   473 lemma subset_chain_Total_Union:
   358 lemma chain_subset_Total_Union:
   474 assumes "subset_chain R" "\<forall>r\<in>R. Total r"
   359 assumes "chain\<^bsub>\<subseteq>\<^esub> R" "\<forall>r\<in>R. Total r"
   475 shows "Total (\<Union>R)"
   360 shows "Total (\<Union>R)"
   476 proof (simp add: Total_def Ball_def, auto del:disjCI)
   361 proof (simp add: Total_def Ball_def, auto del:disjCI)
   477   fix r s a b assume A: "r:R" "s:R" "a:Field r" "b:Field s" "a\<noteq>b"
   362   fix r s a b assume A: "r:R" "s:R" "a:Field r" "b:Field s" "a\<noteq>b"
   478   from `subset_chain R` `r:R` `s:R` have "r\<subseteq>s \<or> s\<subseteq>r"
   363   from `chain\<^bsub>\<subseteq>\<^esub> R` `r:R` `s:R` have "r\<subseteq>s \<or> s\<subseteq>r"
   479     by(simp add:subset_chain_def)
   364     by(simp add:chain_subset_def)
   480   thus "(\<exists>r\<in>R. (a,b) \<in> r) \<or> (\<exists>r\<in>R. (b,a) \<in> r)"
   365   thus "(\<exists>r\<in>R. (a,b) \<in> r) \<or> (\<exists>r\<in>R. (b,a) \<in> r)"
   481   proof
   366   proof
   482     assume "r\<subseteq>s" hence "(a,b):s \<or> (b,a):s" using assms(2) A
   367     assume "r\<subseteq>s" hence "(a,b):s \<or> (b,a):s" using assms(2) A
   483       by(simp add:Total_def)(metis mono_Field subsetD)
   368       by(simp add:Total_def)(metis mono_Field subsetD)
   484     thus ?thesis using `s:R` by blast
   369     thus ?thesis using `s:R` by blast
   515 apply(auto simp:Chain_def init_seg_of_def)
   400 apply(auto simp:Chain_def init_seg_of_def)
   516 apply (metis subsetD)
   401 apply (metis subsetD)
   517 apply (metis subsetD)
   402 apply (metis subsetD)
   518 done
   403 done
   519 
   404 
   520 theorem well_ordering: "\<exists>r::('a*'a)set. Well_order r"
   405 theorem well_ordering: "\<exists>r::('a*'a)set. Well_order r \<and> Field r = UNIV"
   521 proof-
   406 proof-
   522 -- {*The initial segment relation on well-orders: *}
   407 -- {*The initial segment relation on well-orders: *}
   523   let ?WO = "{r::('a*'a)set. Well_order r}"
   408   let ?WO = "{r::('a*'a)set. Well_order r}"
   524   def I \<equiv> "init_seg_of \<inter> ?WO \<times> ?WO"
   409   def I \<equiv> "init_seg_of \<inter> ?WO \<times> ?WO"
   525   have I_init: "I \<subseteq> init_seg_of" by(auto simp:I_def)
   410   have I_init: "I \<subseteq> init_seg_of" by(auto simp:I_def)
   526   hence subch: "!!R. R : Chain I \<Longrightarrow> subset_chain R"
   411   hence subch: "!!R. R : Chain I \<Longrightarrow> chain\<^bsub>\<subseteq>\<^esub> R"
   527     by(auto simp:init_seg_of_def subset_chain_def Chain_def)
   412     by(auto simp:init_seg_of_def chain_subset_def Chain_def)
   528   have Chain_wo: "!!R r. R \<in> Chain I \<Longrightarrow> r \<in> R \<Longrightarrow> Well_order r"
   413   have Chain_wo: "!!R r. R \<in> Chain I \<Longrightarrow> r \<in> R \<Longrightarrow> Well_order r"
   529     by(simp add:Chain_def I_def) blast
   414     by(simp add:Chain_def I_def) blast
   530   have FI: "Field I = ?WO" by(auto simp add:I_def init_seg_of_def Field_def)
   415   have FI: "Field I = ?WO" by(auto simp add:I_def init_seg_of_def Field_def)
   531   hence 0: "Partial_order I"
   416   hence 0: "Partial_order I"
   532     by(auto simp add: Partial_order_def Preorder_def antisym_def antisym_init_seg_of Refl_def trans_def I_def)(metis trans_init_seg_of)
   417     by(auto simp add: Partial_order_def Preorder_def antisym_def antisym_init_seg_of Refl_def trans_def I_def)(metis trans_init_seg_of)
   533 -- {*I-chains have upper bounds in ?WO wrt I: their Union*}
   418 -- {*I-chains have upper bounds in ?WO wrt I: their Union*}
   534   { fix R assume "R \<in> Chain I"
   419   { fix R assume "R \<in> Chain I"
   535     hence Ris: "R \<in> Chain init_seg_of" using mono_Chain[OF I_init] by blast
   420     hence Ris: "R \<in> Chain init_seg_of" using mono_Chain[OF I_init] by blast
   536     have subch: "subset_chain R" using `R : Chain I` I_init
   421     have subch: "chain\<^bsub>\<subseteq>\<^esub> R" using `R : Chain I` I_init
   537       by(auto simp:init_seg_of_def subset_chain_def Chain_def)
   422       by(auto simp:init_seg_of_def chain_subset_def Chain_def)
   538     have "\<forall>r\<in>R. Refl r" "\<forall>r\<in>R. trans r" "\<forall>r\<in>R. antisym r" "\<forall>r\<in>R. Total r"
   423     have "\<forall>r\<in>R. Refl r" "\<forall>r\<in>R. trans r" "\<forall>r\<in>R. antisym r" "\<forall>r\<in>R. Total r"
   539          "\<forall>r\<in>R. wf(r-Id)"
   424          "\<forall>r\<in>R. wf(r-Id)"
   540       using Chain_wo[OF `R \<in> Chain I`] by(simp_all add:Order_defs)
   425       using Chain_wo[OF `R \<in> Chain I`] by(simp_all add:Order_defs)
   541     have "Refl (\<Union>R)" using `\<forall>r\<in>R. Refl r` by(auto simp:Refl_def)
   426     have "Refl (\<Union>R)" using `\<forall>r\<in>R. Refl r` by(auto simp:Refl_def)
   542     moreover have "trans (\<Union>R)"
   427     moreover have "trans (\<Union>R)"
   543       by(rule subset_chain_trans_Union[OF subch `\<forall>r\<in>R. trans r`])
   428       by(rule chain_subset_trans_Union[OF subch `\<forall>r\<in>R. trans r`])
   544     moreover have "antisym(\<Union>R)"
   429     moreover have "antisym(\<Union>R)"
   545       by(rule subset_chain_antisym_Union[OF subch `\<forall>r\<in>R. antisym r`])
   430       by(rule chain_subset_antisym_Union[OF subch `\<forall>r\<in>R. antisym r`])
   546     moreover have "Total (\<Union>R)"
   431     moreover have "Total (\<Union>R)"
   547       by(rule subset_chain_Total_Union[OF subch `\<forall>r\<in>R. Total r`])
   432       by(rule chain_subset_Total_Union[OF subch `\<forall>r\<in>R. Total r`])
   548     moreover have "wf((\<Union>R)-Id)"
   433     moreover have "wf((\<Union>R)-Id)"
   549     proof-
   434     proof-
   550       have "(\<Union>R)-Id = \<Union>{r-Id|r. r \<in> R}" by blast
   435       have "(\<Union>R)-Id = \<Union>{r-Id|r. r \<in> R}" by blast
   551       with `\<forall>r\<in>R. wf(r-Id)` wf_Union_wf_init_segs[OF Chain_inits_DiffI[OF Ris]]
   436       with `\<forall>r\<in>R. wf(r-Id)` wf_Union_wf_init_segs[OF Chain_inits_DiffI[OF Ris]]
   552       show ?thesis by (simp (no_asm_simp)) blast
   437       show ?thesis by (simp (no_asm_simp)) blast
   605     ultimately
   490     ultimately
   606 --{*This contradicts maximality of m:*}
   491 --{*This contradicts maximality of m:*}
   607     have False using max `x \<notin> Field m` unfolding Field_def by blast
   492     have False using max `x \<notin> Field m` unfolding Field_def by blast
   608   }
   493   }
   609   hence "Field m = UNIV" by auto
   494   hence "Field m = UNIV" by auto
   610   with `Well_order m` have "Well_order m" by simp
   495   moreover with `Well_order m` have "Well_order m" by simp
   611   thus ?thesis ..
   496   ultimately show ?thesis by blast
   612 qed
   497 qed
   613 
   498 
       
   499 corollary well_ordering_set: "\<exists>r::('a*'a)set. Well_order r \<and> Field r = A"
       
   500 proof -
       
   501   obtain r::"('a*'a)set" where wo: "Well_order r" and univ: "Field r = UNIV"
       
   502     using well_ordering[where 'a = "'a"] by blast
       
   503   let ?r = "{(x,y). x:A & y:A & (x,y):r}"
       
   504   have 1: "Field ?r = A" using wo univ
       
   505     by(fastsimp simp: Field_def Domain_def Range_def Order_defs Refl_def)
       
   506   have "Refl r" "trans r" "antisym r" "Total r" "wf(r-Id)"
       
   507     using `Well_order r` by(simp_all add:Order_defs)
       
   508   have "Refl ?r" using `Refl r` by(auto simp:Refl_def 1 univ)
       
   509   moreover have "trans ?r" using `trans r`
       
   510     unfolding trans_def by blast
       
   511   moreover have "antisym ?r" using `antisym r`
       
   512     unfolding antisym_def by blast
       
   513   moreover have "Total ?r" using `Total r` by(simp add:Total_def 1 univ)
       
   514   moreover have "wf(?r - Id)" by(rule wf_subset[OF `wf(r-Id)`]) blast
       
   515   ultimately have "Well_order ?r" by(simp add:Order_defs)
       
   516   with 1 show ?thesis by blast
       
   517 qed
       
   518 
   614 end
   519 end