src/HOL/BNF_Constructions_on_Wellorders.thy
changeset 55101 57c875e488bd
parent 55059 ef2e0fb783c6
child 55603 48596c45bf7f
equal deleted inserted replaced
55100:697b41533e1a 55101:57c875e488bd
     8 header {* Constructions on Wellorders as Needed by Bounded Natural Functors *}
     8 header {* Constructions on Wellorders as Needed by Bounded Natural Functors *}
     9 
     9 
    10 theory BNF_Constructions_on_Wellorders
    10 theory BNF_Constructions_on_Wellorders
    11 imports BNF_Wellorder_Embedding
    11 imports BNF_Wellorder_Embedding
    12 begin
    12 begin
    13 
       
    14 
    13 
    15 text {* In this section, we study basic constructions on well-orders, such as restriction to
    14 text {* In this section, we study basic constructions on well-orders, such as restriction to
    16 a set/order filter, copy via direct images, ordinal-like sum of disjoint well-orders,
    15 a set/order filter, copy via direct images, ordinal-like sum of disjoint well-orders,
    17 and bounded square.  We also define between well-orders
    16 and bounded square.  We also define between well-orders
    18 the relations @{text "ordLeq"}, of being embedded (abbreviated @{text "\<le>o"}),
    17 the relations @{text "ordLeq"}, of being embedded (abbreviated @{text "\<le>o"}),
    19 @{text "ordLess"}, of being strictly embedded (abbreviated @{text "<o"}), and
    18 @{text "ordLess"}, of being strictly embedded (abbreviated @{text "<o"}), and
    20 @{text "ordIso"}, of being isomorphic (abbreviated @{text "=o"}).  We study the
    19 @{text "ordIso"}, of being isomorphic (abbreviated @{text "=o"}).  We study the
    21 connections between these relations, order filters, and the aforementioned constructions.
    20 connections between these relations, order filters, and the aforementioned constructions.
    22 A main result of this section is that @{text "<o"} is well-founded.  *}
    21 A main result of this section is that @{text "<o"} is well-founded. *}
    23 
    22 
    24 
    23 
    25 subsection {* Restriction to a set  *}
    24 subsection {* Restriction to a set *}
    26 
       
    27 
    25 
    28 abbreviation Restr :: "'a rel \<Rightarrow> 'a set \<Rightarrow> 'a rel"
    26 abbreviation Restr :: "'a rel \<Rightarrow> 'a set \<Rightarrow> 'a rel"
    29 where "Restr r A \<equiv> r Int (A \<times> A)"
    27 where "Restr r A \<equiv> r Int (A \<times> A)"
    30 
       
    31 
    28 
    32 lemma Restr_subset:
    29 lemma Restr_subset:
    33 "A \<le> B \<Longrightarrow> Restr (Restr r B) A = Restr r A"
    30 "A \<le> B \<Longrightarrow> Restr (Restr r B) A = Restr r A"
    34 by blast
    31 by blast
    35 
    32 
    36 
       
    37 lemma Restr_Field: "Restr r (Field r) = r"
    33 lemma Restr_Field: "Restr r (Field r) = r"
    38 unfolding Field_def by auto
    34 unfolding Field_def by auto
    39 
    35 
    40 
       
    41 lemma Refl_Restr: "Refl r \<Longrightarrow> Refl(Restr r A)"
    36 lemma Refl_Restr: "Refl r \<Longrightarrow> Refl(Restr r A)"
    42 unfolding refl_on_def Field_def by auto
    37 unfolding refl_on_def Field_def by auto
    43 
       
    44 
    38 
    45 lemma antisym_Restr:
    39 lemma antisym_Restr:
    46 "antisym r \<Longrightarrow> antisym(Restr r A)"
    40 "antisym r \<Longrightarrow> antisym(Restr r A)"
    47 unfolding antisym_def Field_def by auto
    41 unfolding antisym_def Field_def by auto
    48 
    42 
    49 
       
    50 lemma Total_Restr:
    43 lemma Total_Restr:
    51 "Total r \<Longrightarrow> Total(Restr r A)"
    44 "Total r \<Longrightarrow> Total(Restr r A)"
    52 unfolding total_on_def Field_def by auto
    45 unfolding total_on_def Field_def by auto
    53 
    46 
    54 
       
    55 lemma trans_Restr:
    47 lemma trans_Restr:
    56 "trans r \<Longrightarrow> trans(Restr r A)"
    48 "trans r \<Longrightarrow> trans(Restr r A)"
    57 unfolding trans_def Field_def by blast
    49 unfolding trans_def Field_def by blast
    58 
    50 
    59 
       
    60 lemma Preorder_Restr:
    51 lemma Preorder_Restr:
    61 "Preorder r \<Longrightarrow> Preorder(Restr r A)"
    52 "Preorder r \<Longrightarrow> Preorder(Restr r A)"
    62 unfolding preorder_on_def by (simp add: Refl_Restr trans_Restr)
    53 unfolding preorder_on_def by (simp add: Refl_Restr trans_Restr)
    63 
    54 
    64 
       
    65 lemma Partial_order_Restr:
    55 lemma Partial_order_Restr:
    66 "Partial_order r \<Longrightarrow> Partial_order(Restr r A)"
    56 "Partial_order r \<Longrightarrow> Partial_order(Restr r A)"
    67 unfolding partial_order_on_def by (simp add: Preorder_Restr antisym_Restr)
    57 unfolding partial_order_on_def by (simp add: Preorder_Restr antisym_Restr)
    68 
    58 
    69 
       
    70 lemma Linear_order_Restr:
    59 lemma Linear_order_Restr:
    71 "Linear_order r \<Longrightarrow> Linear_order(Restr r A)"
    60 "Linear_order r \<Longrightarrow> Linear_order(Restr r A)"
    72 unfolding linear_order_on_def by (simp add: Partial_order_Restr Total_Restr)
    61 unfolding linear_order_on_def by (simp add: Partial_order_Restr Total_Restr)
    73 
       
    74 
    62 
    75 lemma Well_order_Restr:
    63 lemma Well_order_Restr:
    76 assumes "Well_order r"
    64 assumes "Well_order r"
    77 shows "Well_order(Restr r A)"
    65 shows "Well_order(Restr r A)"
    78 proof-
    66 proof-
    81   using well_order_on_def wf_subset by blast
    69   using well_order_on_def wf_subset by blast
    82   thus ?thesis using assms unfolding well_order_on_def
    70   thus ?thesis using assms unfolding well_order_on_def
    83   by (simp add: Linear_order_Restr)
    71   by (simp add: Linear_order_Restr)
    84 qed
    72 qed
    85 
    73 
    86 
       
    87 lemma Field_Restr_subset: "Field(Restr r A) \<le> A"
    74 lemma Field_Restr_subset: "Field(Restr r A) \<le> A"
    88 by (auto simp add: Field_def)
    75 by (auto simp add: Field_def)
    89 
       
    90 
    76 
    91 lemma Refl_Field_Restr:
    77 lemma Refl_Field_Restr:
    92 "Refl r \<Longrightarrow> Field(Restr r A) = (Field r) Int A"
    78 "Refl r \<Longrightarrow> Field(Restr r A) = (Field r) Int A"
    93 unfolding refl_on_def Field_def by blast
    79 unfolding refl_on_def Field_def by blast
    94 
    80 
    95 
       
    96 lemma Refl_Field_Restr2:
    81 lemma Refl_Field_Restr2:
    97 "\<lbrakk>Refl r; A \<le> Field r\<rbrakk> \<Longrightarrow> Field(Restr r A) = A"
    82 "\<lbrakk>Refl r; A \<le> Field r\<rbrakk> \<Longrightarrow> Field(Restr r A) = A"
    98 by (auto simp add: Refl_Field_Restr)
    83 by (auto simp add: Refl_Field_Restr)
    99 
       
   100 
    84 
   101 lemma well_order_on_Restr:
    85 lemma well_order_on_Restr:
   102 assumes WELL: "Well_order r" and SUB: "A \<le> Field r"
    86 assumes WELL: "Well_order r" and SUB: "A \<le> Field r"
   103 shows "well_order_on A (Restr r A)"
    87 shows "well_order_on A (Restr r A)"
   104 using assms
    88 using assms
   105 using Well_order_Restr[of r A] Refl_Field_Restr2[of r A]
    89 using Well_order_Restr[of r A] Refl_Field_Restr2[of r A]
   106      order_on_defs[of "Field r" r] by auto
    90      order_on_defs[of "Field r" r] by auto
   107 
    91 
   108 
    92 
   109 subsection {* Order filters versus restrictions and embeddings  *}
    93 subsection {* Order filters versus restrictions and embeddings *}
   110 
       
   111 
    94 
   112 lemma Field_Restr_ofilter:
    95 lemma Field_Restr_ofilter:
   113 "\<lbrakk>Well_order r; wo_rel.ofilter r A\<rbrakk> \<Longrightarrow> Field(Restr r A) = A"
    96 "\<lbrakk>Well_order r; wo_rel.ofilter r A\<rbrakk> \<Longrightarrow> Field(Restr r A) = A"
   114 by (auto simp add: wo_rel_def wo_rel.ofilter_def wo_rel.REFL Refl_Field_Restr2)
    97 by (auto simp add: wo_rel_def wo_rel.ofilter_def wo_rel.REFL Refl_Field_Restr2)
   115 
       
   116 
    98 
   117 lemma ofilter_Restr_under:
    99 lemma ofilter_Restr_under:
   118 assumes WELL: "Well_order r" and OF: "wo_rel.ofilter r A" and IN: "a \<in> A"
   100 assumes WELL: "Well_order r" and OF: "wo_rel.ofilter r A" and IN: "a \<in> A"
   119 shows "under (Restr r A) a = under r a"
   101 shows "under (Restr r A) a = under r a"
   120 using assms wo_rel_def
   102 using assms wo_rel_def
   122   fix b assume *: "a \<in> A" and "(b,a) \<in> r"
   104   fix b assume *: "a \<in> A" and "(b,a) \<in> r"
   123   hence "b \<in> under r a \<and> a \<in> Field r"
   105   hence "b \<in> under r a \<and> a \<in> Field r"
   124   unfolding under_def using Field_def by fastforce
   106   unfolding under_def using Field_def by fastforce
   125   thus "b \<in> A" using * assms by (auto simp add: wo_rel_def wo_rel.ofilter_def)
   107   thus "b \<in> A" using * assms by (auto simp add: wo_rel_def wo_rel.ofilter_def)
   126 qed
   108 qed
   127 
       
   128 
   109 
   129 lemma ofilter_embed:
   110 lemma ofilter_embed:
   130 assumes "Well_order r"
   111 assumes "Well_order r"
   131 shows "wo_rel.ofilter r A = (A \<le> Field r \<and> embed (Restr r A) r id)"
   112 shows "wo_rel.ofilter r A = (A \<le> Field r \<and> embed (Restr r A) r id)"
   132 proof
   113 proof
   157    finally have "under r a \<le> A" .
   138    finally have "under r a \<le> A" .
   158   }
   139   }
   159   thus "wo_rel.ofilter r A" using assms * by (simp add: wo_rel_def wo_rel.ofilter_def)
   140   thus "wo_rel.ofilter r A" using assms * by (simp add: wo_rel_def wo_rel.ofilter_def)
   160 qed
   141 qed
   161 
   142 
   162 
       
   163 lemma ofilter_Restr_Int:
   143 lemma ofilter_Restr_Int:
   164 assumes WELL: "Well_order r" and OFA: "wo_rel.ofilter r A"
   144 assumes WELL: "Well_order r" and OFA: "wo_rel.ofilter r A"
   165 shows "wo_rel.ofilter (Restr r B) (A Int B)"
   145 shows "wo_rel.ofilter (Restr r B) (A Int B)"
   166 proof-
   146 proof-
   167   let ?rB = "Restr r B"
   147   let ?rB = "Restr r B"
   181     fix a b assume "a \<in> A" and "(b,a) \<in> r"
   161     fix a b assume "a \<in> A" and "(b,a) \<in> r"
   182     thus "b \<in> A" using Well OFA by (auto simp add: wo_rel.ofilter_def under_def)
   162     thus "b \<in> A" using Well OFA by (auto simp add: wo_rel.ofilter_def under_def)
   183   qed
   163   qed
   184 qed
   164 qed
   185 
   165 
   186 
       
   187 lemma ofilter_Restr_subset:
   166 lemma ofilter_Restr_subset:
   188 assumes WELL: "Well_order r" and OFA: "wo_rel.ofilter r A" and SUB: "A \<le> B"
   167 assumes WELL: "Well_order r" and OFA: "wo_rel.ofilter r A" and SUB: "A \<le> B"
   189 shows "wo_rel.ofilter (Restr r B) A"
   168 shows "wo_rel.ofilter (Restr r B) A"
   190 proof-
   169 proof-
   191   have "A Int B = A" using SUB by blast
   170   have "A Int B = A" using SUB by blast
   192   thus ?thesis using assms ofilter_Restr_Int[of r A B] by auto
   171   thus ?thesis using assms ofilter_Restr_Int[of r A B] by auto
   193 qed
   172 qed
   194 
       
   195 
   173 
   196 lemma ofilter_subset_embed:
   174 lemma ofilter_subset_embed:
   197 assumes WELL: "Well_order r" and
   175 assumes WELL: "Well_order r" and
   198         OFA: "wo_rel.ofilter r A" and OFB: "wo_rel.ofilter r B"
   176         OFA: "wo_rel.ofilter r A" and OFB: "wo_rel.ofilter r B"
   199 shows "(A \<le> B) = (embed (Restr r A) (Restr r B) id)"
   177 shows "(A \<le> B) = (embed (Restr r A) (Restr r B) id)"
   229     }
   207     }
   230     thus "A \<le> B" by blast
   208     thus "A \<le> B" by blast
   231   qed
   209   qed
   232 qed
   210 qed
   233 
   211 
   234 
       
   235 lemma ofilter_subset_embedS_iso:
   212 lemma ofilter_subset_embedS_iso:
   236 assumes WELL: "Well_order r" and
   213 assumes WELL: "Well_order r" and
   237         OFA: "wo_rel.ofilter r A" and OFB: "wo_rel.ofilter r B"
   214         OFA: "wo_rel.ofilter r A" and OFB: "wo_rel.ofilter r B"
   238 shows "((A < B) = (embedS (Restr r A) (Restr r B) id)) \<and>
   215 shows "((A < B) = (embedS (Restr r A) (Restr r B) id)) \<and>
   239        ((A = B) = (iso (Restr r A) (Restr r B) id))"
   216        ((A = B) = (iso (Restr r A) (Restr r B) id))"
   253   show ?thesis unfolding embedS_def iso_def
   230   show ?thesis unfolding embedS_def iso_def
   254   using assms ofilter_subset_embed[of r A B]
   231   using assms ofilter_subset_embed[of r A B]
   255         FieldA FieldB bij_betw_id_iff[of A B] by auto
   232         FieldA FieldB bij_betw_id_iff[of A B] by auto
   256 qed
   233 qed
   257 
   234 
   258 
       
   259 lemma ofilter_subset_embedS:
   235 lemma ofilter_subset_embedS:
   260 assumes WELL: "Well_order r" and
   236 assumes WELL: "Well_order r" and
   261         OFA: "wo_rel.ofilter r A" and OFB: "wo_rel.ofilter r B"
   237         OFA: "wo_rel.ofilter r A" and OFB: "wo_rel.ofilter r B"
   262 shows "(A < B) = embedS (Restr r A) (Restr r B) id"
   238 shows "(A < B) = embedS (Restr r A) (Restr r B) id"
   263 using assms by (simp add: ofilter_subset_embedS_iso)
   239 using assms by (simp add: ofilter_subset_embedS_iso)
   264 
       
   265 
   240 
   266 lemma embed_implies_iso_Restr:
   241 lemma embed_implies_iso_Restr:
   267 assumes WELL: "Well_order r" and WELL': "Well_order r'" and
   242 assumes WELL: "Well_order r" and WELL': "Well_order r'" and
   268         EMB: "embed r' r f"
   243         EMB: "embed r' r f"
   269 shows "iso r' (Restr r (f ` (Field r'))) f"
   244 shows "iso r' (Restr r (f ` (Field r'))) f"
   286 qed
   261 qed
   287 
   262 
   288 
   263 
   289 subsection {* The strict inclusion on proper ofilters is well-founded *}
   264 subsection {* The strict inclusion on proper ofilters is well-founded *}
   290 
   265 
   291 
       
   292 definition ofilterIncl :: "'a rel \<Rightarrow> 'a set rel"
   266 definition ofilterIncl :: "'a rel \<Rightarrow> 'a set rel"
   293 where
   267 where
   294 "ofilterIncl r \<equiv> {(A,B). wo_rel.ofilter r A \<and> A \<noteq> Field r \<and>
   268 "ofilterIncl r \<equiv> {(A,B). wo_rel.ofilter r A \<and> A \<noteq> Field r \<and>
   295                          wo_rel.ofilter r B \<and> B \<noteq> Field r \<and> A < B}"
   269                          wo_rel.ofilter r B \<and> B \<noteq> Field r \<and> A < B}"
   296 
       
   297 
   270 
   298 lemma wf_ofilterIncl:
   271 lemma wf_ofilterIncl:
   299 assumes WELL: "Well_order r"
   272 assumes WELL: "Well_order r"
   300 shows "wf(ofilterIncl r)"
   273 shows "wf(ofilterIncl r)"
   301 proof-
   274 proof-
   327   qed
   300   qed
   328   ultimately show "wf (ofilterIncl r)" by (simp add: compat_wf)
   301   ultimately show "wf (ofilterIncl r)" by (simp add: compat_wf)
   329 qed
   302 qed
   330 
   303 
   331 
   304 
   332 
       
   333 subsection {* Ordering the well-orders by existence of embeddings *}
   305 subsection {* Ordering the well-orders by existence of embeddings *}
   334 
       
   335 
   306 
   336 text {* We define three relations between well-orders:
   307 text {* We define three relations between well-orders:
   337 \begin{itemize}
   308 \begin{itemize}
   338 \item @{text "ordLeq"}, of being embedded (abbreviated @{text "\<le>o"});
   309 \item @{text "ordLeq"}, of being embedded (abbreviated @{text "\<le>o"});
   339 \item @{text "ordLess"}, of being strictly embedded (abbreviated @{text "<o"});
   310 \item @{text "ordLess"}, of being strictly embedded (abbreviated @{text "<o"});
   343 The prefix "ord" and the index "o" in these names stand for "ordinal-like".
   314 The prefix "ord" and the index "o" in these names stand for "ordinal-like".
   344 These relations shall be proved to be inter-connected in a similar fashion as the trio
   315 These relations shall be proved to be inter-connected in a similar fashion as the trio
   345 @{text "\<le>"}, @{text "<"}, @{text "="} associated to a total order on a set.
   316 @{text "\<le>"}, @{text "<"}, @{text "="} associated to a total order on a set.
   346 *}
   317 *}
   347 
   318 
   348 
       
   349 definition ordLeq :: "('a rel * 'a' rel) set"
   319 definition ordLeq :: "('a rel * 'a' rel) set"
   350 where
   320 where
   351 "ordLeq = {(r,r'). Well_order r \<and> Well_order r' \<and> (\<exists>f. embed r r' f)}"
   321 "ordLeq = {(r,r'). Well_order r \<and> Well_order r' \<and> (\<exists>f. embed r r' f)}"
   352 
   322 
   353 
       
   354 abbreviation ordLeq2 :: "'a rel \<Rightarrow> 'a' rel \<Rightarrow> bool" (infix "<=o" 50)
   323 abbreviation ordLeq2 :: "'a rel \<Rightarrow> 'a' rel \<Rightarrow> bool" (infix "<=o" 50)
   355 where "r <=o r' \<equiv> (r,r') \<in> ordLeq"
   324 where "r <=o r' \<equiv> (r,r') \<in> ordLeq"
   356 
   325 
   357 
       
   358 abbreviation ordLeq3 :: "'a rel \<Rightarrow> 'a' rel \<Rightarrow> bool" (infix "\<le>o" 50)
   326 abbreviation ordLeq3 :: "'a rel \<Rightarrow> 'a' rel \<Rightarrow> bool" (infix "\<le>o" 50)
   359 where "r \<le>o r' \<equiv> r <=o r'"
   327 where "r \<le>o r' \<equiv> r <=o r'"
   360 
       
   361 
   328 
   362 definition ordLess :: "('a rel * 'a' rel) set"
   329 definition ordLess :: "('a rel * 'a' rel) set"
   363 where
   330 where
   364 "ordLess = {(r,r'). Well_order r \<and> Well_order r' \<and> (\<exists>f. embedS r r' f)}"
   331 "ordLess = {(r,r'). Well_order r \<and> Well_order r' \<and> (\<exists>f. embedS r r' f)}"
   365 
   332 
   366 abbreviation ordLess2 :: "'a rel \<Rightarrow> 'a' rel \<Rightarrow> bool" (infix "<o" 50)
   333 abbreviation ordLess2 :: "'a rel \<Rightarrow> 'a' rel \<Rightarrow> bool" (infix "<o" 50)
   367 where "r <o r' \<equiv> (r,r') \<in> ordLess"
   334 where "r <o r' \<equiv> (r,r') \<in> ordLess"
   368 
   335 
   369 
       
   370 definition ordIso :: "('a rel * 'a' rel) set"
   336 definition ordIso :: "('a rel * 'a' rel) set"
   371 where
   337 where
   372 "ordIso = {(r,r'). Well_order r \<and> Well_order r' \<and> (\<exists>f. iso r r' f)}"
   338 "ordIso = {(r,r'). Well_order r \<and> Well_order r' \<and> (\<exists>f. iso r r' f)}"
   373 
   339 
   374 abbreviation ordIso2 :: "'a rel \<Rightarrow> 'a' rel \<Rightarrow> bool" (infix "=o" 50)
   340 abbreviation ordIso2 :: "'a rel \<Rightarrow> 'a' rel \<Rightarrow> bool" (infix "=o" 50)
   375 where "r =o r' \<equiv> (r,r') \<in> ordIso"
   341 where "r =o r' \<equiv> (r,r') \<in> ordIso"
   376 
       
   377 
   342 
   378 lemmas ordRels_def = ordLeq_def ordLess_def ordIso_def
   343 lemmas ordRels_def = ordLeq_def ordLess_def ordIso_def
   379 
   344 
   380 lemma ordLeq_Well_order_simp:
   345 lemma ordLeq_Well_order_simp:
   381 assumes "r \<le>o r'"
   346 assumes "r \<le>o r'"
   382 shows "Well_order r \<and> Well_order r'"
   347 shows "Well_order r \<and> Well_order r'"
   383 using assms unfolding ordLeq_def by simp
   348 using assms unfolding ordLeq_def by simp
   384 
   349 
   385 
       
   386 text{* Notice that the relations @{text "\<le>o"}, @{text "<o"}, @{text "=o"} connect well-orders
   350 text{* Notice that the relations @{text "\<le>o"}, @{text "<o"}, @{text "=o"} connect well-orders
   387 on potentially {\em distinct} types. However, some of the lemmas below, including the next one,
   351 on potentially {\em distinct} types. However, some of the lemmas below, including the next one,
   388 restrict implicitly the type of these relations to @{text "(('a rel) * ('a rel)) set"} , i.e.,
   352 restrict implicitly the type of these relations to @{text "(('a rel) * ('a rel)) set"} , i.e.,
   389 to @{text "'a rel rel"}.  *}
   353 to @{text "'a rel rel"}. *}
   390 
       
   391 
   354 
   392 lemma ordLeq_reflexive:
   355 lemma ordLeq_reflexive:
   393 "Well_order r \<Longrightarrow> r \<le>o r"
   356 "Well_order r \<Longrightarrow> r \<le>o r"
   394 unfolding ordLeq_def using id_embed[of r] by blast
   357 unfolding ordLeq_def using id_embed[of r] by blast
   395 
       
   396 
   358 
   397 lemma ordLeq_transitive[trans]:
   359 lemma ordLeq_transitive[trans]:
   398 assumes *: "r \<le>o r'" and **: "r' \<le>o r''"
   360 assumes *: "r \<le>o r'" and **: "r' \<le>o r''"
   399 shows "r \<le>o r''"
   361 shows "r \<le>o r''"
   400 proof-
   362 proof-
   405   hence "embed r r'' (f' o f)"
   367   hence "embed r r'' (f' o f)"
   406   using comp_embed[of r r' f r'' f'] by auto
   368   using comp_embed[of r r' f r'' f'] by auto
   407   thus "r \<le>o r''" unfolding ordLeq_def using 1 by auto
   369   thus "r \<le>o r''" unfolding ordLeq_def using 1 by auto
   408 qed
   370 qed
   409 
   371 
   410 
       
   411 lemma ordLeq_total:
   372 lemma ordLeq_total:
   412 "\<lbrakk>Well_order r; Well_order r'\<rbrakk> \<Longrightarrow> r \<le>o r' \<or> r' \<le>o r"
   373 "\<lbrakk>Well_order r; Well_order r'\<rbrakk> \<Longrightarrow> r \<le>o r' \<or> r' \<le>o r"
   413 unfolding ordLeq_def using wellorders_totally_ordered by blast
   374 unfolding ordLeq_def using wellorders_totally_ordered by blast
   414 
   375 
   415 
       
   416 lemma ordIso_reflexive:
   376 lemma ordIso_reflexive:
   417 "Well_order r \<Longrightarrow> r =o r"
   377 "Well_order r \<Longrightarrow> r =o r"
   418 unfolding ordIso_def using id_iso[of r] by blast
   378 unfolding ordIso_def using id_iso[of r] by blast
   419 
       
   420 
   379 
   421 lemma ordIso_transitive[trans]:
   380 lemma ordIso_transitive[trans]:
   422 assumes *: "r =o r'" and **: "r' =o r''"
   381 assumes *: "r =o r'" and **: "r' =o r''"
   423 shows "r =o r''"
   382 shows "r =o r''"
   424 proof-
   383 proof-
   429   hence "iso r r'' (f' o f)"
   388   hence "iso r r'' (f' o f)"
   430   using comp_iso[of r r' f r'' f'] by auto
   389   using comp_iso[of r r' f r'' f'] by auto
   431   thus "r =o r''" unfolding ordIso_def using 1 by auto
   390   thus "r =o r''" unfolding ordIso_def using 1 by auto
   432 qed
   391 qed
   433 
   392 
   434 
       
   435 lemma ordIso_symmetric:
   393 lemma ordIso_symmetric:
   436 assumes *: "r =o r'"
   394 assumes *: "r =o r'"
   437 shows "r' =o r"
   395 shows "r' =o r"
   438 proof-
   396 proof-
   439   obtain f where 1: "Well_order r \<and> Well_order r'" and
   397   obtain f where 1: "Well_order r \<and> Well_order r'" and
   443   have "embed r' r ?f' \<and> bij_betw ?f' (Field r') (Field r)"
   401   have "embed r' r ?f' \<and> bij_betw ?f' (Field r') (Field r)"
   444   using 1 2 by (simp add: bij_betw_inv_into inv_into_Field_embed_bij_betw)
   402   using 1 2 by (simp add: bij_betw_inv_into inv_into_Field_embed_bij_betw)
   445   thus "r' =o r" unfolding ordIso_def using 1 by (auto simp add: iso_def)
   403   thus "r' =o r" unfolding ordIso_def using 1 by (auto simp add: iso_def)
   446 qed
   404 qed
   447 
   405 
   448 
       
   449 lemma ordLeq_ordLess_trans[trans]:
   406 lemma ordLeq_ordLess_trans[trans]:
   450 assumes "r \<le>o r'" and " r' <o r''"
   407 assumes "r \<le>o r'" and " r' <o r''"
   451 shows "r <o r''"
   408 shows "r <o r''"
   452 proof-
   409 proof-
   453   have "Well_order r \<and> Well_order r''"
   410   have "Well_order r \<and> Well_order r''"
   454   using assms unfolding ordLeq_def ordLess_def by auto
   411   using assms unfolding ordLeq_def ordLess_def by auto
   455   thus ?thesis using assms unfolding ordLeq_def ordLess_def
   412   thus ?thesis using assms unfolding ordLeq_def ordLess_def
   456   using embed_comp_embedS by blast
   413   using embed_comp_embedS by blast
   457 qed
   414 qed
   458 
   415 
   459 
       
   460 lemma ordLess_ordLeq_trans[trans]:
   416 lemma ordLess_ordLeq_trans[trans]:
   461 assumes "r <o r'" and " r' \<le>o r''"
   417 assumes "r <o r'" and " r' \<le>o r''"
   462 shows "r <o r''"
   418 shows "r <o r''"
   463 proof-
   419 proof-
   464   have "Well_order r \<and> Well_order r''"
   420   have "Well_order r \<and> Well_order r''"
   465   using assms unfolding ordLeq_def ordLess_def by auto
   421   using assms unfolding ordLeq_def ordLess_def by auto
   466   thus ?thesis using assms unfolding ordLeq_def ordLess_def
   422   thus ?thesis using assms unfolding ordLeq_def ordLess_def
   467   using embedS_comp_embed by blast
   423   using embedS_comp_embed by blast
   468 qed
   424 qed
   469 
   425 
   470 
       
   471 lemma ordLeq_ordIso_trans[trans]:
   426 lemma ordLeq_ordIso_trans[trans]:
   472 assumes "r \<le>o r'" and " r' =o r''"
   427 assumes "r \<le>o r'" and " r' =o r''"
   473 shows "r \<le>o r''"
   428 shows "r \<le>o r''"
   474 proof-
   429 proof-
   475   have "Well_order r \<and> Well_order r''"
   430   have "Well_order r \<and> Well_order r''"
   476   using assms unfolding ordLeq_def ordIso_def by auto
   431   using assms unfolding ordLeq_def ordIso_def by auto
   477   thus ?thesis using assms unfolding ordLeq_def ordIso_def
   432   thus ?thesis using assms unfolding ordLeq_def ordIso_def
   478   using embed_comp_iso by blast
   433   using embed_comp_iso by blast
   479 qed
   434 qed
   480 
   435 
   481 
       
   482 lemma ordIso_ordLeq_trans[trans]:
   436 lemma ordIso_ordLeq_trans[trans]:
   483 assumes "r =o r'" and " r' \<le>o r''"
   437 assumes "r =o r'" and " r' \<le>o r''"
   484 shows "r \<le>o r''"
   438 shows "r \<le>o r''"
   485 proof-
   439 proof-
   486   have "Well_order r \<and> Well_order r''"
   440   have "Well_order r \<and> Well_order r''"
   487   using assms unfolding ordLeq_def ordIso_def by auto
   441   using assms unfolding ordLeq_def ordIso_def by auto
   488   thus ?thesis using assms unfolding ordLeq_def ordIso_def
   442   thus ?thesis using assms unfolding ordLeq_def ordIso_def
   489   using iso_comp_embed by blast
   443   using iso_comp_embed by blast
   490 qed
   444 qed
   491 
   445 
   492 
       
   493 lemma ordLess_ordIso_trans[trans]:
   446 lemma ordLess_ordIso_trans[trans]:
   494 assumes "r <o r'" and " r' =o r''"
   447 assumes "r <o r'" and " r' =o r''"
   495 shows "r <o r''"
   448 shows "r <o r''"
   496 proof-
   449 proof-
   497   have "Well_order r \<and> Well_order r''"
   450   have "Well_order r \<and> Well_order r''"
   498   using assms unfolding ordLess_def ordIso_def by auto
   451   using assms unfolding ordLess_def ordIso_def by auto
   499   thus ?thesis using assms unfolding ordLess_def ordIso_def
   452   thus ?thesis using assms unfolding ordLess_def ordIso_def
   500   using embedS_comp_iso by blast
   453   using embedS_comp_iso by blast
   501 qed
   454 qed
   502 
   455 
   503 
       
   504 lemma ordIso_ordLess_trans[trans]:
   456 lemma ordIso_ordLess_trans[trans]:
   505 assumes "r =o r'" and " r' <o r''"
   457 assumes "r =o r'" and " r' <o r''"
   506 shows "r <o r''"
   458 shows "r <o r''"
   507 proof-
   459 proof-
   508   have "Well_order r \<and> Well_order r''"
   460   have "Well_order r \<and> Well_order r''"
   509   using assms unfolding ordLess_def ordIso_def by auto
   461   using assms unfolding ordLess_def ordIso_def by auto
   510   thus ?thesis using assms unfolding ordLess_def ordIso_def
   462   thus ?thesis using assms unfolding ordLess_def ordIso_def
   511   using iso_comp_embedS by blast
   463   using iso_comp_embedS by blast
   512 qed
   464 qed
   513 
       
   514 
   465 
   515 lemma ordLess_not_embed:
   466 lemma ordLess_not_embed:
   516 assumes "r <o r'"
   467 assumes "r <o r'"
   517 shows "\<not>(\<exists>f'. embed r' r f')"
   468 shows "\<not>(\<exists>f'. embed r' r f')"
   518 proof-
   469 proof-
   524    by (simp add: embed_bothWays_Field_bij_betw)
   475    by (simp add: embed_bothWays_Field_bij_betw)
   525    with 3 have False by contradiction
   476    with 3 have False by contradiction
   526   }
   477   }
   527   thus ?thesis by blast
   478   thus ?thesis by blast
   528 qed
   479 qed
   529 
       
   530 
   480 
   531 lemma ordLess_Field:
   481 lemma ordLess_Field:
   532 assumes OL: "r1 <o r2" and EMB: "embed r1 r2 f"
   482 assumes OL: "r1 <o r2" and EMB: "embed r1 r2 f"
   533 shows "\<not> (f`(Field r1) = Field r2)"
   483 shows "\<not> (f`(Field r1) = Field r2)"
   534 proof-
   484 proof-
   543   using 1 bij_betw_cong[of ?A1] by blast
   493   using 1 bij_betw_cong[of ?A1] by blast
   544   moreover
   494   moreover
   545   have "inj_on f ?A1" using EMB 0 by (simp add: embed_inj_on)
   495   have "inj_on f ?A1" using EMB 0 by (simp add: embed_inj_on)
   546   ultimately show ?thesis by (simp add: bij_betw_def)
   496   ultimately show ?thesis by (simp add: bij_betw_def)
   547 qed
   497 qed
   548 
       
   549 
   498 
   550 lemma ordLess_iff:
   499 lemma ordLess_iff:
   551 "r <o r' = (Well_order r \<and> Well_order r' \<and> \<not>(\<exists>f'. embed r' r f'))"
   500 "r <o r' = (Well_order r \<and> Well_order r' \<and> \<not>(\<exists>f'. embed r' r f'))"
   552 proof
   501 proof
   553   assume *: "r <o r'"
   502   assume *: "r <o r'"
   566   }
   515   }
   567   ultimately show "(r,r') \<in> ordLess"
   516   ultimately show "(r,r') \<in> ordLess"
   568   unfolding ordLess_def using * by (fastforce simp add: embedS_def)
   517   unfolding ordLess_def using * by (fastforce simp add: embedS_def)
   569 qed
   518 qed
   570 
   519 
   571 
       
   572 lemma ordLess_irreflexive: "\<not> r <o r"
   520 lemma ordLess_irreflexive: "\<not> r <o r"
   573 proof
   521 proof
   574   assume "r <o r"
   522   assume "r <o r"
   575   hence "Well_order r \<and>  \<not>(\<exists>f. embed r r f)"
   523   hence "Well_order r \<and>  \<not>(\<exists>f. embed r r f)"
   576   unfolding ordLess_iff ..
   524   unfolding ordLess_iff ..
   577   moreover have "embed r r id" using id_embed[of r] .
   525   moreover have "embed r r id" using id_embed[of r] .
   578   ultimately show False by blast
   526   ultimately show False by blast
   579 qed
   527 qed
   580 
   528 
   581 
       
   582 lemma ordLeq_iff_ordLess_or_ordIso:
   529 lemma ordLeq_iff_ordLess_or_ordIso:
   583 "r \<le>o r' = (r <o r' \<or> r =o r')"
   530 "r \<le>o r' = (r <o r' \<or> r =o r')"
   584 unfolding ordRels_def embedS_defs iso_defs by blast
   531 unfolding ordRels_def embedS_defs iso_defs by blast
   585 
       
   586 
   532 
   587 lemma ordIso_iff_ordLeq:
   533 lemma ordIso_iff_ordLeq:
   588 "(r =o r') = (r \<le>o r' \<and> r' \<le>o r)"
   534 "(r =o r') = (r \<le>o r' \<and> r' \<le>o r)"
   589 proof
   535 proof
   590   assume "r =o r'"
   536   assume "r =o r'"
   602   unfolding ordLeq_def by auto
   548   unfolding ordLeq_def by auto
   603   hence "iso r r' f" by (auto simp add: embed_bothWays_iso)
   549   hence "iso r r' f" by (auto simp add: embed_bothWays_iso)
   604   thus "r =o r'" unfolding ordIso_def using 1 by auto
   550   thus "r =o r'" unfolding ordIso_def using 1 by auto
   605 qed
   551 qed
   606 
   552 
   607 
       
   608 lemma not_ordLess_ordLeq:
   553 lemma not_ordLess_ordLeq:
   609 "r <o r' \<Longrightarrow> \<not> r' \<le>o r"
   554 "r <o r' \<Longrightarrow> \<not> r' \<le>o r"
   610 using ordLess_ordLeq_trans ordLess_irreflexive by blast
   555 using ordLess_ordLeq_trans ordLess_irreflexive by blast
   611 
       
   612 
   556 
   613 lemma ordLess_or_ordLeq:
   557 lemma ordLess_or_ordLeq:
   614 assumes WELL: "Well_order r" and WELL': "Well_order r'"
   558 assumes WELL: "Well_order r" and WELL': "Well_order r'"
   615 shows "r <o r' \<or> r' \<le>o r"
   559 shows "r <o r' \<or> r' \<le>o r"
   616 proof-
   560 proof-
   622    hence "r' \<le>o r" using ordIso_symmetric ordIso_iff_ordLeq by blast
   566    hence "r' \<le>o r" using ordIso_symmetric ordIso_iff_ordLeq by blast
   623   }
   567   }
   624   ultimately show ?thesis by blast
   568   ultimately show ?thesis by blast
   625 qed
   569 qed
   626 
   570 
   627 
       
   628 lemma not_ordLess_ordIso:
   571 lemma not_ordLess_ordIso:
   629 "r <o r' \<Longrightarrow> \<not> r =o r'"
   572 "r <o r' \<Longrightarrow> \<not> r =o r'"
   630 using assms ordLess_ordIso_trans ordIso_symmetric ordLess_irreflexive by blast
   573 using assms ordLess_ordIso_trans ordIso_symmetric ordLess_irreflexive by blast
   631 
       
   632 
   574 
   633 lemma not_ordLeq_iff_ordLess:
   575 lemma not_ordLeq_iff_ordLess:
   634 assumes WELL: "Well_order r" and WELL': "Well_order r'"
   576 assumes WELL: "Well_order r" and WELL': "Well_order r'"
   635 shows "(\<not> r' \<le>o r) = (r <o r')"
   577 shows "(\<not> r' \<le>o r) = (r <o r')"
   636 using assms not_ordLess_ordLeq ordLess_or_ordLeq by blast
   578 using assms not_ordLess_ordLeq ordLess_or_ordLeq by blast
   637 
   579 
   638 
       
   639 lemma not_ordLess_iff_ordLeq:
   580 lemma not_ordLess_iff_ordLeq:
   640 assumes WELL: "Well_order r" and WELL': "Well_order r'"
   581 assumes WELL: "Well_order r" and WELL': "Well_order r'"
   641 shows "(\<not> r' <o r) = (r \<le>o r')"
   582 shows "(\<not> r' <o r) = (r \<le>o r')"
   642 using assms not_ordLess_ordLeq ordLess_or_ordLeq by blast
   583 using assms not_ordLess_ordLeq ordLess_or_ordLeq by blast
   643 
   584 
   644 
       
   645 lemma ordLess_transitive[trans]:
   585 lemma ordLess_transitive[trans]:
   646 "\<lbrakk>r <o r'; r' <o r''\<rbrakk> \<Longrightarrow> r <o r''"
   586 "\<lbrakk>r <o r'; r' <o r''\<rbrakk> \<Longrightarrow> r <o r''"
   647 using assms ordLess_ordLeq_trans ordLeq_iff_ordLess_or_ordIso by blast
   587 using assms ordLess_ordLeq_trans ordLeq_iff_ordLess_or_ordIso by blast
   648 
   588 
   649 
       
   650 corollary ordLess_trans: "trans ordLess"
   589 corollary ordLess_trans: "trans ordLess"
   651 unfolding trans_def using ordLess_transitive by blast
   590 unfolding trans_def using ordLess_transitive by blast
   652 
   591 
   653 
       
   654 lemmas ordIso_equivalence = ordIso_transitive ordIso_reflexive ordIso_symmetric
   592 lemmas ordIso_equivalence = ordIso_transitive ordIso_reflexive ordIso_symmetric
   655 
       
   656 
   593 
   657 lemma ordIso_imp_ordLeq:
   594 lemma ordIso_imp_ordLeq:
   658 "r =o r' \<Longrightarrow> r \<le>o r'"
   595 "r =o r' \<Longrightarrow> r \<le>o r'"
   659 using ordIso_iff_ordLeq by blast
   596 using ordIso_iff_ordLeq by blast
   660 
   597 
   661 
       
   662 lemma ordLess_imp_ordLeq:
   598 lemma ordLess_imp_ordLeq:
   663 "r <o r' \<Longrightarrow> r \<le>o r'"
   599 "r <o r' \<Longrightarrow> r \<le>o r'"
   664 using ordLeq_iff_ordLess_or_ordIso by blast
   600 using ordLeq_iff_ordLess_or_ordIso by blast
   665 
       
   666 
   601 
   667 lemma ofilter_subset_ordLeq:
   602 lemma ofilter_subset_ordLeq:
   668 assumes WELL: "Well_order r" and
   603 assumes WELL: "Well_order r" and
   669         OFA: "wo_rel.ofilter r A" and OFB: "wo_rel.ofilter r B"
   604         OFA: "wo_rel.ofilter r A" and OFB: "wo_rel.ofilter r B"
   670 shows "(A \<le> B) = (Restr r A \<le>o Restr r B)"
   605 shows "(A \<le> B) = (Restr r A \<le>o Restr r B)"
   685   }
   620   }
   686   thus "A \<le> B" using OFA OFB WELL
   621   thus "A \<le> B" using OFA OFB WELL
   687   wo_rel_def[of r] wo_rel.ofilter_linord[of r A B] by blast
   622   wo_rel_def[of r] wo_rel.ofilter_linord[of r A B] by blast
   688 qed
   623 qed
   689 
   624 
   690 
       
   691 lemma ofilter_subset_ordLess:
   625 lemma ofilter_subset_ordLess:
   692 assumes WELL: "Well_order r" and
   626 assumes WELL: "Well_order r" and
   693         OFA: "wo_rel.ofilter r A" and OFB: "wo_rel.ofilter r B"
   627         OFA: "wo_rel.ofilter r A" and OFB: "wo_rel.ofilter r B"
   694 shows "(A < B) = (Restr r A <o Restr r B)"
   628 shows "(A < B) = (Restr r A <o Restr r B)"
   695 proof-
   629 proof-
   703   also have "\<dots> = (Restr r A <o Restr r B)"
   637   also have "\<dots> = (Restr r A <o Restr r B)"
   704   using 1 not_ordLeq_iff_ordLess by blast
   638   using 1 not_ordLeq_iff_ordLess by blast
   705   finally show ?thesis .
   639   finally show ?thesis .
   706 qed
   640 qed
   707 
   641 
   708 
       
   709 lemma ofilter_ordLess:
   642 lemma ofilter_ordLess:
   710 "\<lbrakk>Well_order r; wo_rel.ofilter r A\<rbrakk> \<Longrightarrow> (A < Field r) = (Restr r A <o r)"
   643 "\<lbrakk>Well_order r; wo_rel.ofilter r A\<rbrakk> \<Longrightarrow> (A < Field r) = (Restr r A <o r)"
   711 by (simp add: ofilter_subset_ordLess wo_rel.Field_ofilter
   644 by (simp add: ofilter_subset_ordLess wo_rel.Field_ofilter
   712     wo_rel_def Restr_Field)
   645     wo_rel_def Restr_Field)
   713 
   646 
   714 
       
   715 corollary underS_Restr_ordLess:
   647 corollary underS_Restr_ordLess:
   716 assumes "Well_order r" and "Field r \<noteq> {}"
   648 assumes "Well_order r" and "Field r \<noteq> {}"
   717 shows "Restr r (underS r a) <o r"
   649 shows "Restr r (underS r a) <o r"
   718 proof-
   650 proof-
   719   have "underS r a < Field r" using assms
   651   have "underS r a < Field r" using assms
   720   by (simp add: underS_Field3)
   652   by (simp add: underS_Field3)
   721   thus ?thesis using assms
   653   thus ?thesis using assms
   722   by (simp add: ofilter_ordLess wo_rel.underS_ofilter wo_rel_def)
   654   by (simp add: ofilter_ordLess wo_rel.underS_ofilter wo_rel_def)
   723 qed
   655 qed
   724 
       
   725 
   656 
   726 lemma embed_ordLess_ofilterIncl:
   657 lemma embed_ordLess_ofilterIncl:
   727 assumes
   658 assumes
   728   OL12: "r1 <o r2" and OL23: "r2 <o r3" and
   659   OL12: "r1 <o r2" and OL23: "r2 <o r3" and
   729   EMB13: "embed r1 r3 f13" and EMB23: "embed r2 r3 f23"
   660   EMB13: "embed r1 r3 f13" and EMB23: "embed r2 r3 f23"
   767   (*  *)
   698   (*  *)
   768   with 5 6 show ?thesis
   699   with 5 6 show ?thesis
   769   unfolding ofilterIncl_def by auto
   700   unfolding ofilterIncl_def by auto
   770 qed
   701 qed
   771 
   702 
   772 
       
   773 lemma ordLess_iff_ordIso_Restr:
   703 lemma ordLess_iff_ordIso_Restr:
   774 assumes WELL: "Well_order r" and WELL': "Well_order r'"
   704 assumes WELL: "Well_order r" and WELL': "Well_order r'"
   775 shows "(r' <o r) = (\<exists>a \<in> Field r. r' =o Restr r (underS r a))"
   705 shows "(r' <o r) = (\<exists>a \<in> Field r. r' =o Restr r (underS r a))"
   776 proof(auto)
   706 proof(auto)
   777   fix a assume *: "a \<in> Field r" and **: "r' =o Restr r (underS r a)"
   707   fix a assume *: "a \<in> Field r" and **: "r' =o Restr r (underS r a)"
   793   using WELL' unfolding ordIso_def by auto
   723   using WELL' unfolding ordIso_def by auto
   794   hence "r' =o Restr r (underS r a)" using 4 by auto
   724   hence "r' =o Restr r (underS r a)" using 4 by auto
   795   thus "\<exists>a \<in> Field r. r' =o Restr r (underS r a)" using 3 by auto
   725   thus "\<exists>a \<in> Field r. r' =o Restr r (underS r a)" using 3 by auto
   796 qed
   726 qed
   797 
   727 
   798 
       
   799 lemma internalize_ordLess:
   728 lemma internalize_ordLess:
   800 "(r' <o r) = (\<exists>p. Field p < Field r \<and> r' =o p \<and> p <o r)"
   729 "(r' <o r) = (\<exists>p. Field p < Field r \<and> r' =o p \<and> p <o r)"
   801 proof
   730 proof
   802   assume *: "r' <o r"
   731   assume *: "r' <o r"
   803   hence 0: "Well_order r \<and> Well_order r'" unfolding ordLess_def by auto
   732   hence 0: "Well_order r \<and> Well_order r'" unfolding ordLess_def by auto
   814 next
   743 next
   815   assume "\<exists>p. Field p < Field r \<and> r' =o p \<and> p <o r"
   744   assume "\<exists>p. Field p < Field r \<and> r' =o p \<and> p <o r"
   816   thus "r' <o r" using ordIso_ordLess_trans by blast
   745   thus "r' <o r" using ordIso_ordLess_trans by blast
   817 qed
   746 qed
   818 
   747 
   819 
       
   820 lemma internalize_ordLeq:
   748 lemma internalize_ordLeq:
   821 "(r' \<le>o r) = (\<exists>p. Field p \<le> Field r \<and> r' =o p \<and> p \<le>o r)"
   749 "(r' \<le>o r) = (\<exists>p. Field p \<le> Field r \<and> r' =o p \<and> p \<le>o r)"
   822 proof
   750 proof
   823   assume *: "r' \<le>o r"
   751   assume *: "r' \<le>o r"
   824   moreover
   752   moreover
   835 next
   763 next
   836   assume "\<exists>p. Field p \<le> Field r \<and> r' =o p \<and> p \<le>o r"
   764   assume "\<exists>p. Field p \<le> Field r \<and> r' =o p \<and> p \<le>o r"
   837   thus "r' \<le>o r" using ordIso_ordLeq_trans by blast
   765   thus "r' \<le>o r" using ordIso_ordLeq_trans by blast
   838 qed
   766 qed
   839 
   767 
   840 
       
   841 lemma ordLeq_iff_ordLess_Restr:
   768 lemma ordLeq_iff_ordLess_Restr:
   842 assumes WELL: "Well_order r" and WELL': "Well_order r'"
   769 assumes WELL: "Well_order r" and WELL': "Well_order r'"
   843 shows "(r \<le>o r') = (\<forall>a \<in> Field r. Restr r (underS r a) <o r')"
   770 shows "(r \<le>o r') = (\<forall>a \<in> Field r. Restr r (underS r a) <o r')"
   844 proof(auto)
   771 proof(auto)
   845   assume *: "r \<le>o r'"
   772   assume *: "r \<le>o r'"
   856    hence False using * not_ordLess_ordIso ordIso_symmetric by blast
   783    hence False using * not_ordLess_ordIso ordIso_symmetric by blast
   857   }
   784   }
   858   thus "r \<le>o r'" using ordLess_or_ordLeq assms by blast
   785   thus "r \<le>o r'" using ordLess_or_ordLeq assms by blast
   859 qed
   786 qed
   860 
   787 
   861 
       
   862 lemma finite_ordLess_infinite:
   788 lemma finite_ordLess_infinite:
   863 assumes WELL: "Well_order r" and WELL': "Well_order r'" and
   789 assumes WELL: "Well_order r" and WELL': "Well_order r'" and
   864         FIN: "finite(Field r)" and INF: "\<not>finite(Field r')"
   790         FIN: "finite(Field r)" and INF: "\<not>finite(Field r')"
   865 shows "r <o r'"
   791 shows "r <o r'"
   866 proof-
   792 proof-
   869    unfolding ordLeq_def using assms embed_inj_on embed_Field by blast
   795    unfolding ordLeq_def using assms embed_inj_on embed_Field by blast
   870    hence False using finite_imageD finite_subset FIN INF by metis
   796    hence False using finite_imageD finite_subset FIN INF by metis
   871   }
   797   }
   872   thus ?thesis using WELL WELL' ordLess_or_ordLeq by blast
   798   thus ?thesis using WELL WELL' ordLess_or_ordLeq by blast
   873 qed
   799 qed
   874 
       
   875 
   800 
   876 lemma finite_well_order_on_ordIso:
   801 lemma finite_well_order_on_ordIso:
   877 assumes FIN: "finite A" and
   802 assumes FIN: "finite A" and
   878         WELL: "well_order_on A r" and WELL': "well_order_on A r'"
   803         WELL: "well_order_on A r" and WELL': "well_order_on A r'"
   879 shows "r =o r'"
   804 shows "r =o r'"
   895     thus "r =o r'" unfolding ordIso_def iso_def[abs_def] using 1 2 by auto
   820     thus "r =o r'" unfolding ordIso_def iso_def[abs_def] using 1 2 by auto
   896   qed
   821   qed
   897   ultimately show ?thesis using assms ordLeq_total ordIso_symmetric by metis
   822   ultimately show ?thesis using assms ordLeq_total ordIso_symmetric by metis
   898 qed
   823 qed
   899 
   824 
   900 
       
   901 subsection{* @{text "<o"} is well-founded *}
   825 subsection{* @{text "<o"} is well-founded *}
   902 
       
   903 
   826 
   904 text {* Of course, it only makes sense to state that the @{text "<o"} is well-founded
   827 text {* Of course, it only makes sense to state that the @{text "<o"} is well-founded
   905 on the restricted type @{text "'a rel rel"}.  We prove this by first showing that, for any set
   828 on the restricted type @{text "'a rel rel"}.  We prove this by first showing that, for any set
   906 of well-orders all embedded in a fixed well-order, the function mapping each well-order
   829 of well-orders all embedded in a fixed well-order, the function mapping each well-order
   907 in the set to an order filter of the fixed well-order is compatible w.r.t. to @{text "<o"} versus
   830 in the set to an order filter of the fixed well-order is compatible w.r.t. to @{text "<o"} versus
   908 {\em strict inclusion}; and we already know that strict inclusion of order filters is well-founded. *}
   831 {\em strict inclusion}; and we already know that strict inclusion of order filters is well-founded. *}
   909 
   832 
   910 
       
   911 definition ord_to_filter :: "'a rel \<Rightarrow> 'a rel \<Rightarrow> 'a set"
   833 definition ord_to_filter :: "'a rel \<Rightarrow> 'a rel \<Rightarrow> 'a set"
   912 where "ord_to_filter r0 r \<equiv> (SOME f. embed r r0 f) ` (Field r)"
   834 where "ord_to_filter r0 r \<equiv> (SOME f. embed r r0 f) ` (Field r)"
   913 
       
   914 
   835 
   915 lemma ord_to_filter_compat:
   836 lemma ord_to_filter_compat:
   916 "compat (ordLess Int (ordLess^-1``{r0} \<times> ordLess^-1``{r0}))
   837 "compat (ordLess Int (ordLess^-1``{r0} \<times> ordLess^-1``{r0}))
   917         (ofilterIncl r0)
   838         (ofilterIncl r0)
   918         (ord_to_filter r0)"
   839         (ord_to_filter r0)"
   926   by (auto simp add: ordLess_def embedS_def)
   847   by (auto simp add: ordLess_def embedS_def)
   927   hence "?phi10 ?f10 \<and> ?phi20 ?f20" by (auto simp add: someI_ex)
   848   hence "?phi10 ?f10 \<and> ?phi20 ?f20" by (auto simp add: someI_ex)
   928   thus "(?f10 ` ?A1, ?f20 ` ?A2) \<in> ofilterIncl r0"
   849   thus "(?f10 ` ?A1, ?f20 ` ?A2) \<in> ofilterIncl r0"
   929   using * ** by (simp add: embed_ordLess_ofilterIncl)
   850   using * ** by (simp add: embed_ordLess_ofilterIncl)
   930 qed
   851 qed
   931 
       
   932 
   852 
   933 theorem wf_ordLess: "wf ordLess"
   853 theorem wf_ordLess: "wf ordLess"
   934 proof-
   854 proof-
   935   {fix r0 :: "('a \<times> 'a) set"
   855   {fix r0 :: "('a \<times> 'a) set"
   936    (* need to annotate here!*)
   856    (* need to annotate here!*)
   961     equals0I[of R] by blast
   881     equals0I[of R] by blast
   962   with not_ordLeq_iff_ordLess WELL show ?thesis by blast
   882   with not_ordLeq_iff_ordLess WELL show ?thesis by blast
   963 qed
   883 qed
   964 
   884 
   965 
   885 
   966 
   886 subsection {* Copy via direct images *}
   967 subsection {* Copy via direct images  *}
       
   968 
       
   969 
   887 
   970 text{* The direct image operator is the dual of the inverse image operator @{text "inv_image"}
   888 text{* The direct image operator is the dual of the inverse image operator @{text "inv_image"}
   971 from @{text "Relation.thy"}.  It is useful for transporting a well-order between
   889 from @{text "Relation.thy"}.  It is useful for transporting a well-order between
   972 different types. *}
   890 different types. *}
   973 
   891 
   974 
       
   975 definition dir_image :: "'a rel \<Rightarrow> ('a \<Rightarrow> 'a') \<Rightarrow> 'a' rel"
   892 definition dir_image :: "'a rel \<Rightarrow> ('a \<Rightarrow> 'a') \<Rightarrow> 'a' rel"
   976 where
   893 where
   977 "dir_image r f = {(f a, f b)| a b. (a,b) \<in> r}"
   894 "dir_image r f = {(f a, f b)| a b. (a,b) \<in> r}"
   978 
   895 
   979 
       
   980 lemma dir_image_Field:
   896 lemma dir_image_Field:
   981 "Field(dir_image r f) \<le> f ` (Field r)"
   897 "Field(dir_image r f) \<le> f ` (Field r)"
   982 unfolding dir_image_def Field_def by auto
   898 unfolding dir_image_def Field_def by auto
   983 
   899 
   984 
       
   985 lemma dir_image_minus_Id:
   900 lemma dir_image_minus_Id:
   986 "inj_on f (Field r) \<Longrightarrow> (dir_image r f) - Id = dir_image (r - Id) f"
   901 "inj_on f (Field r) \<Longrightarrow> (dir_image r f) - Id = dir_image (r - Id) f"
   987 unfolding inj_on_def Field_def dir_image_def by auto
   902 unfolding inj_on_def Field_def dir_image_def by auto
   988 
       
   989 
   903 
   990 lemma Refl_dir_image:
   904 lemma Refl_dir_image:
   991 assumes "Refl r"
   905 assumes "Refl r"
   992 shows "Refl(dir_image r f)"
   906 shows "Refl(dir_image r f)"
   993 proof-
   907 proof-
  1001    unfolding dir_image_def by auto
   915    unfolding dir_image_def by auto
  1002   }
   916   }
  1003   thus ?thesis
   917   thus ?thesis
  1004   by(unfold refl_on_def Field_def Domain_def Range_def, auto)
   918   by(unfold refl_on_def Field_def Domain_def Range_def, auto)
  1005 qed
   919 qed
  1006 
       
  1007 
   920 
  1008 lemma trans_dir_image:
   921 lemma trans_dir_image:
  1009 assumes TRANS: "trans r" and INJ: "inj_on f (Field r)"
   922 assumes TRANS: "trans r" and INJ: "inj_on f (Field r)"
  1010 shows "trans(dir_image r f)"
   923 shows "trans(dir_image r f)"
  1011 proof(unfold trans_def, auto)
   924 proof(unfold trans_def, auto)
  1020   hence "(a,c): r" using 2 TRANS unfolding trans_def by blast
   933   hence "(a,c): r" using 2 TRANS unfolding trans_def by blast
  1021   thus "(a',c') \<in> dir_image r f"
   934   thus "(a',c') \<in> dir_image r f"
  1022   unfolding dir_image_def using 1 by auto
   935   unfolding dir_image_def using 1 by auto
  1023 qed
   936 qed
  1024 
   937 
  1025 
       
  1026 lemma Preorder_dir_image:
   938 lemma Preorder_dir_image:
  1027 "\<lbrakk>Preorder r; inj_on f (Field r)\<rbrakk> \<Longrightarrow> Preorder (dir_image r f)"
   939 "\<lbrakk>Preorder r; inj_on f (Field r)\<rbrakk> \<Longrightarrow> Preorder (dir_image r f)"
  1028 by (simp add: preorder_on_def Refl_dir_image trans_dir_image)
   940 by (simp add: preorder_on_def Refl_dir_image trans_dir_image)
  1029 
       
  1030 
   941 
  1031 lemma antisym_dir_image:
   942 lemma antisym_dir_image:
  1032 assumes AN: "antisym r" and INJ: "inj_on f (Field r)"
   943 assumes AN: "antisym r" and INJ: "inj_on f (Field r)"
  1033 shows "antisym(dir_image r f)"
   944 shows "antisym(dir_image r f)"
  1034 proof(unfold antisym_def, auto)
   945 proof(unfold antisym_def, auto)
  1041   hence "a1 = a2 \<and> b1 = b2" using INJ unfolding inj_on_def by auto
   952   hence "a1 = a2 \<and> b1 = b2" using INJ unfolding inj_on_def by auto
  1042   hence "a1 = b2" using 2 AN unfolding antisym_def by auto
   953   hence "a1 = b2" using 2 AN unfolding antisym_def by auto
  1043   thus "a' = b'" using 1 by auto
   954   thus "a' = b'" using 1 by auto
  1044 qed
   955 qed
  1045 
   956 
  1046 
       
  1047 lemma Partial_order_dir_image:
   957 lemma Partial_order_dir_image:
  1048 "\<lbrakk>Partial_order r; inj_on f (Field r)\<rbrakk> \<Longrightarrow> Partial_order (dir_image r f)"
   958 "\<lbrakk>Partial_order r; inj_on f (Field r)\<rbrakk> \<Longrightarrow> Partial_order (dir_image r f)"
  1049 by (simp add: partial_order_on_def Preorder_dir_image antisym_dir_image)
   959 by (simp add: partial_order_on_def Preorder_dir_image antisym_dir_image)
  1050 
       
  1051 
   960 
  1052 lemma Total_dir_image:
   961 lemma Total_dir_image:
  1053 assumes TOT: "Total r" and INJ: "inj_on f (Field r)"
   962 assumes TOT: "Total r" and INJ: "inj_on f (Field r)"
  1054 shows "Total(dir_image r f)"
   963 shows "Total(dir_image r f)"
  1055 proof(unfold total_on_def, intro ballI impI)
   964 proof(unfold total_on_def, intro ballI impI)
  1062   hence "(a,b) \<in> r \<or> (b,a) \<in> r" using 1 TOT unfolding total_on_def by auto
   971   hence "(a,b) \<in> r \<or> (b,a) \<in> r" using 1 TOT unfolding total_on_def by auto
  1063   thus "(a',b') \<in> dir_image r f \<or> (b',a') \<in> dir_image r f"
   972   thus "(a',b') \<in> dir_image r f \<or> (b',a') \<in> dir_image r f"
  1064   using 1 unfolding dir_image_def by auto
   973   using 1 unfolding dir_image_def by auto
  1065 qed
   974 qed
  1066 
   975 
  1067 
       
  1068 lemma Linear_order_dir_image:
   976 lemma Linear_order_dir_image:
  1069 "\<lbrakk>Linear_order r; inj_on f (Field r)\<rbrakk> \<Longrightarrow> Linear_order (dir_image r f)"
   977 "\<lbrakk>Linear_order r; inj_on f (Field r)\<rbrakk> \<Longrightarrow> Linear_order (dir_image r f)"
  1070 by (simp add: linear_order_on_def Partial_order_dir_image Total_dir_image)
   978 by (simp add: linear_order_on_def Partial_order_dir_image Total_dir_image)
  1071 
       
  1072 
   979 
  1073 lemma wf_dir_image:
   980 lemma wf_dir_image:
  1074 assumes WF: "wf r" and INJ: "inj_on f (Field r)"
   981 assumes WF: "wf r" and INJ: "inj_on f (Field r)"
  1075 shows "wf(dir_image r f)"
   982 shows "wf(dir_image r f)"
  1076 proof(unfold wf_eq_minimal2, intro allI impI, elim conjE)
   983 proof(unfold wf_eq_minimal2, intro allI impI, elim conjE)
  1093   qed
  1000   qed
  1094   thus "\<exists>a'\<in>A'. \<forall>b'\<in>A'. (b', a') \<notin> dir_image r f"
  1001   thus "\<exists>a'\<in>A'. \<forall>b'\<in>A'. (b', a') \<notin> dir_image r f"
  1095   using A_def 1 by blast
  1002   using A_def 1 by blast
  1096 qed
  1003 qed
  1097 
  1004 
  1098 
       
  1099 lemma Well_order_dir_image:
  1005 lemma Well_order_dir_image:
  1100 "\<lbrakk>Well_order r; inj_on f (Field r)\<rbrakk> \<Longrightarrow> Well_order (dir_image r f)"
  1006 "\<lbrakk>Well_order r; inj_on f (Field r)\<rbrakk> \<Longrightarrow> Well_order (dir_image r f)"
  1101 using assms unfolding well_order_on_def
  1007 using assms unfolding well_order_on_def
  1102 using Linear_order_dir_image[of r f] wf_dir_image[of "r - Id" f]
  1008 using Linear_order_dir_image[of r f] wf_dir_image[of "r - Id" f]
  1103   dir_image_minus_Id[of f r]
  1009   dir_image_minus_Id[of f r]
  1104   subset_inj_on[of f "Field r" "Field(r - Id)"]
  1010   subset_inj_on[of f "Field r" "Field(r - Id)"]
  1105   mono_Field[of "r - Id" r] by auto
  1011   mono_Field[of "r - Id" r] by auto
  1106 
  1012 
  1107 
       
  1108 lemma dir_image_Field2:
  1013 lemma dir_image_Field2:
  1109 "Refl r \<Longrightarrow> Field(dir_image r f) = f ` (Field r)"
  1014 "Refl r \<Longrightarrow> Field(dir_image r f) = f ` (Field r)"
  1110 unfolding Field_def dir_image_def refl_on_def Domain_def Range_def by blast
  1015 unfolding Field_def dir_image_def refl_on_def Domain_def Range_def by blast
  1111 
       
  1112 
  1016 
  1113 lemma dir_image_bij_betw:
  1017 lemma dir_image_bij_betw:
  1114 "\<lbrakk>Well_order r; inj_on f (Field r)\<rbrakk> \<Longrightarrow> bij_betw f (Field r) (Field (dir_image r f))"
  1018 "\<lbrakk>Well_order r; inj_on f (Field r)\<rbrakk> \<Longrightarrow> bij_betw f (Field r) (Field (dir_image r f))"
  1115 unfolding bij_betw_def
  1019 unfolding bij_betw_def
  1116 by (simp add: dir_image_Field2 order_on_defs)
  1020 by (simp add: dir_image_Field2 order_on_defs)
  1117 
  1021 
  1118 
       
  1119 lemma dir_image_compat:
  1022 lemma dir_image_compat:
  1120 "compat r (dir_image r f) f"
  1023 "compat r (dir_image r f) f"
  1121 unfolding compat_def dir_image_def by auto
  1024 unfolding compat_def dir_image_def by auto
  1122 
  1025 
  1123 
       
  1124 lemma dir_image_iso:
  1026 lemma dir_image_iso:
  1125 "\<lbrakk>Well_order r; inj_on f (Field r)\<rbrakk>  \<Longrightarrow> iso r (dir_image r f) f"
  1027 "\<lbrakk>Well_order r; inj_on f (Field r)\<rbrakk>  \<Longrightarrow> iso r (dir_image r f) f"
  1126 using iso_iff3 dir_image_compat dir_image_bij_betw Well_order_dir_image by blast
  1028 using iso_iff3 dir_image_compat dir_image_bij_betw Well_order_dir_image by blast
  1127 
  1029 
  1128 
       
  1129 lemma dir_image_ordIso:
  1030 lemma dir_image_ordIso:
  1130 "\<lbrakk>Well_order r; inj_on f (Field r)\<rbrakk>  \<Longrightarrow> r =o dir_image r f"
  1031 "\<lbrakk>Well_order r; inj_on f (Field r)\<rbrakk>  \<Longrightarrow> r =o dir_image r f"
  1131 unfolding ordIso_def using dir_image_iso Well_order_dir_image by blast
  1032 unfolding ordIso_def using dir_image_iso Well_order_dir_image by blast
  1132 
       
  1133 
  1033 
  1134 lemma Well_order_iso_copy:
  1034 lemma Well_order_iso_copy:
  1135 assumes WELL: "well_order_on A r" and BIJ: "bij_betw f A A'"
  1035 assumes WELL: "well_order_on A r" and BIJ: "bij_betw f A A'"
  1136 shows "\<exists>r'. well_order_on A' r' \<and> r =o r'"
  1036 shows "\<exists>r'. well_order_on A' r' \<and> r =o r'"
  1137 proof-
  1037 proof-
  1147    using 1 Well_order_dir_image BIJ unfolding bij_betw_def by blast
  1047    using 1 Well_order_dir_image BIJ unfolding bij_betw_def by blast
  1148    ultimately show ?thesis unfolding ordIso_def using 1 2 by blast
  1048    ultimately show ?thesis unfolding ordIso_def using 1 2 by blast
  1149 qed
  1049 qed
  1150 
  1050 
  1151 
  1051 
  1152 
  1052 subsection {* Bounded square *}
  1153 subsection {* Bounded square  *}
       
  1154 
       
  1155 
  1053 
  1156 text{* This construction essentially defines, for an order relation @{text "r"}, a lexicographic
  1054 text{* This construction essentially defines, for an order relation @{text "r"}, a lexicographic
  1157 order @{text "bsqr r"} on @{text "(Field r) \<times> (Field r)"}, applying the
  1055 order @{text "bsqr r"} on @{text "(Field r) \<times> (Field r)"}, applying the
  1158 following criteria (in this order):
  1056 following criteria (in this order):
  1159 \begin{itemize}
  1057 \begin{itemize}
  1166 at proving that the square of an infinite set has the same cardinal
  1064 at proving that the square of an infinite set has the same cardinal
  1167 as that set. The essential property required there (and which is ensured by this
  1065 as that set. The essential property required there (and which is ensured by this
  1168 construction) is that any proper order filter of the product order is included in a rectangle, i.e.,
  1066 construction) is that any proper order filter of the product order is included in a rectangle, i.e.,
  1169 in a product of proper filters on the original relation (assumed to be a well-order). *}
  1067 in a product of proper filters on the original relation (assumed to be a well-order). *}
  1170 
  1068 
  1171 
       
  1172 definition bsqr :: "'a rel => ('a * 'a)rel"
  1069 definition bsqr :: "'a rel => ('a * 'a)rel"
  1173 where
  1070 where
  1174 "bsqr r = {((a1,a2),(b1,b2)).
  1071 "bsqr r = {((a1,a2),(b1,b2)).
  1175            {a1,a2,b1,b2} \<le> Field r \<and>
  1072            {a1,a2,b1,b2} \<le> Field r \<and>
  1176            (a1 = b1 \<and> a2 = b2 \<or>
  1073            (a1 = b1 \<and> a2 = b2 \<or>
  1177             (wo_rel.max2 r a1 a2, wo_rel.max2 r b1 b2) \<in> r - Id \<or>
  1074             (wo_rel.max2 r a1 a2, wo_rel.max2 r b1 b2) \<in> r - Id \<or>
  1178             wo_rel.max2 r a1 a2 = wo_rel.max2 r b1 b2 \<and> (a1,b1) \<in> r - Id \<or>
  1075             wo_rel.max2 r a1 a2 = wo_rel.max2 r b1 b2 \<and> (a1,b1) \<in> r - Id \<or>
  1179             wo_rel.max2 r a1 a2 = wo_rel.max2 r b1 b2 \<and> a1 = b1  \<and> (a2,b2) \<in> r - Id
  1076             wo_rel.max2 r a1 a2 = wo_rel.max2 r b1 b2 \<and> a1 = b1  \<and> (a2,b2) \<in> r - Id
  1180            )}"
  1077            )}"
  1181 
       
  1182 
  1078 
  1183 lemma Field_bsqr:
  1079 lemma Field_bsqr:
  1184 "Field (bsqr r) = Field r \<times> Field r"
  1080 "Field (bsqr r) = Field r \<times> Field r"
  1185 proof
  1081 proof
  1186   show "Field (bsqr r) \<le> Field r \<times> Field r"
  1082   show "Field (bsqr r) \<le> Field r \<times> Field r"
  1200     hence "((a1,a2),(a1,a2)) \<in> bsqr r" unfolding bsqr_def by blast
  1096     hence "((a1,a2),(a1,a2)) \<in> bsqr r" unfolding bsqr_def by blast
  1201     thus "(a1,a2) \<in> Field (bsqr r)" unfolding Field_def by auto
  1097     thus "(a1,a2) \<in> Field (bsqr r)" unfolding Field_def by auto
  1202   qed
  1098   qed
  1203 qed
  1099 qed
  1204 
  1100 
  1205 
       
  1206 lemma bsqr_Refl: "Refl(bsqr r)"
  1101 lemma bsqr_Refl: "Refl(bsqr r)"
  1207 by(unfold refl_on_def Field_bsqr, auto simp add: bsqr_def)
  1102 by(unfold refl_on_def Field_bsqr, auto simp add: bsqr_def)
  1208 
       
  1209 
  1103 
  1210 lemma bsqr_Trans:
  1104 lemma bsqr_Trans:
  1211 assumes "Well_order r"
  1105 assumes "Well_order r"
  1212 shows "trans (bsqr r)"
  1106 shows "trans (bsqr r)"
  1213 proof(unfold trans_def, auto)
  1107 proof(unfold trans_def, auto)
  1294     }
  1188     }
  1295     ultimately show ?thesis using 0 1 by auto
  1189     ultimately show ?thesis using 0 1 by auto
  1296   qed
  1190   qed
  1297 qed
  1191 qed
  1298 
  1192 
  1299 
       
  1300 lemma bsqr_antisym:
  1193 lemma bsqr_antisym:
  1301 assumes "Well_order r"
  1194 assumes "Well_order r"
  1302 shows "antisym (bsqr r)"
  1195 shows "antisym (bsqr r)"
  1303 proof(unfold antisym_def, clarify)
  1196 proof(unfold antisym_def, clarify)
  1304   (* Preliminary facts *)
  1197   (* Preliminary facts *)
  1364      ultimately have ?thesis using 0 2 by auto
  1257      ultimately have ?thesis using 0 2 by auto
  1365     }
  1258     }
  1366     ultimately show ?thesis using 0 1 by blast
  1259     ultimately show ?thesis using 0 1 by blast
  1367   qed
  1260   qed
  1368 qed
  1261 qed
  1369 
       
  1370 
  1262 
  1371 lemma bsqr_Total:
  1263 lemma bsqr_Total:
  1372 assumes "Well_order r"
  1264 assumes "Well_order r"
  1373 shows "Total(bsqr r)"
  1265 shows "Total(bsqr r)"
  1374 proof-
  1266 proof-
  1483    qed
  1375    qed
  1484   }
  1376   }
  1485   thus ?thesis unfolding total_on_def by fast
  1377   thus ?thesis unfolding total_on_def by fast
  1486 qed
  1378 qed
  1487 
  1379 
  1488 
       
  1489 lemma bsqr_Linear_order:
  1380 lemma bsqr_Linear_order:
  1490 assumes "Well_order r"
  1381 assumes "Well_order r"
  1491 shows "Linear_order(bsqr r)"
  1382 shows "Linear_order(bsqr r)"
  1492 unfolding order_on_defs
  1383 unfolding order_on_defs
  1493 using assms bsqr_Refl bsqr_Trans bsqr_antisym bsqr_Total by blast
  1384 using assms bsqr_Refl bsqr_Trans bsqr_antisym bsqr_Total by blast
  1494 
       
  1495 
  1385 
  1496 lemma bsqr_Well_order:
  1386 lemma bsqr_Well_order:
  1497 assumes "Well_order r"
  1387 assumes "Well_order r"
  1498 shows "Well_order(bsqr r)"
  1388 shows "Well_order(bsqr r)"
  1499 using assms
  1389 using assms
  1555   }
  1445   }
  1556   (*  *)
  1446   (*  *)
  1557   ultimately show "\<exists>d \<in> D. \<forall>d' \<in> D. (d,d') \<in> bsqr r" by fastforce
  1447   ultimately show "\<exists>d \<in> D. \<forall>d' \<in> D. (d,d') \<in> bsqr r" by fastforce
  1558 qed
  1448 qed
  1559 
  1449 
  1560 
       
  1561 lemma bsqr_max2:
  1450 lemma bsqr_max2:
  1562 assumes WELL: "Well_order r" and LEQ: "((a1,a2),(b1,b2)) \<in> bsqr r"
  1451 assumes WELL: "Well_order r" and LEQ: "((a1,a2),(b1,b2)) \<in> bsqr r"
  1563 shows "(wo_rel.max2 r a1 a2, wo_rel.max2 r b1 b2) \<in> r"
  1452 shows "(wo_rel.max2 r a1 a2, wo_rel.max2 r b1 b2) \<in> r"
  1564 proof-
  1453 proof-
  1565   have "{(a1,a2),(b1,b2)} \<le> Field(bsqr r)"
  1454   have "{(a1,a2),(b1,b2)} \<le> Field(bsqr r)"
  1569   using WELL wo_rel_def[of r] wo_rel.max2_among[of r] by fastforce
  1458   using WELL wo_rel_def[of r] wo_rel.max2_among[of r] by fastforce
  1570   moreover have "(wo_rel.max2 r a1 a2, wo_rel.max2 r b1 b2) \<in> r \<or> wo_rel.max2 r a1 a2 = wo_rel.max2 r b1 b2"
  1459   moreover have "(wo_rel.max2 r a1 a2, wo_rel.max2 r b1 b2) \<in> r \<or> wo_rel.max2 r a1 a2 = wo_rel.max2 r b1 b2"
  1571   using LEQ unfolding bsqr_def by auto
  1460   using LEQ unfolding bsqr_def by auto
  1572   ultimately show ?thesis using WELL unfolding order_on_defs refl_on_def by auto
  1461   ultimately show ?thesis using WELL unfolding order_on_defs refl_on_def by auto
  1573 qed
  1462 qed
  1574 
       
  1575 
  1463 
  1576 lemma bsqr_ofilter:
  1464 lemma bsqr_ofilter:
  1577 assumes WELL: "Well_order r" and
  1465 assumes WELL: "Well_order r" and
  1578         OF: "wo_rel.ofilter (bsqr r) D" and SUB: "D < Field r \<times> Field r" and
  1466         OF: "wo_rel.ofilter (bsqr r) D" and SUB: "D < Field r \<times> Field r" and
  1579         NE: "\<not> (\<exists>a. Field r = under r a)"
  1467         NE: "\<not> (\<exists>a. Field r = under r a)"