src/HOL/Library/Zorn.thy
author huffman
Wed Feb 17 10:30:36 2010 -0800 (2010-02-17)
changeset 35175 61255c81da01
parent 32960 69916a850301
child 44890 22f665a2e91c
permissions -rw-r--r--
fix more looping simp rules
     1 (*  Title:      HOL/Library/Zorn.thy
     2     Author:     Jacques D. Fleuriot, Tobias Nipkow
     3 
     4 Zorn's Lemma (ported from Larry Paulson's Zorn.thy in ZF).
     5 The well-ordering theorem.
     6 *)
     7 
     8 header {* Zorn's Lemma *}
     9 
    10 theory Zorn
    11 imports Order_Relation Main
    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"
    17 
    18 text{*
    19   The lemma and section numbers refer to an unpublished article
    20   \cite{Abrial-Laffitte}.
    21 *}
    22 
    23 definition
    24   chain     ::  "'a set set => 'a set set set" where
    25   "chain S  = {F. F \<subseteq> S & chain\<^bsub>\<subseteq>\<^esub> F}"
    26 
    27 definition
    28   super     ::  "['a set set,'a set set] => 'a set set set" where
    29   "super S c = {d. d \<in> chain S & c \<subset> d}"
    30 
    31 definition
    32   maxchain  ::  "'a set set => 'a set set set" where
    33   "maxchain S = {c. c \<in> chain S & super S c = {}}"
    34 
    35 definition
    36   succ      ::  "['a set set,'a set set] => 'a set set" where
    37   "succ S c =
    38     (if c \<notin> chain S | c \<in> maxchain S
    39     then c else SOME c'. c' \<in> super S c)"
    40 
    41 inductive_set
    42   TFin :: "'a set set => 'a set set set"
    43   for S :: "'a set set"
    44   where
    45     succI:        "x \<in> TFin S ==> succ S x \<in> TFin S"
    46   | Pow_UnionI:   "Y \<in> Pow(TFin S) ==> Union(Y) \<in> TFin S"
    47 
    48 
    49 subsection{*Mathematical Preamble*}
    50 
    51 lemma Union_lemma0:
    52     "(\<forall>x \<in> C. x \<subseteq> A | B \<subseteq> x) ==> Union(C) \<subseteq> A | B \<subseteq> Union(C)"
    53   by blast
    54 
    55 
    56 text{*This is theorem @{text increasingD2} of ZF/Zorn.thy*}
    57 
    58 lemma Abrial_axiom1: "x \<subseteq> succ S x"
    59   apply (auto simp add: succ_def super_def maxchain_def)
    60   apply (rule contrapos_np, assumption)
    61   apply (rule_tac Q="\<lambda>S. xa \<in> S" in someI2, blast+)
    62   done
    63 
    64 lemmas TFin_UnionI = TFin.Pow_UnionI [OF PowI]
    65 
    66 lemma TFin_induct:
    67   assumes H: "n \<in> TFin S"
    68   and I: "!!x. x \<in> TFin S ==> P x ==> P (succ S x)"
    69     "!!Y. Y \<subseteq> TFin S ==> Ball Y P ==> P(Union Y)"
    70   shows "P n" using H
    71   apply (induct rule: TFin.induct [where P=P])
    72    apply (blast intro: I)+
    73   done
    74 
    75 lemma succ_trans: "x \<subseteq> y ==> x \<subseteq> succ S y"
    76   apply (erule subset_trans)
    77   apply (rule Abrial_axiom1)
    78   done
    79 
    80 text{*Lemma 1 of section 3.1*}
    81 lemma TFin_linear_lemma1:
    82      "[| n \<in> TFin S;  m \<in> TFin S;
    83          \<forall>x \<in> TFin S. x \<subseteq> m --> x = m | succ S x \<subseteq> m
    84       |] ==> n \<subseteq> m | succ S m \<subseteq> n"
    85   apply (erule TFin_induct)
    86    apply (erule_tac [2] Union_lemma0)
    87   apply (blast del: subsetI intro: succ_trans)
    88   done
    89 
    90 text{* Lemma 2 of section 3.2 *}
    91 lemma TFin_linear_lemma2:
    92      "m \<in> TFin S ==> \<forall>n \<in> TFin S. n \<subseteq> m --> n=m | succ S n \<subseteq> m"
    93   apply (erule TFin_induct)
    94    apply (rule impI [THEN ballI])
    95    txt{*case split using @{text TFin_linear_lemma1}*}
    96    apply (rule_tac n1 = n and m1 = x in TFin_linear_lemma1 [THEN disjE],
    97      assumption+)
    98     apply (drule_tac x = n in bspec, assumption)
    99     apply (blast del: subsetI intro: succ_trans, blast)
   100   txt{*second induction step*}
   101   apply (rule impI [THEN ballI])
   102   apply (rule Union_lemma0 [THEN disjE])
   103     apply (rule_tac [3] disjI2)
   104     prefer 2 apply blast
   105    apply (rule ballI)
   106    apply (rule_tac n1 = n and m1 = x in TFin_linear_lemma1 [THEN disjE],
   107      assumption+, auto)
   108   apply (blast intro!: Abrial_axiom1 [THEN subsetD])
   109   done
   110 
   111 text{*Re-ordering the premises of Lemma 2*}
   112 lemma TFin_subsetD:
   113      "[| n \<subseteq> m;  m \<in> TFin S;  n \<in> TFin S |] ==> n=m | succ S n \<subseteq> m"
   114   by (rule TFin_linear_lemma2 [rule_format])
   115 
   116 text{*Consequences from section 3.3 -- Property 3.2, the ordering is total*}
   117 lemma TFin_subset_linear: "[| m \<in> TFin S;  n \<in> TFin S|] ==> n \<subseteq> m | m \<subseteq> n"
   118   apply (rule disjE)
   119     apply (rule TFin_linear_lemma1 [OF _ _TFin_linear_lemma2])
   120       apply (assumption+, erule disjI2)
   121   apply (blast del: subsetI
   122     intro: subsetI Abrial_axiom1 [THEN subset_trans])
   123   done
   124 
   125 text{*Lemma 3 of section 3.3*}
   126 lemma eq_succ_upper: "[| n \<in> TFin S;  m \<in> TFin S;  m = succ S m |] ==> n \<subseteq> m"
   127   apply (erule TFin_induct)
   128    apply (drule TFin_subsetD)
   129      apply (assumption+, force, blast)
   130   done
   131 
   132 text{*Property 3.3 of section 3.3*}
   133 lemma equal_succ_Union: "m \<in> TFin S ==> (m = succ S m) = (m = Union(TFin S))"
   134   apply (rule iffI)
   135    apply (rule Union_upper [THEN equalityI])
   136     apply assumption
   137    apply (rule eq_succ_upper [THEN Union_least], assumption+)
   138   apply (erule ssubst)
   139   apply (rule Abrial_axiom1 [THEN equalityI])
   140   apply (blast del: subsetI intro: subsetI TFin_UnionI TFin.succI)
   141   done
   142 
   143 subsection{*Hausdorff's Theorem: Every Set Contains a Maximal Chain.*}
   144 
   145 text{*NB: We assume the partial ordering is @{text "\<subseteq>"},
   146  the subset relation!*}
   147 
   148 lemma empty_set_mem_chain: "({} :: 'a set set) \<in> chain S"
   149 by (unfold chain_def chain_subset_def) auto
   150 
   151 lemma super_subset_chain: "super S c \<subseteq> chain S"
   152   by (unfold super_def) blast
   153 
   154 lemma maxchain_subset_chain: "maxchain S \<subseteq> chain S"
   155   by (unfold maxchain_def) blast
   156 
   157 lemma mem_super_Ex: "c \<in> chain S - maxchain S ==> EX d. d \<in> super S c"
   158   by (unfold super_def maxchain_def) auto
   159 
   160 lemma select_super:
   161      "c \<in> chain S - maxchain S ==> (\<some>c'. c': super S c): super S c"
   162   apply (erule mem_super_Ex [THEN exE])
   163   apply (rule someI2 [where Q="%X. X : super S c"], auto)
   164   done
   165 
   166 lemma select_not_equals:
   167      "c \<in> chain S - maxchain S ==> (\<some>c'. c': super S c) \<noteq> c"
   168   apply (rule notI)
   169   apply (drule select_super)
   170   apply (simp add: super_def less_le)
   171   done
   172 
   173 lemma succI3: "c \<in> chain S - maxchain S ==> succ S c = (\<some>c'. c': super S c)"
   174   by (unfold succ_def) (blast intro!: if_not_P)
   175 
   176 lemma succ_not_equals: "c \<in> chain S - maxchain S ==> succ S c \<noteq> c"
   177   apply (frule succI3)
   178   apply (simp (no_asm_simp))
   179   apply (rule select_not_equals, assumption)
   180   done
   181 
   182 lemma TFin_chain_lemma4: "c \<in> TFin S ==> (c :: 'a set set): chain S"
   183   apply (erule TFin_induct)
   184    apply (simp add: succ_def select_super [THEN super_subset_chain[THEN subsetD]])
   185   apply (unfold chain_def chain_subset_def)
   186   apply (rule CollectI, safe)
   187    apply (drule bspec, assumption)
   188    apply (rule_tac [2] m1 = Xa and n1 = X in TFin_subset_linear [THEN disjE],
   189      best+)
   190   done
   191 
   192 theorem Hausdorff: "\<exists>c. (c :: 'a set set): maxchain S"
   193   apply (rule_tac x = "Union (TFin S)" in exI)
   194   apply (rule classical)
   195   apply (subgoal_tac "succ S (Union (TFin S)) = Union (TFin S) ")
   196    prefer 2
   197    apply (blast intro!: TFin_UnionI equal_succ_Union [THEN iffD2, symmetric])
   198   apply (cut_tac subset_refl [THEN TFin_UnionI, THEN TFin_chain_lemma4])
   199   apply (drule DiffI [THEN succ_not_equals], blast+)
   200   done
   201 
   202 
   203 subsection{*Zorn's Lemma: If All Chains Have Upper Bounds Then
   204                                There Is  a Maximal Element*}
   205 
   206 lemma chain_extend:
   207   "[| c \<in> chain S; z \<in> S; \<forall>x \<in> c. x \<subseteq> (z:: 'a set) |] ==> {z} Un c \<in> chain S"
   208 by (unfold chain_def chain_subset_def) blast
   209 
   210 lemma chain_Union_upper: "[| c \<in> chain S; x \<in> c |] ==> x \<subseteq> Union(c)"
   211 by auto
   212 
   213 lemma chain_ball_Union_upper: "c \<in> chain S ==> \<forall>x \<in> c. x \<subseteq> Union(c)"
   214 by auto
   215 
   216 lemma maxchain_Zorn:
   217   "[| c \<in> maxchain S; u \<in> S; Union(c) \<subseteq> u |] ==> Union(c) = u"
   218 apply (rule ccontr)
   219 apply (simp add: maxchain_def)
   220 apply (erule conjE)
   221 apply (subgoal_tac "({u} Un c) \<in> super S c")
   222  apply simp
   223 apply (unfold super_def less_le)
   224 apply (blast intro: chain_extend dest: chain_Union_upper)
   225 done
   226 
   227 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"
   229 apply (cut_tac Hausdorff maxchain_subset_chain)
   230 apply (erule exE)
   231 apply (drule subsetD, assumption)
   232 apply (drule bspec, assumption)
   233 apply (rule_tac x = "Union(c)" in bexI)
   234  apply (rule ballI, rule impI)
   235  apply (blast dest!: maxchain_Zorn, assumption)
   236 done
   237 
   238 subsection{*Alternative version of Zorn's Lemma*}
   239 
   240 lemma Zorn_Lemma2:
   241   "\<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"
   243 apply (cut_tac Hausdorff maxchain_subset_chain)
   244 apply (erule exE)
   245 apply (drule subsetD, assumption)
   246 apply (drule bspec, assumption, erule bexE)
   247 apply (rule_tac x = y in bexI)
   248  prefer 2 apply assumption
   249 apply clarify
   250 apply (rule ccontr)
   251 apply (frule_tac z = x in chain_extend)
   252   apply (assumption, blast)
   253 apply (unfold maxchain_def super_def less_le)
   254 apply (blast elim!: equalityCE)
   255 done
   256 
   257 text{*Various other lemmas*}
   258 
   259 lemma chainD: "[| c \<in> chain S; x \<in> c; y \<in> c |] ==> x \<subseteq> y | y \<subseteq> x"
   260 by (unfold chain_def chain_subset_def) blast
   261 
   262 lemma chainD2: "!!(c :: 'a set set). c \<in> chain S ==> c \<subseteq> S"
   263 by (unfold chain_def) blast
   264 
   265 
   266 (* Define globally? In Relation.thy? *)
   267 definition Chain :: "('a*'a)set \<Rightarrow> 'a set set" where
   268 "Chain r \<equiv> {A. \<forall>a\<in>A.\<forall>b\<in>A. (a,b) : r \<or> (b,a) \<in> r}"
   269 
   270 lemma mono_Chain: "r \<subseteq> s \<Longrightarrow> Chain r \<subseteq> Chain s"
   271 unfolding Chain_def by blast
   272 
   273 text{* Zorn's lemma for partial orders: *}
   274 
   275 lemma Zorns_po_lemma:
   276 assumes po: "Partial_order r" and u: "\<forall>C\<in>Chain r. \<exists>u\<in>Field r. \<forall>a\<in>C. (a,u):r"
   277 shows "\<exists>m\<in>Field r. \<forall>a\<in>Field r. (m,a):r \<longrightarrow> a=m"
   278 proof-
   279   have "Preorder r" using po by(simp add:partial_order_on_def)
   280 --{* Mirror r in the set of subsets below (wrt r) elements of A*}
   281   let ?B = "%x. r^-1 `` {x}" let ?S = "?B ` Field r"
   282   have "\<forall>C \<in> chain ?S. EX U:?S. ALL A:C. A\<subseteq>U"
   283   proof (auto simp:chain_def chain_subset_def)
   284     fix C assume 1: "C \<subseteq> ?S" and 2: "\<forall>A\<in>C.\<forall>B\<in>C. A\<subseteq>B | B\<subseteq>A"
   285     let ?A = "{x\<in>Field r. \<exists>M\<in>C. M = ?B x}"
   286     have "C = ?B ` ?A" using 1 by(auto simp: image_def)
   287     have "?A\<in>Chain r"
   288     proof (simp add:Chain_def, intro allI impI, elim conjE)
   289       fix a b
   290       assume "a \<in> Field r" "?B a \<in> C" "b \<in> Field r" "?B b \<in> C"
   291       hence "?B a \<subseteq> ?B b \<or> ?B b \<subseteq> ?B a" using 2 by auto
   292       thus "(a, b) \<in> r \<or> (b, a) \<in> r" using `Preorder r` `a:Field r` `b:Field r`
   293         by (simp add:subset_Image1_Image1_iff)
   294     qed
   295     then obtain u where uA: "u:Field r" "\<forall>a\<in>?A. (a,u) : r" using u by auto
   296     have "\<forall>A\<in>C. A \<subseteq> r^-1 `` {u}" (is "?P u")
   297     proof auto
   298       fix a B assume aB: "B:C" "a:B"
   299       with 1 obtain x where "x:Field r" "B = r^-1 `` {x}" by auto
   300       thus "(a,u) : r" using uA aB `Preorder r`
   301         by (auto simp add: preorder_on_def refl_on_def) (metis transD)
   302     qed
   303     thus "EX u:Field r. ?P u" using `u:Field r` by blast
   304   qed
   305   from Zorn_Lemma2[OF this]
   306   obtain m B where "m:Field r" "B = r^-1 `` {m}"
   307     "\<forall>x\<in>Field r. B \<subseteq> r^-1 `` {x} \<longrightarrow> B = r^-1 `` {x}"
   308     by auto
   309   hence "\<forall>a\<in>Field r. (m, a) \<in> r \<longrightarrow> a = m" using po `Preorder r` `m:Field r`
   310     by(auto simp:subset_Image1_Image1_iff Partial_order_eq_Image1_Image1_iff)
   311   thus ?thesis using `m:Field r` by blast
   312 qed
   313 
   314 (* The initial segment of a relation appears generally useful.
   315    Move to Relation.thy?
   316    Definition correct/most general?
   317    Naming?
   318 *)
   319 definition init_seg_of :: "(('a*'a)set * ('a*'a)set)set" where
   320 "init_seg_of == {(r,s). r \<subseteq> s \<and> (\<forall>a b c. (a,b):s \<and> (b,c):r \<longrightarrow> (a,b):r)}"
   321 
   322 abbreviation initialSegmentOf :: "('a*'a)set \<Rightarrow> ('a*'a)set \<Rightarrow> bool"
   323              (infix "initial'_segment'_of" 55) where
   324 "r initial_segment_of s == (r,s):init_seg_of"
   325 
   326 lemma refl_on_init_seg_of[simp]: "r initial_segment_of r"
   327 by(simp add:init_seg_of_def)
   328 
   329 lemma trans_init_seg_of:
   330   "r initial_segment_of s \<Longrightarrow> s initial_segment_of t \<Longrightarrow> r initial_segment_of t"
   331 by(simp (no_asm_use) add: init_seg_of_def)
   332   (metis Domain_iff UnCI Un_absorb2 subset_trans)
   333 
   334 lemma antisym_init_seg_of:
   335   "r initial_segment_of s \<Longrightarrow> s initial_segment_of r \<Longrightarrow> r=s"
   336 unfolding init_seg_of_def by safe
   337 
   338 lemma Chain_init_seg_of_Union:
   339   "R \<in> Chain init_seg_of \<Longrightarrow> r\<in>R \<Longrightarrow> r initial_segment_of \<Union>R"
   340 by(auto simp add:init_seg_of_def Chain_def Ball_def) blast
   341 
   342 lemma chain_subset_trans_Union:
   343   "chain\<^bsub>\<subseteq>\<^esub> R \<Longrightarrow> \<forall>r\<in>R. trans r \<Longrightarrow> trans(\<Union>R)"
   344 apply(auto simp add:chain_subset_def)
   345 apply(simp (no_asm_use) add:trans_def)
   346 apply (metis subsetD)
   347 done
   348 
   349 lemma chain_subset_antisym_Union:
   350   "chain\<^bsub>\<subseteq>\<^esub> R \<Longrightarrow> \<forall>r\<in>R. antisym r \<Longrightarrow> antisym(\<Union>R)"
   351 apply(auto simp add:chain_subset_def antisym_def)
   352 apply (metis subsetD)
   353 done
   354 
   355 lemma chain_subset_Total_Union:
   356 assumes "chain\<^bsub>\<subseteq>\<^esub> R" "\<forall>r\<in>R. Total r"
   357 shows "Total (\<Union>R)"
   358 proof (simp add: total_on_def Ball_def, auto del:disjCI)
   359   fix r s a b assume A: "r:R" "s:R" "a:Field r" "b:Field s" "a\<noteq>b"
   360   from `chain\<^bsub>\<subseteq>\<^esub> R` `r:R` `s:R` have "r\<subseteq>s \<or> s\<subseteq>r"
   361     by(simp add:chain_subset_def)
   362   thus "(\<exists>r\<in>R. (a,b) \<in> r) \<or> (\<exists>r\<in>R. (b,a) \<in> r)"
   363   proof
   364     assume "r\<subseteq>s" hence "(a,b):s \<or> (b,a):s" using assms(2) A
   365       by(simp add:total_on_def)(metis mono_Field subsetD)
   366     thus ?thesis using `s:R` by blast
   367   next
   368     assume "s\<subseteq>r" hence "(a,b):r \<or> (b,a):r" using assms(2) A
   369       by(simp add:total_on_def)(metis mono_Field subsetD)
   370     thus ?thesis using `r:R` by blast
   371   qed
   372 qed
   373 
   374 lemma wf_Union_wf_init_segs:
   375 assumes "R \<in> Chain init_seg_of" and "\<forall>r\<in>R. wf r" shows "wf(\<Union>R)"
   376 proof(simp add:wf_iff_no_infinite_down_chain, rule ccontr, auto)
   377   fix f assume 1: "\<forall>i. \<exists>r\<in>R. (f(Suc i), f i) \<in> r"
   378   then obtain r where "r:R" and "(f(Suc 0), f 0) : r" by auto
   379   { fix i have "(f(Suc i), f i) \<in> r"
   380     proof(induct i)
   381       case 0 show ?case by fact
   382     next
   383       case (Suc i)
   384       moreover obtain s where "s\<in>R" and "(f(Suc(Suc i)), f(Suc i)) \<in> s"
   385         using 1 by auto
   386       moreover hence "s initial_segment_of r \<or> r initial_segment_of s"
   387         using assms(1) `r:R` by(simp add: Chain_def)
   388       ultimately show ?case by(simp add:init_seg_of_def) blast
   389     qed
   390   }
   391   thus False using assms(2) `r:R`
   392     by(simp add:wf_iff_no_infinite_down_chain) blast
   393 qed
   394 
   395 lemma initial_segment_of_Diff:
   396   "p initial_segment_of q \<Longrightarrow> p - s initial_segment_of q - s"
   397 unfolding init_seg_of_def by blast
   398 
   399 lemma Chain_inits_DiffI:
   400   "R \<in> Chain init_seg_of \<Longrightarrow> {r - s |r. r \<in> R} \<in> Chain init_seg_of"
   401 unfolding Chain_def by (blast intro: initial_segment_of_Diff)
   402 
   403 theorem well_ordering: "\<exists>r::('a*'a)set. Well_order r \<and> Field r = UNIV"
   404 proof-
   405 -- {*The initial segment relation on well-orders: *}
   406   let ?WO = "{r::('a*'a)set. Well_order r}"
   407   def I \<equiv> "init_seg_of \<inter> ?WO \<times> ?WO"
   408   have I_init: "I \<subseteq> init_seg_of" by(auto simp:I_def)
   409   hence subch: "!!R. R : Chain I \<Longrightarrow> chain\<^bsub>\<subseteq>\<^esub> R"
   410     by(auto simp:init_seg_of_def chain_subset_def Chain_def)
   411   have Chain_wo: "!!R r. R \<in> Chain I \<Longrightarrow> r \<in> R \<Longrightarrow> Well_order r"
   412     by(simp add:Chain_def I_def) blast
   413   have FI: "Field I = ?WO" by(auto simp add:I_def init_seg_of_def Field_def)
   414   hence 0: "Partial_order I"
   415     by(auto simp: partial_order_on_def preorder_on_def antisym_def antisym_init_seg_of refl_on_def trans_def I_def elim!: trans_init_seg_of)
   416 -- {*I-chains have upper bounds in ?WO wrt I: their Union*}
   417   { fix R assume "R \<in> Chain I"
   418     hence Ris: "R \<in> Chain init_seg_of" using mono_Chain[OF I_init] by blast
   419     have subch: "chain\<^bsub>\<subseteq>\<^esub> R" using `R : Chain I` I_init
   420       by(auto simp:init_seg_of_def chain_subset_def Chain_def)
   421     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"
   422          "\<forall>r\<in>R. wf(r-Id)"
   423       using Chain_wo[OF `R \<in> Chain I`] by(simp_all add:order_on_defs)
   424     have "Refl (\<Union>R)" using `\<forall>r\<in>R. Refl r` by(auto simp:refl_on_def)
   425     moreover have "trans (\<Union>R)"
   426       by(rule chain_subset_trans_Union[OF subch `\<forall>r\<in>R. trans r`])
   427     moreover have "antisym(\<Union>R)"
   428       by(rule chain_subset_antisym_Union[OF subch `\<forall>r\<in>R. antisym r`])
   429     moreover have "Total (\<Union>R)"
   430       by(rule chain_subset_Total_Union[OF subch `\<forall>r\<in>R. Total r`])
   431     moreover have "wf((\<Union>R)-Id)"
   432     proof-
   433       have "(\<Union>R)-Id = \<Union>{r-Id|r. r \<in> R}" by blast
   434       with `\<forall>r\<in>R. wf(r-Id)` wf_Union_wf_init_segs[OF Chain_inits_DiffI[OF Ris]]
   435       show ?thesis by (simp (no_asm_simp)) blast
   436     qed
   437     ultimately have "Well_order (\<Union>R)" by(simp add:order_on_defs)
   438     moreover have "\<forall>r \<in> R. r initial_segment_of \<Union>R" using Ris
   439       by(simp add: Chain_init_seg_of_Union)
   440     ultimately have "\<Union>R : ?WO \<and> (\<forall>r\<in>R. (r,\<Union>R) : I)"
   441       using mono_Chain[OF I_init] `R \<in> Chain I`
   442       by(simp (no_asm) add:I_def del:Field_Union)(metis Chain_wo subsetD)
   443   }
   444   hence 1: "\<forall>R \<in> Chain I. \<exists>u\<in>Field I. \<forall>r\<in>R. (r,u) : I" by (subst FI) blast
   445 --{*Zorn's Lemma yields a maximal well-order m:*}
   446   then obtain m::"('a*'a)set" where "Well_order m" and
   447     max: "\<forall>r. Well_order r \<and> (m,r):I \<longrightarrow> r=m"
   448     using Zorns_po_lemma[OF 0 1] by (auto simp:FI)
   449 --{*Now show by contradiction that m covers the whole type:*}
   450   { fix x::'a assume "x \<notin> Field m"
   451 --{*We assume that x is not covered and extend m at the top with x*}
   452     have "m \<noteq> {}"
   453     proof
   454       assume "m={}"
   455       moreover have "Well_order {(x,x)}"
   456         by(simp add:order_on_defs refl_on_def trans_def antisym_def total_on_def Field_def Domain_def Range_def)
   457       ultimately show False using max
   458         by (auto simp:I_def init_seg_of_def simp del:Field_insert)
   459     qed
   460     hence "Field m \<noteq> {}" by(auto simp:Field_def)
   461     moreover have "wf(m-Id)" using `Well_order m`
   462       by(simp add:well_order_on_def)
   463 --{*The extension of m by x:*}
   464     let ?s = "{(a,x)|a. a : Field m}" let ?m = "insert (x,x) m Un ?s"
   465     have Fm: "Field ?m = insert x (Field m)"
   466       apply(simp add:Field_insert Field_Un)
   467       unfolding Field_def by auto
   468     have "Refl m" "trans m" "antisym m" "Total m" "wf(m-Id)"
   469       using `Well_order m` by(simp_all add:order_on_defs)
   470 --{*We show that the extension is a well-order*}
   471     have "Refl ?m" using `Refl m` Fm by(auto simp:refl_on_def)
   472     moreover have "trans ?m" using `trans m` `x \<notin> Field m`
   473       unfolding trans_def Field_def Domain_def Range_def by blast
   474     moreover have "antisym ?m" using `antisym m` `x \<notin> Field m`
   475       unfolding antisym_def Field_def Domain_def Range_def by blast
   476     moreover have "Total ?m" using `Total m` Fm by(auto simp: total_on_def)
   477     moreover have "wf(?m-Id)"
   478     proof-
   479       have "wf ?s" using `x \<notin> Field m`
   480         by(auto simp add:wf_eq_minimal Field_def Domain_def Range_def) metis
   481       thus ?thesis using `wf(m-Id)` `x \<notin> Field m`
   482         wf_subset[OF `wf ?s` Diff_subset]
   483         by (fastsimp intro!: wf_Un simp add: Un_Diff Field_def)
   484     qed
   485     ultimately have "Well_order ?m" by(simp add:order_on_defs)
   486 --{*We show that the extension is above m*}
   487     moreover hence "(m,?m) : I" using `Well_order m` `x \<notin> Field m`
   488       by(fastsimp simp:I_def init_seg_of_def Field_def Domain_def Range_def)
   489     ultimately
   490 --{*This contradicts maximality of m:*}
   491     have False using max `x \<notin> Field m` unfolding Field_def by blast
   492   }
   493   hence "Field m = UNIV" by auto
   494   moreover with `Well_order m` have "Well_order m" by simp
   495   ultimately show ?thesis by blast
   496 qed
   497 
   498 corollary well_order_on: "\<exists>r::('a*'a)set. well_order_on A r"
   499 proof -
   500   obtain r::"('a*'a)set" where wo: "Well_order r" and univ: "Field r = UNIV"
   501     using well_ordering[where 'a = "'a"] by blast
   502   let ?r = "{(x,y). x:A & y:A & (x,y):r}"
   503   have 1: "Field ?r = A" using wo univ
   504     by(fastsimp simp: Field_def Domain_def Range_def order_on_defs refl_on_def)
   505   have "Refl r" "trans r" "antisym r" "Total r" "wf(r-Id)"
   506     using `Well_order r` by(simp_all add:order_on_defs)
   507   have "Refl ?r" using `Refl r` by(auto simp:refl_on_def 1 univ)
   508   moreover have "trans ?r" using `trans r`
   509     unfolding trans_def by blast
   510   moreover have "antisym ?r" using `antisym r`
   511     unfolding antisym_def by blast
   512   moreover have "Total ?r" using `Total r` by(simp add:total_on_def 1 univ)
   513   moreover have "wf(?r - Id)" by(rule wf_subset[OF `wf(r-Id)`]) blast
   514   ultimately have "Well_order ?r" by(simp add:order_on_defs)
   515   with 1 show ?thesis by metis
   516 qed
   517 
   518 end