src/HOL/Cardinals/Cardinal_Order_Relation.thy
author blanchet
Mon Jan 20 22:24:48 2014 +0100 (2014-01-20)
changeset 55087 252c7fec4119
parent 55056 b5c94200d081
child 55102 761e40ce91bc
permissions -rw-r--r--
renamed 'regular' to 'regularCard' to avoid clashes (e.g. in Meson_Test)
     1 (*  Title:      HOL/Cardinals/Cardinal_Order_Relation.thy
     2     Author:     Andrei Popescu, TU Muenchen
     3     Copyright   2012
     4 
     5 Cardinal-order relations.
     6 *)
     7 
     8 header {* Cardinal-Order Relations *}
     9 
    10 theory Cardinal_Order_Relation
    11 imports BNF_Cardinal_Order_Relation Constructions_on_Wellorders
    12 begin
    13 
    14 declare
    15   card_order_on_well_order_on[simp]
    16   card_of_card_order_on[simp]
    17   card_of_well_order_on[simp]
    18   Field_card_of[simp]
    19   card_of_Card_order[simp]
    20   card_of_Well_order[simp]
    21   card_of_least[simp]
    22   card_of_unique[simp]
    23   card_of_mono1[simp]
    24   card_of_mono2[simp]
    25   card_of_cong[simp]
    26   card_of_Field_ordLess[simp]
    27   card_of_Field_ordIso[simp]
    28   card_of_underS[simp]
    29   ordLess_Field[simp]
    30   card_of_empty[simp]
    31   card_of_empty1[simp]
    32   card_of_image[simp]
    33   card_of_singl_ordLeq[simp]
    34   Card_order_singl_ordLeq[simp]
    35   card_of_Pow[simp]
    36   Card_order_Pow[simp]
    37   card_of_Plus1[simp]
    38   Card_order_Plus1[simp]
    39   card_of_Plus2[simp]
    40   Card_order_Plus2[simp]
    41   card_of_Plus_mono1[simp]
    42   card_of_Plus_mono2[simp]
    43   card_of_Plus_mono[simp]
    44   card_of_Plus_cong2[simp]
    45   card_of_Plus_cong[simp]
    46   card_of_Un_Plus_ordLeq[simp]
    47   card_of_Times1[simp]
    48   card_of_Times2[simp]
    49   card_of_Times3[simp]
    50   card_of_Times_mono1[simp]
    51   card_of_Times_mono2[simp]
    52   card_of_ordIso_finite[simp]
    53   card_of_Times_same_infinite[simp]
    54   card_of_Times_infinite_simps[simp]
    55   card_of_Plus_infinite1[simp]
    56   card_of_Plus_infinite2[simp]
    57   card_of_Plus_ordLess_infinite[simp]
    58   card_of_Plus_ordLess_infinite_Field[simp]
    59   infinite_cartesian_product[simp]
    60   cardSuc_Card_order[simp]
    61   cardSuc_greater[simp]
    62   cardSuc_ordLeq[simp]
    63   cardSuc_ordLeq_ordLess[simp]
    64   cardSuc_mono_ordLeq[simp]
    65   cardSuc_invar_ordIso[simp]
    66   card_of_cardSuc_finite[simp]
    67   cardSuc_finite[simp]
    68   card_of_Plus_ordLeq_infinite_Field[simp]
    69   curr_in[intro, simp]
    70 
    71 
    72 subsection {* Cardinal of a set *}
    73 
    74 lemma card_of_inj_rel: assumes INJ: "!! x y y'. \<lbrakk>(x,y) : R; (x,y') : R\<rbrakk> \<Longrightarrow> y = y'"
    75 shows "|{y. EX x. (x,y) : R}| <=o |{x. EX y. (x,y) : R}|"
    76 proof-
    77   let ?Y = "{y. EX x. (x,y) : R}"  let ?X = "{x. EX y. (x,y) : R}"
    78   let ?f = "% y. SOME x. (x,y) : R"
    79   have "?f ` ?Y <= ?X" by (auto dest: someI)
    80   moreover have "inj_on ?f ?Y"
    81   unfolding inj_on_def proof(auto)
    82     fix y1 x1 y2 x2
    83     assume *: "(x1, y1) \<in> R" "(x2, y2) \<in> R" and **: "?f y1 = ?f y2"
    84     hence "(?f y1,y1) : R" using someI[of "% x. (x,y1) : R"] by auto
    85     moreover have "(?f y2,y2) : R" using * someI[of "% x. (x,y2) : R"] by auto
    86     ultimately show "y1 = y2" using ** INJ by auto
    87   qed
    88   ultimately show "|?Y| <=o |?X|" using card_of_ordLeq by blast
    89 qed
    90 
    91 lemma card_of_unique2: "\<lbrakk>card_order_on B r; bij_betw f A B\<rbrakk> \<Longrightarrow> r =o |A|"
    92 using card_of_ordIso card_of_unique ordIso_equivalence by blast
    93 
    94 lemma internalize_card_of_ordLess:
    95 "( |A| <o r) = (\<exists>B < Field r. |A| =o |B| \<and> |B| <o r)"
    96 proof
    97   assume "|A| <o r"
    98   then obtain p where 1: "Field p < Field r \<and> |A| =o p \<and> p <o r"
    99   using internalize_ordLess[of "|A|" r] by blast
   100   hence "Card_order p" using card_of_Card_order Card_order_ordIso2 by blast
   101   hence "|Field p| =o p" using card_of_Field_ordIso by blast
   102   hence "|A| =o |Field p| \<and> |Field p| <o r"
   103   using 1 ordIso_equivalence ordIso_ordLess_trans by blast
   104   thus "\<exists>B < Field r. |A| =o |B| \<and> |B| <o r" using 1 by blast
   105 next
   106   assume "\<exists>B < Field r. |A| =o |B| \<and> |B| <o r"
   107   thus "|A| <o r" using ordIso_ordLess_trans by blast
   108 qed
   109 
   110 lemma internalize_card_of_ordLess2:
   111 "( |A| <o |C| ) = (\<exists>B < C. |A| =o |B| \<and> |B| <o |C| )"
   112 using internalize_card_of_ordLess[of "A" "|C|"] Field_card_of[of C] by auto
   113 
   114 lemma Card_order_omax:
   115 assumes "finite R" and "R \<noteq> {}" and "\<forall>r\<in>R. Card_order r"
   116 shows "Card_order (omax R)"
   117 proof-
   118   have "\<forall>r\<in>R. Well_order r"
   119   using assms unfolding card_order_on_def by simp
   120   thus ?thesis using assms apply - apply(drule omax_in) by auto
   121 qed
   122 
   123 lemma Card_order_omax2:
   124 assumes "finite I" and "I \<noteq> {}"
   125 shows "Card_order (omax {|A i| | i. i \<in> I})"
   126 proof-
   127   let ?R = "{|A i| | i. i \<in> I}"
   128   have "finite ?R" and "?R \<noteq> {}" using assms by auto
   129   moreover have "\<forall>r\<in>?R. Card_order r"
   130   using card_of_Card_order by auto
   131   ultimately show ?thesis by(rule Card_order_omax)
   132 qed
   133 
   134 
   135 subsection {* Cardinals versus set operations on arbitrary sets *}
   136 
   137 lemma card_of_set_type[simp]: "|UNIV::'a set| <o |UNIV::'a set set|"
   138 using card_of_Pow[of "UNIV::'a set"] by simp
   139 
   140 lemma card_of_Un1[simp]:
   141 shows "|A| \<le>o |A \<union> B| "
   142 using inj_on_id[of A] card_of_ordLeq[of A _] by fastforce
   143 
   144 lemma card_of_diff[simp]:
   145 shows "|A - B| \<le>o |A|"
   146 using inj_on_id[of "A - B"] card_of_ordLeq[of "A - B" _] by fastforce
   147 
   148 lemma subset_ordLeq_strict:
   149 assumes "A \<le> B" and "|A| <o |B|"
   150 shows "A < B"
   151 proof-
   152   {assume "\<not>(A < B)"
   153    hence "A = B" using assms(1) by blast
   154    hence False using assms(2) not_ordLess_ordIso card_of_refl by blast
   155   }
   156   thus ?thesis by blast
   157 qed
   158 
   159 corollary subset_ordLeq_diff:
   160 assumes "A \<le> B" and "|A| <o |B|"
   161 shows "B - A \<noteq> {}"
   162 using assms subset_ordLeq_strict by blast
   163 
   164 lemma card_of_empty4:
   165 "|{}::'b set| <o |A::'a set| = (A \<noteq> {})"
   166 proof(intro iffI notI)
   167   assume *: "|{}::'b set| <o |A|" and "A = {}"
   168   hence "|A| =o |{}::'b set|"
   169   using card_of_ordIso unfolding bij_betw_def inj_on_def by blast
   170   hence "|{}::'b set| =o |A|" using ordIso_symmetric by blast
   171   with * show False using not_ordLess_ordIso[of "|{}::'b set|" "|A|"] by blast
   172 next
   173   assume "A \<noteq> {}"
   174   hence "(\<not> (\<exists>f. inj_on f A \<and> f ` A \<subseteq> {}))"
   175   unfolding inj_on_def by blast
   176   thus "| {} | <o | A |"
   177   using card_of_ordLess by blast
   178 qed
   179 
   180 lemma card_of_empty5:
   181 "|A| <o |B| \<Longrightarrow> B \<noteq> {}"
   182 using card_of_empty not_ordLess_ordLeq by blast
   183 
   184 lemma Well_order_card_of_empty:
   185 "Well_order r \<Longrightarrow> |{}| \<le>o r" by simp
   186 
   187 lemma card_of_UNIV[simp]:
   188 "|A :: 'a set| \<le>o |UNIV :: 'a set|"
   189 using card_of_mono1[of A] by simp
   190 
   191 lemma card_of_UNIV2[simp]:
   192 "Card_order r \<Longrightarrow> (r :: 'a rel) \<le>o |UNIV :: 'a set|"
   193 using card_of_UNIV[of "Field r"] card_of_Field_ordIso
   194       ordIso_symmetric ordIso_ordLeq_trans by blast
   195 
   196 lemma card_of_Pow_mono[simp]:
   197 assumes "|A| \<le>o |B|"
   198 shows "|Pow A| \<le>o |Pow B|"
   199 proof-
   200   obtain f where "inj_on f A \<and> f ` A \<le> B"
   201   using assms card_of_ordLeq[of A B] by auto
   202   hence "inj_on (image f) (Pow A) \<and> (image f) ` (Pow A) \<le> (Pow B)"
   203   by (auto simp add: inj_on_image_Pow image_Pow_mono)
   204   thus ?thesis using card_of_ordLeq[of "Pow A"] by metis
   205 qed
   206 
   207 lemma ordIso_Pow_mono[simp]:
   208 assumes "r \<le>o r'"
   209 shows "|Pow(Field r)| \<le>o |Pow(Field r')|"
   210 using assms card_of_mono2 card_of_Pow_mono by blast
   211 
   212 lemma card_of_Pow_cong[simp]:
   213 assumes "|A| =o |B|"
   214 shows "|Pow A| =o |Pow B|"
   215 proof-
   216   obtain f where "bij_betw f A B"
   217   using assms card_of_ordIso[of A B] by auto
   218   hence "bij_betw (image f) (Pow A) (Pow B)"
   219   by (auto simp add: bij_betw_image_Pow)
   220   thus ?thesis using card_of_ordIso[of "Pow A"] by auto
   221 qed
   222 
   223 lemma ordIso_Pow_cong[simp]:
   224 assumes "r =o r'"
   225 shows "|Pow(Field r)| =o |Pow(Field r')|"
   226 using assms card_of_cong card_of_Pow_cong by blast
   227 
   228 corollary Card_order_Plus_empty1:
   229 "Card_order r \<Longrightarrow> r =o |(Field r) <+> {}|"
   230 using card_of_Plus_empty1 card_of_Field_ordIso ordIso_equivalence by blast
   231 
   232 corollary Card_order_Plus_empty2:
   233 "Card_order r \<Longrightarrow> r =o |{} <+> (Field r)|"
   234 using card_of_Plus_empty2 card_of_Field_ordIso ordIso_equivalence by blast
   235 
   236 lemma Card_order_Un1:
   237 shows "Card_order r \<Longrightarrow> |Field r| \<le>o |(Field r) \<union> B| "
   238 using card_of_Un1 card_of_Field_ordIso ordIso_symmetric ordIso_ordLeq_trans by auto
   239 
   240 lemma card_of_Un2[simp]:
   241 shows "|A| \<le>o |B \<union> A|"
   242 using inj_on_id[of A] card_of_ordLeq[of A _] by fastforce
   243 
   244 lemma Card_order_Un2:
   245 shows "Card_order r \<Longrightarrow> |Field r| \<le>o |A \<union> (Field r)| "
   246 using card_of_Un2 card_of_Field_ordIso ordIso_symmetric ordIso_ordLeq_trans by auto
   247 
   248 lemma Un_Plus_bij_betw:
   249 assumes "A Int B = {}"
   250 shows "\<exists>f. bij_betw f (A \<union> B) (A <+> B)"
   251 proof-
   252   let ?f = "\<lambda> c. if c \<in> A then Inl c else Inr c"
   253   have "bij_betw ?f (A \<union> B) (A <+> B)"
   254   using assms by(unfold bij_betw_def inj_on_def, auto)
   255   thus ?thesis by blast
   256 qed
   257 
   258 lemma card_of_Un_Plus_ordIso:
   259 assumes "A Int B = {}"
   260 shows "|A \<union> B| =o |A <+> B|"
   261 using assms card_of_ordIso[of "A \<union> B"] Un_Plus_bij_betw[of A B] by auto
   262 
   263 lemma card_of_Un_Plus_ordIso1:
   264 "|A \<union> B| =o |A <+> (B - A)|"
   265 using card_of_Un_Plus_ordIso[of A "B - A"] by auto
   266 
   267 lemma card_of_Un_Plus_ordIso2:
   268 "|A \<union> B| =o |(A - B) <+> B|"
   269 using card_of_Un_Plus_ordIso[of "A - B" B] by auto
   270 
   271 lemma card_of_Times_singl1: "|A| =o |A \<times> {b}|"
   272 proof-
   273   have "bij_betw fst (A \<times> {b}) A" unfolding bij_betw_def inj_on_def by force
   274   thus ?thesis using card_of_ordIso ordIso_symmetric by blast
   275 qed
   276 
   277 corollary Card_order_Times_singl1:
   278 "Card_order r \<Longrightarrow> r =o |(Field r) \<times> {b}|"
   279 using card_of_Times_singl1[of _ b] card_of_Field_ordIso ordIso_equivalence by blast
   280 
   281 lemma card_of_Times_singl2: "|A| =o |{b} \<times> A|"
   282 proof-
   283   have "bij_betw snd ({b} \<times> A) A" unfolding bij_betw_def inj_on_def by force
   284   thus ?thesis using card_of_ordIso ordIso_symmetric by blast
   285 qed
   286 
   287 corollary Card_order_Times_singl2:
   288 "Card_order r \<Longrightarrow> r =o |{a} \<times> (Field r)|"
   289 using card_of_Times_singl2[of _ a] card_of_Field_ordIso ordIso_equivalence by blast
   290 
   291 lemma card_of_Times_assoc: "|(A \<times> B) \<times> C| =o |A \<times> B \<times> C|"
   292 proof -
   293   let ?f = "\<lambda>((a,b),c). (a,(b,c))"
   294   have "A \<times> B \<times> C \<subseteq> ?f ` ((A \<times> B) \<times> C)"
   295   proof
   296     fix x assume "x \<in> A \<times> B \<times> C"
   297     then obtain a b c where *: "a \<in> A" "b \<in> B" "c \<in> C" "x = (a, b, c)" by blast
   298     let ?x = "((a, b), c)"
   299     from * have "?x \<in> (A \<times> B) \<times> C" "x = ?f ?x" by auto
   300     thus "x \<in> ?f ` ((A \<times> B) \<times> C)" by blast
   301   qed
   302   hence "bij_betw ?f ((A \<times> B) \<times> C) (A \<times> B \<times> C)"
   303   unfolding bij_betw_def inj_on_def by auto
   304   thus ?thesis using card_of_ordIso by blast
   305 qed
   306 
   307 corollary Card_order_Times3:
   308 "Card_order r \<Longrightarrow> |Field r| \<le>o |(Field r) \<times> (Field r)|"
   309   by (rule card_of_Times3)
   310 
   311 lemma card_of_Times_cong1[simp]:
   312 assumes "|A| =o |B|"
   313 shows "|A \<times> C| =o |B \<times> C|"
   314 using assms by (simp add: ordIso_iff_ordLeq)
   315 
   316 lemma card_of_Times_cong2[simp]:
   317 assumes "|A| =o |B|"
   318 shows "|C \<times> A| =o |C \<times> B|"
   319 using assms by (simp add: ordIso_iff_ordLeq)
   320 
   321 lemma card_of_Times_mono[simp]:
   322 assumes "|A| \<le>o |B|" and "|C| \<le>o |D|"
   323 shows "|A \<times> C| \<le>o |B \<times> D|"
   324 using assms card_of_Times_mono1[of A B C] card_of_Times_mono2[of C D B]
   325       ordLeq_transitive[of "|A \<times> C|"] by blast
   326 
   327 corollary ordLeq_Times_mono:
   328 assumes "r \<le>o r'" and "p \<le>o p'"
   329 shows "|(Field r) \<times> (Field p)| \<le>o |(Field r') \<times> (Field p')|"
   330 using assms card_of_mono2[of r r'] card_of_mono2[of p p'] card_of_Times_mono by blast
   331 
   332 corollary ordIso_Times_cong1[simp]:
   333 assumes "r =o r'"
   334 shows "|(Field r) \<times> C| =o |(Field r') \<times> C|"
   335 using assms card_of_cong card_of_Times_cong1 by blast
   336 
   337 corollary ordIso_Times_cong2:
   338 assumes "r =o r'"
   339 shows "|A \<times> (Field r)| =o |A \<times> (Field r')|"
   340 using assms card_of_cong card_of_Times_cong2 by blast
   341 
   342 lemma card_of_Times_cong[simp]:
   343 assumes "|A| =o |B|" and "|C| =o |D|"
   344 shows "|A \<times> C| =o |B \<times> D|"
   345 using assms
   346 by (auto simp add: ordIso_iff_ordLeq)
   347 
   348 corollary ordIso_Times_cong:
   349 assumes "r =o r'" and "p =o p'"
   350 shows "|(Field r) \<times> (Field p)| =o |(Field r') \<times> (Field p')|"
   351 using assms card_of_cong[of r r'] card_of_cong[of p p'] card_of_Times_cong by blast
   352 
   353 lemma card_of_Sigma_mono2:
   354 assumes "inj_on f (I::'i set)" and "f ` I \<le> (J::'j set)"
   355 shows "|SIGMA i : I. (A::'j \<Rightarrow> 'a set) (f i)| \<le>o |SIGMA j : J. A j|"
   356 proof-
   357   let ?LEFT = "SIGMA i : I. A (f i)"
   358   let ?RIGHT = "SIGMA j : J. A j"
   359   obtain u where u_def: "u = (\<lambda>(i::'i,a::'a). (f i,a))" by blast
   360   have "inj_on u ?LEFT \<and> u `?LEFT \<le> ?RIGHT"
   361   using assms unfolding u_def inj_on_def by auto
   362   thus ?thesis using card_of_ordLeq by blast
   363 qed
   364 
   365 lemma card_of_Sigma_mono:
   366 assumes INJ: "inj_on f I" and IM: "f ` I \<le> J" and
   367         LEQ: "\<forall>j \<in> J. |A j| \<le>o |B j|"
   368 shows "|SIGMA i : I. A (f i)| \<le>o |SIGMA j : J. B j|"
   369 proof-
   370   have "\<forall>i \<in> I. |A(f i)| \<le>o |B(f i)|"
   371   using IM LEQ by blast
   372   hence "|SIGMA i : I. A (f i)| \<le>o |SIGMA i : I. B (f i)|"
   373   using card_of_Sigma_mono1[of I] by metis
   374   moreover have "|SIGMA i : I. B (f i)| \<le>o |SIGMA j : J. B j|"
   375   using INJ IM card_of_Sigma_mono2 by blast
   376   ultimately show ?thesis using ordLeq_transitive by blast
   377 qed
   378 
   379 
   380 lemma ordLeq_Sigma_mono1:
   381 assumes "\<forall>i \<in> I. p i \<le>o r i"
   382 shows "|SIGMA i : I. Field(p i)| \<le>o |SIGMA i : I. Field(r i)|"
   383 using assms by (auto simp add: card_of_Sigma_mono1)
   384 
   385 
   386 lemma ordLeq_Sigma_mono:
   387 assumes "inj_on f I" and "f ` I \<le> J" and
   388         "\<forall>j \<in> J. p j \<le>o r j"
   389 shows "|SIGMA i : I. Field(p(f i))| \<le>o |SIGMA j : J. Field(r j)|"
   390 using assms card_of_mono2 card_of_Sigma_mono
   391       [of f I J "\<lambda> i. Field(p i)" "\<lambda> j. Field(r j)"] by metis
   392 
   393 
   394 lemma card_of_Sigma_cong1:
   395 assumes "\<forall>i \<in> I. |A i| =o |B i|"
   396 shows "|SIGMA i : I. A i| =o |SIGMA i : I. B i|"
   397 using assms by (auto simp add: card_of_Sigma_mono1 ordIso_iff_ordLeq)
   398 
   399 
   400 lemma card_of_Sigma_cong2:
   401 assumes "bij_betw f (I::'i set) (J::'j set)"
   402 shows "|SIGMA i : I. (A::'j \<Rightarrow> 'a set) (f i)| =o |SIGMA j : J. A j|"
   403 proof-
   404   let ?LEFT = "SIGMA i : I. A (f i)"
   405   let ?RIGHT = "SIGMA j : J. A j"
   406   obtain u where u_def: "u = (\<lambda>(i::'i,a::'a). (f i,a))" by blast
   407   have "bij_betw u ?LEFT ?RIGHT"
   408   using assms unfolding u_def bij_betw_def inj_on_def by auto
   409   thus ?thesis using card_of_ordIso by blast
   410 qed
   411 
   412 lemma card_of_Sigma_cong:
   413 assumes BIJ: "bij_betw f I J" and
   414         ISO: "\<forall>j \<in> J. |A j| =o |B j|"
   415 shows "|SIGMA i : I. A (f i)| =o |SIGMA j : J. B j|"
   416 proof-
   417   have "\<forall>i \<in> I. |A(f i)| =o |B(f i)|"
   418   using ISO BIJ unfolding bij_betw_def by blast
   419   hence "|SIGMA i : I. A (f i)| =o |SIGMA i : I. B (f i)|" by (rule card_of_Sigma_cong1)
   420   moreover have "|SIGMA i : I. B (f i)| =o |SIGMA j : J. B j|"
   421   using BIJ card_of_Sigma_cong2 by blast
   422   ultimately show ?thesis using ordIso_transitive by blast
   423 qed
   424 
   425 lemma ordIso_Sigma_cong1:
   426 assumes "\<forall>i \<in> I. p i =o r i"
   427 shows "|SIGMA i : I. Field(p i)| =o |SIGMA i : I. Field(r i)|"
   428 using assms by (auto simp add: card_of_Sigma_cong1)
   429 
   430 lemma ordLeq_Sigma_cong:
   431 assumes "bij_betw f I J" and
   432         "\<forall>j \<in> J. p j =o r j"
   433 shows "|SIGMA i : I. Field(p(f i))| =o |SIGMA j : J. Field(r j)|"
   434 using assms card_of_cong card_of_Sigma_cong
   435       [of f I J "\<lambda> j. Field(p j)" "\<lambda> j. Field(r j)"] by blast
   436 
   437 corollary ordLeq_Sigma_Times:
   438 "\<forall>i \<in> I. p i \<le>o r \<Longrightarrow> |SIGMA i : I. Field (p i)| \<le>o |I \<times> (Field r)|"
   439 by (auto simp add: card_of_Sigma_Times)
   440 
   441 lemma card_of_UNION_Sigma2:
   442 assumes
   443 "!! i j. \<lbrakk>{i,j} <= I; i ~= j\<rbrakk> \<Longrightarrow> A i Int A j = {}"
   444 shows
   445 "|\<Union>i\<in>I. A i| =o |Sigma I A|"
   446 proof-
   447   let ?L = "\<Union>i\<in>I. A i"  let ?R = "Sigma I A"
   448   have "|?L| <=o |?R|" using card_of_UNION_Sigma .
   449   moreover have "|?R| <=o |?L|"
   450   proof-
   451     have "inj_on snd ?R"
   452     unfolding inj_on_def using assms by auto
   453     moreover have "snd ` ?R <= ?L" by auto
   454     ultimately show ?thesis using card_of_ordLeq by blast
   455   qed
   456   ultimately show ?thesis by(simp add: ordIso_iff_ordLeq)
   457 qed
   458 
   459 corollary Plus_into_Times:
   460 assumes A2: "a1 \<noteq> a2 \<and> {a1,a2} \<le> A" and
   461         B2: "b1 \<noteq> b2 \<and> {b1,b2} \<le> B"
   462 shows "\<exists>f. inj_on f (A <+> B) \<and> f ` (A <+> B) \<le> A \<times> B"
   463 using assms by (auto simp add: card_of_Plus_Times card_of_ordLeq)
   464 
   465 corollary Plus_into_Times_types:
   466 assumes A2: "(a1::'a) \<noteq> a2" and  B2: "(b1::'b) \<noteq> b2"
   467 shows "\<exists>(f::'a + 'b \<Rightarrow> 'a * 'b). inj f"
   468 using assms Plus_into_Times[of a1 a2 UNIV b1 b2 UNIV]
   469 by auto
   470 
   471 corollary Times_same_infinite_bij_betw:
   472 assumes "\<not>finite A"
   473 shows "\<exists>f. bij_betw f (A \<times> A) A"
   474 using assms by (auto simp add: card_of_ordIso)
   475 
   476 corollary Times_same_infinite_bij_betw_types:
   477 assumes INF: "\<not>finite(UNIV::'a set)"
   478 shows "\<exists>(f::('a * 'a) => 'a). bij f"
   479 using assms Times_same_infinite_bij_betw[of "UNIV::'a set"]
   480 by auto
   481 
   482 corollary Times_infinite_bij_betw:
   483 assumes INF: "\<not>finite A" and NE: "B \<noteq> {}" and INJ: "inj_on g B \<and> g ` B \<le> A"
   484 shows "(\<exists>f. bij_betw f (A \<times> B) A) \<and> (\<exists>h. bij_betw h (B \<times> A) A)"
   485 proof-
   486   have "|B| \<le>o |A|" using INJ card_of_ordLeq by blast
   487   thus ?thesis using INF NE
   488   by (auto simp add: card_of_ordIso card_of_Times_infinite)
   489 qed
   490 
   491 corollary Times_infinite_bij_betw_types:
   492 assumes INF: "\<not>finite(UNIV::'a set)" and
   493         BIJ: "inj(g::'b \<Rightarrow> 'a)"
   494 shows "(\<exists>(f::('b * 'a) => 'a). bij f) \<and> (\<exists>(h::('a * 'b) => 'a). bij h)"
   495 using assms Times_infinite_bij_betw[of "UNIV::'a set" "UNIV::'b set" g]
   496 by auto
   497 
   498 lemma card_of_Times_ordLeq_infinite:
   499 "\<lbrakk>\<not>finite C; |A| \<le>o |C|; |B| \<le>o |C|\<rbrakk>
   500  \<Longrightarrow> |A <*> B| \<le>o |C|"
   501 by(simp add: card_of_Sigma_ordLeq_infinite)
   502 
   503 corollary Plus_infinite_bij_betw:
   504 assumes INF: "\<not>finite A" and INJ: "inj_on g B \<and> g ` B \<le> A"
   505 shows "(\<exists>f. bij_betw f (A <+> B) A) \<and> (\<exists>h. bij_betw h (B <+> A) A)"
   506 proof-
   507   have "|B| \<le>o |A|" using INJ card_of_ordLeq by blast
   508   thus ?thesis using INF
   509   by (auto simp add: card_of_ordIso)
   510 qed
   511 
   512 corollary Plus_infinite_bij_betw_types:
   513 assumes INF: "\<not>finite(UNIV::'a set)" and
   514         BIJ: "inj(g::'b \<Rightarrow> 'a)"
   515 shows "(\<exists>(f::('b + 'a) => 'a). bij f) \<and> (\<exists>(h::('a + 'b) => 'a). bij h)"
   516 using assms Plus_infinite_bij_betw[of "UNIV::'a set" g "UNIV::'b set"]
   517 by auto
   518 
   519 lemma card_of_Un_infinite:
   520 assumes INF: "\<not>finite A" and LEQ: "|B| \<le>o |A|"
   521 shows "|A \<union> B| =o |A| \<and> |B \<union> A| =o |A|"
   522 proof-
   523   have "|A \<union> B| \<le>o |A <+> B|" by (rule card_of_Un_Plus_ordLeq)
   524   moreover have "|A <+> B| =o |A|"
   525   using assms by (metis card_of_Plus_infinite)
   526   ultimately have "|A \<union> B| \<le>o |A|" using ordLeq_ordIso_trans by blast
   527   hence "|A \<union> B| =o |A|" using card_of_Un1 ordIso_iff_ordLeq by blast
   528   thus ?thesis using Un_commute[of B A] by auto
   529 qed
   530 
   531 lemma card_of_Un_infinite_simps[simp]:
   532 "\<lbrakk>\<not>finite A; |B| \<le>o |A| \<rbrakk> \<Longrightarrow> |A \<union> B| =o |A|"
   533 "\<lbrakk>\<not>finite A; |B| \<le>o |A| \<rbrakk> \<Longrightarrow> |B \<union> A| =o |A|"
   534 using card_of_Un_infinite by auto
   535 
   536 lemma card_of_Un_diff_infinite:
   537 assumes INF: "\<not>finite A" and LESS: "|B| <o |A|"
   538 shows "|A - B| =o |A|"
   539 proof-
   540   obtain C where C_def: "C = A - B" by blast
   541   have "|A \<union> B| =o |A|"
   542   using assms ordLeq_iff_ordLess_or_ordIso card_of_Un_infinite by blast
   543   moreover have "C \<union> B = A \<union> B" unfolding C_def by auto
   544   ultimately have 1: "|C \<union> B| =o |A|" by auto
   545   (*  *)
   546   {assume *: "|C| \<le>o |B|"
   547    moreover
   548    {assume **: "finite B"
   549     hence "finite C"
   550     using card_of_ordLeq_finite * by blast
   551     hence False using ** INF card_of_ordIso_finite 1 by blast
   552    }
   553    hence "\<not>finite B" by auto
   554    ultimately have False
   555    using card_of_Un_infinite 1 ordIso_equivalence(1,3) LESS not_ordLess_ordIso by metis
   556   }
   557   hence 2: "|B| \<le>o |C|" using card_of_Well_order ordLeq_total by blast
   558   {assume *: "finite C"
   559     hence "finite B" using card_of_ordLeq_finite 2 by blast
   560     hence False using * INF card_of_ordIso_finite 1 by blast
   561   }
   562   hence "\<not>finite C" by auto
   563   hence "|C| =o |A|"
   564   using  card_of_Un_infinite 1 2 ordIso_equivalence(1,3) by metis
   565   thus ?thesis unfolding C_def .
   566 qed
   567 
   568 corollary Card_order_Un_infinite:
   569 assumes INF: "\<not>finite(Field r)" and CARD: "Card_order r" and
   570         LEQ: "p \<le>o r"
   571 shows "| (Field r) \<union> (Field p) | =o r \<and> | (Field p) \<union> (Field r) | =o r"
   572 proof-
   573   have "| Field r \<union> Field p | =o | Field r | \<and>
   574         | Field p \<union> Field r | =o | Field r |"
   575   using assms by (auto simp add: card_of_Un_infinite)
   576   thus ?thesis
   577   using assms card_of_Field_ordIso[of r]
   578         ordIso_transitive[of "|Field r \<union> Field p|"]
   579         ordIso_transitive[of _ "|Field r|"] by blast
   580 qed
   581 
   582 corollary subset_ordLeq_diff_infinite:
   583 assumes INF: "\<not>finite B" and SUB: "A \<le> B" and LESS: "|A| <o |B|"
   584 shows "\<not>finite (B - A)"
   585 using assms card_of_Un_diff_infinite card_of_ordIso_finite by blast
   586 
   587 lemma card_of_Times_ordLess_infinite[simp]:
   588 assumes INF: "\<not>finite C" and
   589         LESS1: "|A| <o |C|" and LESS2: "|B| <o |C|"
   590 shows "|A \<times> B| <o |C|"
   591 proof(cases "A = {} \<or> B = {}")
   592   assume Case1: "A = {} \<or> B = {}"
   593   hence "A \<times> B = {}" by blast
   594   moreover have "C \<noteq> {}" using
   595   LESS1 card_of_empty5 by blast
   596   ultimately show ?thesis by(auto simp add:  card_of_empty4)
   597 next
   598   assume Case2: "\<not>(A = {} \<or> B = {})"
   599   {assume *: "|C| \<le>o |A \<times> B|"
   600    hence "\<not>finite (A \<times> B)" using INF card_of_ordLeq_finite by blast
   601    hence 1: "\<not>finite A \<or> \<not>finite B" using finite_cartesian_product by blast
   602    {assume Case21: "|A| \<le>o |B|"
   603     hence "\<not>finite B" using 1 card_of_ordLeq_finite by blast
   604     hence "|A \<times> B| =o |B|" using Case2 Case21
   605     by (auto simp add: card_of_Times_infinite)
   606     hence False using LESS2 not_ordLess_ordLeq * ordLeq_ordIso_trans by blast
   607    }
   608    moreover
   609    {assume Case22: "|B| \<le>o |A|"
   610     hence "\<not>finite A" using 1 card_of_ordLeq_finite by blast
   611     hence "|A \<times> B| =o |A|" using Case2 Case22
   612     by (auto simp add: card_of_Times_infinite)
   613     hence False using LESS1 not_ordLess_ordLeq * ordLeq_ordIso_trans by blast
   614    }
   615    ultimately have False using ordLeq_total card_of_Well_order[of A]
   616    card_of_Well_order[of B] by blast
   617   }
   618   thus ?thesis using ordLess_or_ordLeq[of "|A \<times> B|" "|C|"]
   619   card_of_Well_order[of "A \<times> B"] card_of_Well_order[of "C"] by auto
   620 qed
   621 
   622 lemma card_of_Times_ordLess_infinite_Field[simp]:
   623 assumes INF: "\<not>finite (Field r)" and r: "Card_order r" and
   624         LESS1: "|A| <o r" and LESS2: "|B| <o r"
   625 shows "|A \<times> B| <o r"
   626 proof-
   627   let ?C  = "Field r"
   628   have 1: "r =o |?C| \<and> |?C| =o r" using r card_of_Field_ordIso
   629   ordIso_symmetric by blast
   630   hence "|A| <o |?C|"  "|B| <o |?C|"
   631   using LESS1 LESS2 ordLess_ordIso_trans by blast+
   632   hence  "|A <*> B| <o |?C|" using INF
   633   card_of_Times_ordLess_infinite by blast
   634   thus ?thesis using 1 ordLess_ordIso_trans by blast
   635 qed
   636 
   637 lemma card_of_Un_ordLess_infinite[simp]:
   638 assumes INF: "\<not>finite C" and
   639         LESS1: "|A| <o |C|" and LESS2: "|B| <o |C|"
   640 shows "|A \<union> B| <o |C|"
   641 using assms card_of_Plus_ordLess_infinite card_of_Un_Plus_ordLeq
   642       ordLeq_ordLess_trans by blast
   643 
   644 lemma card_of_Un_ordLess_infinite_Field[simp]:
   645 assumes INF: "\<not>finite (Field r)" and r: "Card_order r" and
   646         LESS1: "|A| <o r" and LESS2: "|B| <o r"
   647 shows "|A Un B| <o r"
   648 proof-
   649   let ?C  = "Field r"
   650   have 1: "r =o |?C| \<and> |?C| =o r" using r card_of_Field_ordIso
   651   ordIso_symmetric by blast
   652   hence "|A| <o |?C|"  "|B| <o |?C|"
   653   using LESS1 LESS2 ordLess_ordIso_trans by blast+
   654   hence  "|A Un B| <o |?C|" using INF
   655   card_of_Un_ordLess_infinite by blast
   656   thus ?thesis using 1 ordLess_ordIso_trans by blast
   657 qed
   658 
   659 
   660 subsection {* Cardinals versus set operations involving infinite sets *}
   661 
   662 lemma finite_iff_cardOf_nat:
   663 "finite A = ( |A| <o |UNIV :: nat set| )"
   664 using infinite_iff_card_of_nat[of A]
   665 not_ordLeq_iff_ordLess[of "|A|" "|UNIV :: nat set|"]
   666 by fastforce
   667 
   668 lemma finite_ordLess_infinite2[simp]:
   669 assumes "finite A" and "\<not>finite B"
   670 shows "|A| <o |B|"
   671 using assms
   672 finite_ordLess_infinite[of "|A|" "|B|"]
   673 card_of_Well_order[of A] card_of_Well_order[of B]
   674 Field_card_of[of A] Field_card_of[of B] by auto
   675 
   676 lemma infinite_card_of_insert:
   677 assumes "\<not>finite A"
   678 shows "|insert a A| =o |A|"
   679 proof-
   680   have iA: "insert a A = A \<union> {a}" by simp
   681   show ?thesis
   682   using infinite_imp_bij_betw2[OF assms] unfolding iA
   683   by (metis bij_betw_inv card_of_ordIso)
   684 qed
   685 
   686 lemma card_of_Un_singl_ordLess_infinite1:
   687 assumes "\<not>finite B" and "|A| <o |B|"
   688 shows "|{a} Un A| <o |B|"
   689 proof-
   690   have "|{a}| <o |B|" using assms by auto
   691   thus ?thesis using assms card_of_Un_ordLess_infinite[of B] by blast
   692 qed
   693 
   694 lemma card_of_Un_singl_ordLess_infinite:
   695 assumes "\<not>finite B"
   696 shows "( |A| <o |B| ) = ( |{a} Un A| <o |B| )"
   697 using assms card_of_Un_singl_ordLess_infinite1[of B A]
   698 proof(auto)
   699   assume "|insert a A| <o |B|"
   700   moreover have "|A| <=o |insert a A|" using card_of_mono1[of A "insert a A"] by blast
   701   ultimately show "|A| <o |B|" using ordLeq_ordLess_trans by blast
   702 qed
   703 
   704 
   705 subsection {* Cardinals versus lists *}
   706 
   707 text{* The next is an auxiliary operator, which shall be used for inductive
   708 proofs of facts concerning the cardinality of @{text "List"} : *}
   709 
   710 definition nlists :: "'a set \<Rightarrow> nat \<Rightarrow> 'a list set"
   711 where "nlists A n \<equiv> {l. set l \<le> A \<and> length l = n}"
   712 
   713 lemma lists_def2: "lists A = {l. set l \<le> A}"
   714 using in_listsI by blast
   715 
   716 lemma lists_UNION_nlists: "lists A = (\<Union> n. nlists A n)"
   717 unfolding lists_def2 nlists_def by blast
   718 
   719 lemma card_of_lists: "|A| \<le>o |lists A|"
   720 proof-
   721   let ?h = "\<lambda> a. [a]"
   722   have "inj_on ?h A \<and> ?h ` A \<le> lists A"
   723   unfolding inj_on_def lists_def2 by auto
   724   thus ?thesis by (metis card_of_ordLeq)
   725 qed
   726 
   727 lemma nlists_0: "nlists A 0 = {[]}"
   728 unfolding nlists_def by auto
   729 
   730 lemma nlists_not_empty:
   731 assumes "A \<noteq> {}"
   732 shows "nlists A n \<noteq> {}"
   733 proof(induct n, simp add: nlists_0)
   734   fix n assume "nlists A n \<noteq> {}"
   735   then obtain a and l where "a \<in> A \<and> l \<in> nlists A n" using assms by auto
   736   hence "a # l \<in> nlists A (Suc n)" unfolding nlists_def by auto
   737   thus "nlists A (Suc n) \<noteq> {}" by auto
   738 qed
   739 
   740 lemma Nil_in_lists: "[] \<in> lists A"
   741 unfolding lists_def2 by auto
   742 
   743 lemma lists_not_empty: "lists A \<noteq> {}"
   744 using Nil_in_lists by blast
   745 
   746 lemma card_of_nlists_Succ: "|nlists A (Suc n)| =o |A \<times> (nlists A n)|"
   747 proof-
   748   let ?B = "A \<times> (nlists A n)"   let ?h = "\<lambda>(a,l). a # l"
   749   have "inj_on ?h ?B \<and> ?h ` ?B \<le> nlists A (Suc n)"
   750   unfolding inj_on_def nlists_def by auto
   751   moreover have "nlists A (Suc n) \<le> ?h ` ?B"
   752   proof(auto)
   753     fix l assume "l \<in> nlists A (Suc n)"
   754     hence 1: "length l = Suc n \<and> set l \<le> A" unfolding nlists_def by auto
   755     then obtain a and l' where 2: "l = a # l'" by (auto simp: length_Suc_conv)
   756     hence "a \<in> A \<and> set l' \<le> A \<and> length l' = n" using 1 by auto
   757     thus "l \<in> ?h ` ?B"  using 2 unfolding nlists_def by auto
   758   qed
   759   ultimately have "bij_betw ?h ?B (nlists A (Suc n))"
   760   unfolding bij_betw_def by auto
   761   thus ?thesis using card_of_ordIso ordIso_symmetric by blast
   762 qed
   763 
   764 lemma card_of_nlists_infinite:
   765 assumes "\<not>finite A"
   766 shows "|nlists A n| \<le>o |A|"
   767 proof(induct n)
   768   have "A \<noteq> {}" using assms by auto
   769   thus "|nlists A 0| \<le>o |A|" by (simp add: nlists_0)
   770 next
   771   fix n assume IH: "|nlists A n| \<le>o |A|"
   772   have "|nlists A (Suc n)| =o |A \<times> (nlists A n)|"
   773   using card_of_nlists_Succ by blast
   774   moreover
   775   {have "nlists A n \<noteq> {}" using assms nlists_not_empty[of A] by blast
   776    hence "|A \<times> (nlists A n)| =o |A|"
   777    using assms IH by (auto simp add: card_of_Times_infinite)
   778   }
   779   ultimately show "|nlists A (Suc n)| \<le>o |A|"
   780   using ordIso_transitive ordIso_iff_ordLeq by blast
   781 qed
   782 
   783 lemma Card_order_lists: "Card_order r \<Longrightarrow> r \<le>o |lists(Field r) |"
   784 using card_of_lists card_of_Field_ordIso ordIso_ordLeq_trans ordIso_symmetric by blast
   785 
   786 lemma Union_set_lists:
   787 "Union(set ` (lists A)) = A"
   788 unfolding lists_def2 proof(auto)
   789   fix a assume "a \<in> A"
   790   hence "set [a] \<le> A \<and> a \<in> set [a]" by auto
   791   thus "\<exists>l. set l \<le> A \<and> a \<in> set l" by blast
   792 qed
   793 
   794 lemma inj_on_map_lists:
   795 assumes "inj_on f A"
   796 shows "inj_on (map f) (lists A)"
   797 using assms Union_set_lists[of A] inj_on_mapI[of f "lists A"] by auto
   798 
   799 lemma map_lists_mono:
   800 assumes "f ` A \<le> B"
   801 shows "(map f) ` (lists A) \<le> lists B"
   802 using assms unfolding lists_def2 by (auto, blast) (* lethal combination of methods :)  *)
   803 
   804 lemma map_lists_surjective:
   805 assumes "f ` A = B"
   806 shows "(map f) ` (lists A) = lists B"
   807 using assms unfolding lists_def2
   808 proof (auto, blast)
   809   fix l' assume *: "set l' \<le> f ` A"
   810   have "set l' \<le> f ` A \<longrightarrow> l' \<in> map f ` {l. set l \<le> A}"
   811   proof(induct l', auto)
   812     fix l a
   813     assume "a \<in> A" and "set l \<le> A" and
   814            IH: "f ` (set l) \<le> f ` A"
   815     hence "set (a # l) \<le> A" by auto
   816     hence "map f (a # l) \<in> map f ` {l. set l \<le> A}" by blast
   817     thus "f a # map f l \<in> map f ` {l. set l \<le> A}" by auto
   818   qed
   819   thus "l' \<in> map f ` {l. set l \<le> A}" using * by auto
   820 qed
   821 
   822 lemma bij_betw_map_lists:
   823 assumes "bij_betw f A B"
   824 shows "bij_betw (map f) (lists A) (lists B)"
   825 using assms unfolding bij_betw_def
   826 by(auto simp add: inj_on_map_lists map_lists_surjective)
   827 
   828 lemma card_of_lists_mono[simp]:
   829 assumes "|A| \<le>o |B|"
   830 shows "|lists A| \<le>o |lists B|"
   831 proof-
   832   obtain f where "inj_on f A \<and> f ` A \<le> B"
   833   using assms card_of_ordLeq[of A B] by auto
   834   hence "inj_on (map f) (lists A) \<and> (map f) ` (lists A) \<le> (lists B)"
   835   by (auto simp add: inj_on_map_lists map_lists_mono)
   836   thus ?thesis using card_of_ordLeq[of "lists A"] by metis
   837 qed
   838 
   839 lemma ordIso_lists_mono:
   840 assumes "r \<le>o r'"
   841 shows "|lists(Field r)| \<le>o |lists(Field r')|"
   842 using assms card_of_mono2 card_of_lists_mono by blast
   843 
   844 lemma card_of_lists_cong[simp]:
   845 assumes "|A| =o |B|"
   846 shows "|lists A| =o |lists B|"
   847 proof-
   848   obtain f where "bij_betw f A B"
   849   using assms card_of_ordIso[of A B] by auto
   850   hence "bij_betw (map f) (lists A) (lists B)"
   851   by (auto simp add: bij_betw_map_lists)
   852   thus ?thesis using card_of_ordIso[of "lists A"] by auto
   853 qed
   854 
   855 lemma card_of_lists_infinite[simp]:
   856 assumes "\<not>finite A"
   857 shows "|lists A| =o |A|"
   858 proof-
   859   have "|lists A| \<le>o |A|" unfolding lists_UNION_nlists
   860   by (rule card_of_UNION_ordLeq_infinite[OF assms _ ballI[OF card_of_nlists_infinite[OF assms]]])
   861     (metis infinite_iff_card_of_nat assms)
   862   thus ?thesis using card_of_lists ordIso_iff_ordLeq by blast
   863 qed
   864 
   865 lemma Card_order_lists_infinite:
   866 assumes "Card_order r" and "\<not>finite(Field r)"
   867 shows "|lists(Field r)| =o r"
   868 using assms card_of_lists_infinite card_of_Field_ordIso ordIso_transitive by blast
   869 
   870 lemma ordIso_lists_cong:
   871 assumes "r =o r'"
   872 shows "|lists(Field r)| =o |lists(Field r')|"
   873 using assms card_of_cong card_of_lists_cong by blast
   874 
   875 corollary lists_infinite_bij_betw:
   876 assumes "\<not>finite A"
   877 shows "\<exists>f. bij_betw f (lists A) A"
   878 using assms card_of_lists_infinite card_of_ordIso by blast
   879 
   880 corollary lists_infinite_bij_betw_types:
   881 assumes "\<not>finite(UNIV :: 'a set)"
   882 shows "\<exists>(f::'a list \<Rightarrow> 'a). bij f"
   883 using assms assms lists_infinite_bij_betw[of "UNIV::'a set"]
   884 using lists_UNIV by auto
   885 
   886 
   887 subsection {* Cardinals versus the set-of-finite-sets operator  *}
   888 
   889 definition Fpow :: "'a set \<Rightarrow> 'a set set"
   890 where "Fpow A \<equiv> {X. X \<le> A \<and> finite X}"
   891 
   892 lemma Fpow_mono: "A \<le> B \<Longrightarrow> Fpow A \<le> Fpow B"
   893 unfolding Fpow_def by auto
   894 
   895 lemma empty_in_Fpow: "{} \<in> Fpow A"
   896 unfolding Fpow_def by auto
   897 
   898 lemma Fpow_not_empty: "Fpow A \<noteq> {}"
   899 using empty_in_Fpow by blast
   900 
   901 lemma Fpow_subset_Pow: "Fpow A \<le> Pow A"
   902 unfolding Fpow_def by auto
   903 
   904 lemma card_of_Fpow[simp]: "|A| \<le>o |Fpow A|"
   905 proof-
   906   let ?h = "\<lambda> a. {a}"
   907   have "inj_on ?h A \<and> ?h ` A \<le> Fpow A"
   908   unfolding inj_on_def Fpow_def by auto
   909   thus ?thesis using card_of_ordLeq by metis
   910 qed
   911 
   912 lemma Card_order_Fpow: "Card_order r \<Longrightarrow> r \<le>o |Fpow(Field r) |"
   913 using card_of_Fpow card_of_Field_ordIso ordIso_ordLeq_trans ordIso_symmetric by blast
   914 
   915 lemma Fpow_Pow_finite: "Fpow A = Pow A Int {A. finite A}"
   916 unfolding Fpow_def Pow_def by blast
   917 
   918 lemma inj_on_image_Fpow:
   919 assumes "inj_on f A"
   920 shows "inj_on (image f) (Fpow A)"
   921 using assms Fpow_subset_Pow[of A] subset_inj_on[of "image f" "Pow A"]
   922       inj_on_image_Pow by blast
   923 
   924 lemma image_Fpow_mono:
   925 assumes "f ` A \<le> B"
   926 shows "(image f) ` (Fpow A) \<le> Fpow B"
   927 using assms by(unfold Fpow_def, auto)
   928 
   929 lemma image_Fpow_surjective:
   930 assumes "f ` A = B"
   931 shows "(image f) ` (Fpow A) = Fpow B"
   932 using assms proof(unfold Fpow_def, auto)
   933   fix Y assume *: "Y \<le> f ` A" and **: "finite Y"
   934   hence "\<forall>b \<in> Y. \<exists>a. a \<in> A \<and> f a = b" by auto
   935   with bchoice[of Y "\<lambda>b a. a \<in> A \<and> f a = b"]
   936   obtain g where 1: "\<forall>b \<in> Y. g b \<in> A \<and> f(g b) = b" by blast
   937   obtain X where X_def: "X = g ` Y" by blast
   938   have "f ` X = Y \<and> X \<le> A \<and> finite X"
   939   by(unfold X_def, force simp add: ** 1)
   940   thus "Y \<in> (image f) ` {X. X \<le> A \<and> finite X}" by auto
   941 qed
   942 
   943 lemma bij_betw_image_Fpow:
   944 assumes "bij_betw f A B"
   945 shows "bij_betw (image f) (Fpow A) (Fpow B)"
   946 using assms unfolding bij_betw_def
   947 by (auto simp add: inj_on_image_Fpow image_Fpow_surjective)
   948 
   949 lemma card_of_Fpow_mono[simp]:
   950 assumes "|A| \<le>o |B|"
   951 shows "|Fpow A| \<le>o |Fpow B|"
   952 proof-
   953   obtain f where "inj_on f A \<and> f ` A \<le> B"
   954   using assms card_of_ordLeq[of A B] by auto
   955   hence "inj_on (image f) (Fpow A) \<and> (image f) ` (Fpow A) \<le> (Fpow B)"
   956   by (auto simp add: inj_on_image_Fpow image_Fpow_mono)
   957   thus ?thesis using card_of_ordLeq[of "Fpow A"] by auto
   958 qed
   959 
   960 lemma ordIso_Fpow_mono:
   961 assumes "r \<le>o r'"
   962 shows "|Fpow(Field r)| \<le>o |Fpow(Field r')|"
   963 using assms card_of_mono2 card_of_Fpow_mono by blast
   964 
   965 lemma card_of_Fpow_cong[simp]:
   966 assumes "|A| =o |B|"
   967 shows "|Fpow A| =o |Fpow B|"
   968 proof-
   969   obtain f where "bij_betw f A B"
   970   using assms card_of_ordIso[of A B] by auto
   971   hence "bij_betw (image f) (Fpow A) (Fpow B)"
   972   by (auto simp add: bij_betw_image_Fpow)
   973   thus ?thesis using card_of_ordIso[of "Fpow A"] by auto
   974 qed
   975 
   976 lemma ordIso_Fpow_cong:
   977 assumes "r =o r'"
   978 shows "|Fpow(Field r)| =o |Fpow(Field r')|"
   979 using assms card_of_cong card_of_Fpow_cong by blast
   980 
   981 lemma card_of_Fpow_lists: "|Fpow A| \<le>o |lists A|"
   982 proof-
   983   have "set ` (lists A) = Fpow A"
   984   unfolding lists_def2 Fpow_def using finite_list finite_set by blast
   985   thus ?thesis using card_of_ordLeq2[of "Fpow A"] Fpow_not_empty[of A] by blast
   986 qed
   987 
   988 lemma card_of_Fpow_infinite[simp]:
   989 assumes "\<not>finite A"
   990 shows "|Fpow A| =o |A|"
   991 using assms card_of_Fpow_lists card_of_lists_infinite card_of_Fpow
   992       ordLeq_ordIso_trans ordIso_iff_ordLeq by blast
   993 
   994 corollary Fpow_infinite_bij_betw:
   995 assumes "\<not>finite A"
   996 shows "\<exists>f. bij_betw f (Fpow A) A"
   997 using assms card_of_Fpow_infinite card_of_ordIso by blast
   998 
   999 
  1000 subsection {* The cardinal $\omega$ and the finite cardinals  *}
  1001 
  1002 subsubsection {* First as well-orders *}
  1003 
  1004 lemma Field_natLess: "Field natLess = (UNIV::nat set)"
  1005 by(unfold Field_def, auto)
  1006 
  1007 lemma natLeq_well_order_on: "well_order_on UNIV natLeq"
  1008 using natLeq_Well_order Field_natLeq by auto
  1009 
  1010 lemma natLeq_wo_rel: "wo_rel natLeq"
  1011 unfolding wo_rel_def using natLeq_Well_order .
  1012 
  1013 lemma natLeq_ofilter_less: "ofilter natLeq {0 ..< n}"
  1014 by(auto simp add: natLeq_wo_rel wo_rel.ofilter_def,
  1015    simp add: Field_natLeq, unfold under_def, auto)
  1016 
  1017 lemma natLeq_ofilter_leq: "ofilter natLeq {0 .. n}"
  1018 by(auto simp add: natLeq_wo_rel wo_rel.ofilter_def,
  1019    simp add: Field_natLeq, unfold under_def, auto)
  1020 
  1021 lemma natLeq_UNIV_ofilter: "wo_rel.ofilter natLeq UNIV"
  1022 using natLeq_wo_rel Field_natLeq wo_rel.Field_ofilter[of natLeq] by auto
  1023 
  1024 lemma closed_nat_set_iff:
  1025 assumes "\<forall>(m::nat) n. n \<in> A \<and> m \<le> n \<longrightarrow> m \<in> A"
  1026 shows "A = UNIV \<or> (\<exists>n. A = {0 ..< n})"
  1027 proof-
  1028   {assume "A \<noteq> UNIV" hence "\<exists>n. n \<notin> A" by blast
  1029    moreover obtain n where n_def: "n = (LEAST n. n \<notin> A)" by blast
  1030    ultimately have 1: "n \<notin> A \<and> (\<forall>m. m < n \<longrightarrow> m \<in> A)"
  1031    using LeastI_ex[of "\<lambda> n. n \<notin> A"] n_def Least_le[of "\<lambda> n. n \<notin> A"] by fastforce
  1032    have "A = {0 ..< n}"
  1033    proof(auto simp add: 1)
  1034      fix m assume *: "m \<in> A"
  1035      {assume "n \<le> m" with assms * have "n \<in> A" by blast
  1036       hence False using 1 by auto
  1037      }
  1038      thus "m < n" by fastforce
  1039    qed
  1040    hence "\<exists>n. A = {0 ..< n}" by blast
  1041   }
  1042   thus ?thesis by blast
  1043 qed
  1044 
  1045 lemma natLeq_ofilter_iff:
  1046 "ofilter natLeq A = (A = UNIV \<or> (\<exists>n. A = {0 ..< n}))"
  1047 proof(rule iffI)
  1048   assume "ofilter natLeq A"
  1049   hence "\<forall>m n. n \<in> A \<and> m \<le> n \<longrightarrow> m \<in> A"
  1050   by(auto simp add: natLeq_wo_rel wo_rel.ofilter_def under_def)
  1051   thus "A = UNIV \<or> (\<exists>n. A = {0 ..< n})" using closed_nat_set_iff by blast
  1052 next
  1053   assume "A = UNIV \<or> (\<exists>n. A = {0 ..< n})"
  1054   thus "ofilter natLeq A"
  1055   by(auto simp add: natLeq_ofilter_less natLeq_UNIV_ofilter)
  1056 qed
  1057 
  1058 lemma natLeq_under_leq: "under natLeq n = {0 .. n}"
  1059 unfolding under_def by auto
  1060 
  1061 lemma natLeq_on_ofilter_less_eq:
  1062 "n \<le> m \<Longrightarrow> wo_rel.ofilter (natLeq_on m) {0 ..< n}"
  1063 apply (auto simp add: natLeq_on_wo_rel wo_rel.ofilter_def)
  1064 apply (simp add: Field_natLeq_on)
  1065 by (auto simp add: under_def)
  1066 
  1067 lemma natLeq_on_ofilter_iff:
  1068 "wo_rel.ofilter (natLeq_on m) A = (\<exists>n \<le> m. A = {0 ..< n})"
  1069 proof(rule iffI)
  1070   assume *: "wo_rel.ofilter (natLeq_on m) A"
  1071   hence 1: "A \<le> {0..<m}"
  1072   by (auto simp add: natLeq_on_wo_rel wo_rel.ofilter_def under_def Field_natLeq_on)
  1073   hence "\<forall>n1 n2. n2 \<in> A \<and> n1 \<le> n2 \<longrightarrow> n1 \<in> A"
  1074   using * by(fastforce simp add: natLeq_on_wo_rel wo_rel.ofilter_def under_def)
  1075   hence "A = UNIV \<or> (\<exists>n. A = {0 ..< n})" using closed_nat_set_iff by blast
  1076   thus "\<exists>n \<le> m. A = {0 ..< n}" using 1 atLeastLessThan_less_eq by blast
  1077 next
  1078   assume "(\<exists>n\<le>m. A = {0 ..< n})"
  1079   thus "wo_rel.ofilter (natLeq_on m) A" by (auto simp add: natLeq_on_ofilter_less_eq)
  1080 qed
  1081 
  1082 corollary natLeq_on_ofilter:
  1083 "ofilter(natLeq_on n) {0 ..< n}"
  1084 by (auto simp add: natLeq_on_ofilter_less_eq)
  1085 
  1086 lemma natLeq_on_ofilter_less:
  1087 "n < m \<Longrightarrow> ofilter (natLeq_on m) {0 .. n}"
  1088 by(auto simp add: natLeq_on_wo_rel wo_rel.ofilter_def,
  1089    simp add: Field_natLeq_on, unfold under_def, auto)
  1090 
  1091 lemma natLeq_on_ordLess_natLeq: "natLeq_on n <o natLeq"
  1092 using Field_natLeq Field_natLeq_on[of n]
  1093       finite_ordLess_infinite[of "natLeq_on n" natLeq]
  1094       natLeq_Well_order natLeq_on_Well_order[of n] by auto
  1095 
  1096 lemma natLeq_on_injective:
  1097 "natLeq_on m = natLeq_on n \<Longrightarrow> m = n"
  1098 using Field_natLeq_on[of m] Field_natLeq_on[of n]
  1099       atLeastLessThan_injective[of m n, unfolded atLeastLessThan_def] by blast
  1100 
  1101 lemma natLeq_on_injective_ordIso:
  1102 "(natLeq_on m =o natLeq_on n) = (m = n)"
  1103 proof(auto simp add: natLeq_on_Well_order ordIso_reflexive)
  1104   assume "natLeq_on m =o natLeq_on n"
  1105   then obtain f where "bij_betw f {x. x<m} {x. x<n}"
  1106   using Field_natLeq_on assms unfolding ordIso_def iso_def[abs_def] by auto
  1107   thus "m = n" using atLeastLessThan_injective2[of f m n]
  1108     unfolding atLeast_0 atLeastLessThan_def lessThan_def Int_UNIV_left by blast
  1109 qed
  1110 
  1111 
  1112 subsubsection {* Then as cardinals *}
  1113 
  1114 lemma ordIso_natLeq_infinite1:
  1115 "|A| =o natLeq \<Longrightarrow> \<not>finite A"
  1116 using ordIso_symmetric ordIso_imp_ordLeq infinite_iff_natLeq_ordLeq by blast
  1117 
  1118 lemma ordIso_natLeq_infinite2:
  1119 "natLeq =o |A| \<Longrightarrow> \<not>finite A"
  1120 using ordIso_imp_ordLeq infinite_iff_natLeq_ordLeq by blast
  1121 
  1122 
  1123 lemma ordIso_natLeq_on_imp_finite:
  1124 "|A| =o natLeq_on n \<Longrightarrow> finite A"
  1125 unfolding ordIso_def iso_def[abs_def]
  1126 by (auto simp: Field_natLeq_on bij_betw_finite)
  1127 
  1128 
  1129 lemma natLeq_on_Card_order: "Card_order (natLeq_on n)"
  1130 proof(unfold card_order_on_def,
  1131       auto simp add: natLeq_on_Well_order, simp add: Field_natLeq_on)
  1132   fix r assume "well_order_on {x. x < n} r"
  1133   thus "natLeq_on n \<le>o r"
  1134   using finite_atLeastLessThan natLeq_on_well_order_on
  1135         finite_well_order_on_ordIso ordIso_iff_ordLeq by blast
  1136 qed
  1137 
  1138 
  1139 corollary card_of_Field_natLeq_on:
  1140 "|Field (natLeq_on n)| =o natLeq_on n"
  1141 using Field_natLeq_on natLeq_on_Card_order
  1142       Card_order_iff_ordIso_card_of[of "natLeq_on n"]
  1143       ordIso_symmetric[of "natLeq_on n"] by blast
  1144 
  1145 
  1146 corollary card_of_less:
  1147 "|{0 ..< n}| =o natLeq_on n"
  1148 using Field_natLeq_on card_of_Field_natLeq_on
  1149 unfolding atLeast_0 atLeastLessThan_def lessThan_def Int_UNIV_left by auto
  1150 
  1151 
  1152 lemma natLeq_on_ordLeq_less_eq:
  1153 "((natLeq_on m) \<le>o (natLeq_on n)) = (m \<le> n)"
  1154 proof
  1155   assume "natLeq_on m \<le>o natLeq_on n"
  1156   then obtain f where "inj_on f {x. x < m} \<and> f ` {x. x < m} \<le> {x. x < n}"
  1157   unfolding ordLeq_def using
  1158     embed_inj_on[OF natLeq_on_Well_order[of m], of "natLeq_on n", unfolded Field_natLeq_on]
  1159      embed_Field[OF natLeq_on_Well_order[of m], of "natLeq_on n", unfolded Field_natLeq_on] by blast
  1160   thus "m \<le> n" using atLeastLessThan_less_eq2
  1161     unfolding atLeast_0 atLeastLessThan_def lessThan_def Int_UNIV_left by blast
  1162 next
  1163   assume "m \<le> n"
  1164   hence "inj_on id {0..<m} \<and> id ` {0..<m} \<le> {0..<n}" unfolding inj_on_def by auto
  1165   hence "|{0..<m}| \<le>o |{0..<n}|" using card_of_ordLeq by blast
  1166   thus "natLeq_on m \<le>o natLeq_on n"
  1167   using card_of_less ordIso_ordLeq_trans ordLeq_ordIso_trans ordIso_symmetric by blast
  1168 qed
  1169 
  1170 
  1171 lemma natLeq_on_ordLeq_less:
  1172 "((natLeq_on m) <o (natLeq_on n)) = (m < n)"
  1173 using not_ordLeq_iff_ordLess[OF natLeq_on_Well_order natLeq_on_Well_order, of n m]
  1174    natLeq_on_ordLeq_less_eq[of n m] by linarith
  1175 
  1176 lemma ordLeq_natLeq_on_imp_finite:
  1177 assumes "|A| \<le>o natLeq_on n"
  1178 shows "finite A"
  1179 proof-
  1180   have "|A| \<le>o |{0 ..< n}|"
  1181   using assms card_of_less ordIso_symmetric ordLeq_ordIso_trans by blast
  1182   thus ?thesis by (auto simp add: card_of_ordLeq_finite)
  1183 qed
  1184 
  1185 
  1186 subsubsection {* "Backward compatibility" with the numeric cardinal operator for finite sets *}
  1187 
  1188 lemma finite_card_of_iff_card2:
  1189 assumes FIN: "finite A" and FIN': "finite B"
  1190 shows "( |A| \<le>o |B| ) = (card A \<le> card B)"
  1191 using assms card_of_ordLeq[of A B] inj_on_iff_card_le[of A B] by blast
  1192 
  1193 lemma finite_imp_card_of_natLeq_on:
  1194 assumes "finite A"
  1195 shows "|A| =o natLeq_on (card A)"
  1196 proof-
  1197   obtain h where "bij_betw h A {0 ..< card A}"
  1198   using assms ex_bij_betw_finite_nat by blast
  1199   thus ?thesis using card_of_ordIso card_of_less ordIso_equivalence by blast
  1200 qed
  1201 
  1202 lemma finite_iff_card_of_natLeq_on:
  1203 "finite A = (\<exists>n. |A| =o natLeq_on n)"
  1204 using finite_imp_card_of_natLeq_on[of A]
  1205 by(auto simp add: ordIso_natLeq_on_imp_finite)
  1206 
  1207 
  1208 lemma finite_card_of_iff_card:
  1209 assumes FIN: "finite A" and FIN': "finite B"
  1210 shows "( |A| =o |B| ) = (card A = card B)"
  1211 using assms card_of_ordIso[of A B] bij_betw_iff_card[of A B] by blast
  1212 
  1213 lemma finite_card_of_iff_card3:
  1214 assumes FIN: "finite A" and FIN': "finite B"
  1215 shows "( |A| <o |B| ) = (card A < card B)"
  1216 proof-
  1217   have "( |A| <o |B| ) = (~ ( |B| \<le>o |A| ))" by simp
  1218   also have "... = (~ (card B \<le> card A))"
  1219   using assms by(simp add: finite_card_of_iff_card2)
  1220   also have "... = (card A < card B)" by auto
  1221   finally show ?thesis .
  1222 qed
  1223 
  1224 lemma card_Field_natLeq_on:
  1225 "card(Field(natLeq_on n)) = n"
  1226 using Field_natLeq_on card_atLeastLessThan by auto
  1227 
  1228 
  1229 subsection {* The successor of a cardinal *}
  1230 
  1231 lemma embed_implies_ordIso_Restr:
  1232 assumes WELL: "Well_order r" and WELL': "Well_order r'" and EMB: "embed r' r f"
  1233 shows "r' =o Restr r (f ` (Field r'))"
  1234 using assms embed_implies_iso_Restr Well_order_Restr unfolding ordIso_def by blast
  1235 
  1236 lemma cardSuc_Well_order[simp]:
  1237 "Card_order r \<Longrightarrow> Well_order(cardSuc r)"
  1238 using cardSuc_Card_order unfolding card_order_on_def by blast
  1239 
  1240 lemma Field_cardSuc_not_empty:
  1241 assumes "Card_order r"
  1242 shows "Field (cardSuc r) \<noteq> {}"
  1243 proof
  1244   assume "Field(cardSuc r) = {}"
  1245   hence "|Field(cardSuc r)| \<le>o r" using assms Card_order_empty[of r] by auto
  1246   hence "cardSuc r \<le>o r" using assms card_of_Field_ordIso
  1247   cardSuc_Card_order ordIso_symmetric ordIso_ordLeq_trans by blast
  1248   thus False using cardSuc_greater not_ordLess_ordLeq assms by blast
  1249 qed
  1250 
  1251 lemma cardSuc_mono_ordLess[simp]:
  1252 assumes CARD: "Card_order r" and CARD': "Card_order r'"
  1253 shows "(cardSuc r <o cardSuc r') = (r <o r')"
  1254 proof-
  1255   have 0: "Well_order r \<and> Well_order r' \<and> Well_order(cardSuc r) \<and> Well_order(cardSuc r')"
  1256   using assms by auto
  1257   thus ?thesis
  1258   using not_ordLeq_iff_ordLess not_ordLeq_iff_ordLess[of r r']
  1259   using cardSuc_mono_ordLeq[of r' r] assms by blast
  1260 qed
  1261 
  1262 lemma cardSuc_natLeq_on_Suc:
  1263 "cardSuc(natLeq_on n) =o natLeq_on(Suc n)"
  1264 proof-
  1265   obtain r r' p where r_def: "r = natLeq_on n" and
  1266                       r'_def: "r' = cardSuc(natLeq_on n)"  and
  1267                       p_def: "p = natLeq_on(Suc n)" by blast
  1268   (* Preliminary facts:  *)
  1269   have CARD: "Card_order r \<and> Card_order r' \<and> Card_order p" unfolding r_def r'_def p_def
  1270   using cardSuc_ordLess_ordLeq natLeq_on_Card_order cardSuc_Card_order by blast
  1271   hence WELL: "Well_order r \<and> Well_order r' \<and>  Well_order p"
  1272   unfolding card_order_on_def by force
  1273   have FIELD: "Field r = {0..<n} \<and> Field p = {0..<(Suc n)}"
  1274   unfolding r_def p_def Field_natLeq_on atLeast_0 atLeastLessThan_def lessThan_def by simp
  1275   hence FIN: "finite (Field r)" by force
  1276   have "r <o r'" using CARD unfolding r_def r'_def using cardSuc_greater by blast
  1277   hence "|Field r| <o r'" using CARD card_of_Field_ordIso ordIso_ordLess_trans by blast
  1278   hence LESS: "|Field r| <o |Field r'|"
  1279   using CARD card_of_Field_ordIso ordLess_ordIso_trans ordIso_symmetric by blast
  1280   (* Main proof: *)
  1281   have "r' \<le>o p" using CARD unfolding r_def r'_def p_def
  1282   using natLeq_on_ordLeq_less cardSuc_ordLess_ordLeq by blast
  1283   moreover have "p \<le>o r'"
  1284   proof-
  1285     {assume "r' <o p"
  1286      then obtain f where 0: "embedS r' p f" unfolding ordLess_def by force
  1287      let ?q = "Restr p (f ` Field r')"
  1288      have 1: "embed r' p f" using 0 unfolding embedS_def by force
  1289      hence 2: "f ` Field r' < {0..<(Suc n)}"
  1290      using WELL FIELD 0 by (auto simp add: embedS_iff)
  1291      have "wo_rel.ofilter p (f ` Field r')" using embed_Field_ofilter 1 WELL by blast
  1292      then obtain m where "m \<le> Suc n" and 3: "f ` (Field r') = {0..<m}"
  1293      unfolding p_def by (auto simp add: natLeq_on_ofilter_iff)
  1294      hence 4: "m \<le> n" using 2 by force
  1295      (*  *)
  1296      have "bij_betw f (Field r') (f ` (Field r'))"
  1297      using WELL embed_inj_on[OF _ 1] unfolding bij_betw_def by blast
  1298      moreover have "finite(f ` (Field r'))" using 3 finite_atLeastLessThan[of 0 m] by force
  1299      ultimately have 5: "finite (Field r') \<and> card(Field r') = card (f ` (Field r'))"
  1300      using bij_betw_same_card bij_betw_finite by metis
  1301      hence "card(Field r') \<le> card(Field r)" using 3 4 FIELD by force
  1302      hence "|Field r'| \<le>o |Field r|" using FIN 5 finite_card_of_iff_card2 by blast
  1303      hence False using LESS not_ordLess_ordLeq by auto
  1304     }
  1305     thus ?thesis using WELL CARD by fastforce
  1306   qed
  1307   ultimately show ?thesis using ordIso_iff_ordLeq unfolding r'_def p_def by blast
  1308 qed
  1309 
  1310 lemma card_of_Plus_ordLeq_infinite[simp]:
  1311 assumes C: "\<not>finite C" and A: "|A| \<le>o |C|" and B: "|B| \<le>o |C|"
  1312 shows "|A <+> B| \<le>o |C|"
  1313 proof-
  1314   let ?r = "cardSuc |C|"
  1315   have "Card_order ?r \<and> \<not>finite (Field ?r)" using assms by simp
  1316   moreover have "|A| <o ?r" and "|B| <o ?r" using A B by auto
  1317   ultimately have "|A <+> B| <o ?r"
  1318   using card_of_Plus_ordLess_infinite_Field by blast
  1319   thus ?thesis using C by simp
  1320 qed
  1321 
  1322 lemma card_of_Un_ordLeq_infinite[simp]:
  1323 assumes C: "\<not>finite C" and A: "|A| \<le>o |C|" and B: "|B| \<le>o |C|"
  1324 shows "|A Un B| \<le>o |C|"
  1325 using assms card_of_Plus_ordLeq_infinite card_of_Un_Plus_ordLeq
  1326 ordLeq_transitive by metis
  1327 
  1328 
  1329 subsection {* Others *}
  1330 
  1331 lemma under_mono[simp]:
  1332 assumes "Well_order r" and "(i,j) \<in> r"
  1333 shows "under r i \<subseteq> under r j"
  1334 using assms unfolding under_def order_on_defs
  1335 trans_def by blast
  1336 
  1337 lemma underS_under:
  1338 assumes "i \<in> Field r"
  1339 shows "underS r i = under r i - {i}"
  1340 using assms unfolding underS_def under_def by auto
  1341 
  1342 lemma relChain_under:
  1343 assumes "Well_order r"
  1344 shows "relChain r (\<lambda> i. under r i)"
  1345 using assms unfolding relChain_def by auto
  1346 
  1347 lemma card_of_infinite_diff_finite:
  1348 assumes "\<not>finite A" and "finite B"
  1349 shows "|A - B| =o |A|"
  1350 by (metis assms card_of_Un_diff_infinite finite_ordLess_infinite2)
  1351 
  1352 lemma infinite_card_of_diff_singl:
  1353 assumes "\<not>finite A"
  1354 shows "|A - {a}| =o |A|"
  1355 by (metis assms card_of_infinite_diff_finite finite.emptyI finite_insert)
  1356 
  1357 lemma card_of_vimage:
  1358 assumes "B \<subseteq> range f"
  1359 shows "|B| \<le>o |f -` B|"
  1360 apply(rule surj_imp_ordLeq[of _ f])
  1361 using assms by (metis Int_absorb2 image_vimage_eq order_refl)
  1362 
  1363 lemma surj_card_of_vimage:
  1364 assumes "surj f"
  1365 shows "|B| \<le>o |f -` B|"
  1366 by (metis assms card_of_vimage subset_UNIV)
  1367 
  1368 lemma infinite_Pow:
  1369 assumes "\<not> finite A"
  1370 shows "\<not> finite (Pow A)"
  1371 proof-
  1372   have "|A| \<le>o |Pow A|" by (metis card_of_Pow ordLess_imp_ordLeq)
  1373   thus ?thesis by (metis assms finite_Pow_iff)
  1374 qed
  1375 
  1376 (* bounded powerset *)
  1377 definition Bpow where
  1378 "Bpow r A \<equiv> {X . X \<subseteq> A \<and> |X| \<le>o r}"
  1379 
  1380 lemma Bpow_empty[simp]:
  1381 assumes "Card_order r"
  1382 shows "Bpow r {} = {{}}"
  1383 using assms unfolding Bpow_def by auto
  1384 
  1385 lemma singl_in_Bpow:
  1386 assumes rc: "Card_order r"
  1387 and r: "Field r \<noteq> {}" and a: "a \<in> A"
  1388 shows "{a} \<in> Bpow r A"
  1389 proof-
  1390   have "|{a}| \<le>o r" using r rc by auto
  1391   thus ?thesis unfolding Bpow_def using a by auto
  1392 qed
  1393 
  1394 lemma ordLeq_card_Bpow:
  1395 assumes rc: "Card_order r" and r: "Field r \<noteq> {}"
  1396 shows "|A| \<le>o |Bpow r A|"
  1397 proof-
  1398   have "inj_on (\<lambda> a. {a}) A" unfolding inj_on_def by auto
  1399   moreover have "(\<lambda> a. {a}) ` A \<subseteq> Bpow r A"
  1400   using singl_in_Bpow[OF assms] by auto
  1401   ultimately show ?thesis unfolding card_of_ordLeq[symmetric] by blast
  1402 qed
  1403 
  1404 lemma infinite_Bpow:
  1405 assumes rc: "Card_order r" and r: "Field r \<noteq> {}"
  1406 and A: "\<not>finite A"
  1407 shows "\<not>finite (Bpow r A)"
  1408 using ordLeq_card_Bpow[OF rc r]
  1409 by (metis A card_of_ordLeq_infinite)
  1410 
  1411 definition Func_option where
  1412  "Func_option A B \<equiv>
  1413   {f. (\<forall> a. f a \<noteq> None \<longleftrightarrow> a \<in> A) \<and> (\<forall> a \<in> A. case f a of Some b \<Rightarrow> b \<in> B |None \<Rightarrow> True)}"
  1414 
  1415 lemma card_of_Func_option_Func:
  1416 "|Func_option A B| =o |Func A B|"
  1417 proof (rule ordIso_symmetric, unfold card_of_ordIso[symmetric], intro exI)
  1418   let ?F = "\<lambda> f a. if a \<in> A then Some (f a) else None"
  1419   show "bij_betw ?F (Func A B) (Func_option A B)"
  1420   unfolding bij_betw_def unfolding inj_on_def proof(intro conjI ballI impI)
  1421     fix f g assume f: "f \<in> Func A B" and g: "g \<in> Func A B" and eq: "?F f = ?F g"
  1422     show "f = g"
  1423     proof(rule ext)
  1424       fix a
  1425       show "f a = g a"
  1426       proof(cases "a \<in> A")
  1427         case True
  1428         have "Some (f a) = ?F f a" using True by auto
  1429         also have "... = ?F g a" using eq unfolding fun_eq_iff by(rule allE)
  1430         also have "... = Some (g a)" using True by auto
  1431         finally have "Some (f a) = Some (g a)" .
  1432         thus ?thesis by simp
  1433       qed(insert f g, unfold Func_def, auto)
  1434     qed
  1435   next
  1436     show "?F ` Func A B = Func_option A B"
  1437     proof safe
  1438       fix f assume f: "f \<in> Func_option A B"
  1439       def g \<equiv> "\<lambda> a. case f a of Some b \<Rightarrow> b | None \<Rightarrow> undefined"
  1440       have "g \<in> Func A B"
  1441       using f unfolding g_def Func_def Func_option_def by force+
  1442       moreover have "f = ?F g"
  1443       proof(rule ext)
  1444         fix a show "f a = ?F g a"
  1445         using f unfolding Func_option_def g_def by (cases "a \<in> A") force+
  1446       qed
  1447       ultimately show "f \<in> ?F ` (Func A B)" by blast
  1448     qed(unfold Func_def Func_option_def, auto)
  1449   qed
  1450 qed
  1451 
  1452 (* partial-function space: *)
  1453 definition Pfunc where
  1454 "Pfunc A B \<equiv>
  1455  {f. (\<forall>a. f a \<noteq> None \<longrightarrow> a \<in> A) \<and>
  1456      (\<forall>a. case f a of None \<Rightarrow> True | Some b \<Rightarrow> b \<in> B)}"
  1457 
  1458 lemma Func_Pfunc:
  1459 "Func_option A B \<subseteq> Pfunc A B"
  1460 unfolding Func_option_def Pfunc_def by auto
  1461 
  1462 lemma Pfunc_Func_option:
  1463 "Pfunc A B = (\<Union> A' \<in> Pow A. Func_option A' B)"
  1464 proof safe
  1465   fix f assume f: "f \<in> Pfunc A B"
  1466   show "f \<in> (\<Union>A'\<in>Pow A. Func_option A' B)"
  1467   proof (intro UN_I)
  1468     let ?A' = "{a. f a \<noteq> None}"
  1469     show "?A' \<in> Pow A" using f unfolding Pow_def Pfunc_def by auto
  1470     show "f \<in> Func_option ?A' B" using f unfolding Func_option_def Pfunc_def by auto
  1471   qed
  1472 next
  1473   fix f A' assume "f \<in> Func_option A' B" and "A' \<subseteq> A"
  1474   thus "f \<in> Pfunc A B" unfolding Func_option_def Pfunc_def by auto
  1475 qed
  1476 
  1477 lemma card_of_Func_mono:
  1478 fixes A1 A2 :: "'a set" and B :: "'b set"
  1479 assumes A12: "A1 \<subseteq> A2" and B: "B \<noteq> {}"
  1480 shows "|Func A1 B| \<le>o |Func A2 B|"
  1481 proof-
  1482   obtain bb where bb: "bb \<in> B" using B by auto
  1483   def F \<equiv> "\<lambda> (f1::'a \<Rightarrow> 'b) a. if a \<in> A2 then (if a \<in> A1 then f1 a else bb)
  1484                                                 else undefined"
  1485   show ?thesis unfolding card_of_ordLeq[symmetric] proof(intro exI[of _ F] conjI)
  1486     show "inj_on F (Func A1 B)" unfolding inj_on_def proof safe
  1487       fix f g assume f: "f \<in> Func A1 B" and g: "g \<in> Func A1 B" and eq: "F f = F g"
  1488       show "f = g"
  1489       proof(rule ext)
  1490         fix a show "f a = g a"
  1491         proof(cases "a \<in> A1")
  1492           case True
  1493           thus ?thesis using eq A12 unfolding F_def fun_eq_iff
  1494           by (elim allE[of _ a]) auto
  1495         qed(insert f g, unfold Func_def, fastforce)
  1496       qed
  1497     qed
  1498   qed(insert bb, unfold Func_def F_def, force)
  1499 qed
  1500 
  1501 lemma card_of_Func_option_mono:
  1502 fixes A1 A2 :: "'a set" and B :: "'b set"
  1503 assumes A12: "A1 \<subseteq> A2" and B: "B \<noteq> {}"
  1504 shows "|Func_option A1 B| \<le>o |Func_option A2 B|"
  1505 by (metis card_of_Func_mono[OF A12 B] card_of_Func_option_Func
  1506   ordIso_ordLeq_trans ordLeq_ordIso_trans ordIso_symmetric)
  1507 
  1508 lemma card_of_Pfunc_Pow_Func_option:
  1509 assumes "B \<noteq> {}"
  1510 shows "|Pfunc A B| \<le>o |Pow A <*> Func_option A B|"
  1511 proof-
  1512   have "|Pfunc A B| =o |\<Union> A' \<in> Pow A. Func_option A' B|" (is "_ =o ?K")
  1513     unfolding Pfunc_Func_option by(rule card_of_refl)
  1514   also have "?K \<le>o |Sigma (Pow A) (\<lambda> A'. Func_option A' B)|" using card_of_UNION_Sigma .
  1515   also have "|Sigma (Pow A) (\<lambda> A'. Func_option A' B)| \<le>o |Pow A <*> Func_option A B|"
  1516     apply(rule card_of_Sigma_mono1) using card_of_Func_option_mono[OF _ assms] by auto
  1517   finally show ?thesis .
  1518 qed
  1519 
  1520 lemma Bpow_ordLeq_Func_Field:
  1521 assumes rc: "Card_order r" and r: "Field r \<noteq> {}" and A: "\<not>finite A"
  1522 shows "|Bpow r A| \<le>o |Func (Field r) A|"
  1523 proof-
  1524   let ?F = "\<lambda> f. {x | x a. f a = x \<and> a \<in> Field r}"
  1525   {fix X assume "X \<in> Bpow r A - {{}}"
  1526    hence XA: "X \<subseteq> A" and "|X| \<le>o r"
  1527    and X: "X \<noteq> {}" unfolding Bpow_def by auto
  1528    hence "|X| \<le>o |Field r|" by (metis Field_card_of card_of_mono2)
  1529    then obtain F where 1: "X = F ` (Field r)"
  1530    using card_of_ordLeq2[OF X] by metis
  1531    def f \<equiv> "\<lambda> i. if i \<in> Field r then F i else undefined"
  1532    have "\<exists> f \<in> Func (Field r) A. X = ?F f"
  1533    apply (intro bexI[of _ f]) using 1 XA unfolding Func_def f_def by auto
  1534   }
  1535   hence "Bpow r A - {{}} \<subseteq> ?F ` (Func (Field r) A)" by auto
  1536   hence "|Bpow r A - {{}}| \<le>o |Func (Field r) A|"
  1537   by (rule surj_imp_ordLeq)
  1538   moreover
  1539   {have 2: "\<not>finite (Bpow r A)" using infinite_Bpow[OF rc r A] .
  1540    have "|Bpow r A| =o |Bpow r A - {{}}|"
  1541      by (metis 2 infinite_card_of_diff_singl ordIso_symmetric)
  1542   }
  1543   ultimately show ?thesis by (metis ordIso_ordLeq_trans)
  1544 qed
  1545 
  1546 lemma empty_in_Func[simp]:
  1547 "B \<noteq> {} \<Longrightarrow> (\<lambda>x. undefined) \<in> Func {} B"
  1548 unfolding Func_def by auto
  1549 
  1550 lemma Func_mono[simp]:
  1551 assumes "B1 \<subseteq> B2"
  1552 shows "Func A B1 \<subseteq> Func A B2"
  1553 using assms unfolding Func_def by force
  1554 
  1555 lemma Pfunc_mono[simp]:
  1556 assumes "A1 \<subseteq> A2" and "B1 \<subseteq> B2"
  1557 shows "Pfunc A B1 \<subseteq> Pfunc A B2"
  1558 using assms in_mono unfolding Pfunc_def apply safe
  1559 apply(case_tac "x a", auto)
  1560 by (metis in_mono option.simps(5))
  1561 
  1562 lemma card_of_Func_UNIV_UNIV:
  1563 "|Func (UNIV::'a set) (UNIV::'b set)| =o |UNIV::('a \<Rightarrow> 'b) set|"
  1564 using card_of_Func_UNIV[of "UNIV::'b set"] by auto
  1565 
  1566 lemma ordLeq_Func:
  1567 assumes "{b1,b2} \<subseteq> B" "b1 \<noteq> b2"
  1568 shows "|A| \<le>o |Func A B|"
  1569 unfolding card_of_ordLeq[symmetric] proof(intro exI conjI)
  1570   let ?F = "\<lambda> aa a. if a \<in> A then (if a = aa then b1 else b2) else undefined"
  1571   show "inj_on ?F A" using assms unfolding inj_on_def fun_eq_iff by auto
  1572   show "?F ` A \<subseteq> Func A B" using assms unfolding Func_def by auto
  1573 qed
  1574 
  1575 lemma infinite_Func:
  1576 assumes A: "\<not>finite A" and B: "{b1,b2} \<subseteq> B" "b1 \<noteq> b2"
  1577 shows "\<not>finite (Func A B)"
  1578 using ordLeq_Func[OF B] by (metis A card_of_ordLeq_finite)
  1579 
  1580 section {* Infinite cardinals are limit ordinals *}
  1581 
  1582 lemma card_order_infinite_isLimOrd:
  1583 assumes c: "Card_order r" and i: "\<not>finite (Field r)"
  1584 shows "isLimOrd r"
  1585 proof-
  1586   have 0: "wo_rel r" and 00: "Well_order r"
  1587   using c unfolding card_order_on_def wo_rel_def by auto
  1588   hence rr: "Refl r" by (metis wo_rel.REFL)
  1589   show ?thesis unfolding wo_rel.isLimOrd_def[OF 0] wo_rel.isSuccOrd_def[OF 0] proof safe
  1590     fix j assume j: "j \<in> Field r" and jm: "\<forall>i\<in>Field r. (i, j) \<in> r"
  1591     def p \<equiv> "Restr r (Field r - {j})"
  1592     have fp: "Field p = Field r - {j}"
  1593     unfolding p_def apply(rule Refl_Field_Restr2[OF rr]) by auto
  1594     have of: "ofilter r (Field p)" unfolding wo_rel.ofilter_def[OF 0] proof safe
  1595       fix a x assume a: "a \<in> Field p" and "x \<in> under r a"
  1596       hence x: "(x,a) \<in> r" "x \<in> Field r" unfolding under_def Field_def by auto
  1597       moreover have a: "a \<noteq> j" "a \<in> Field r" "(a,j) \<in> r" using a jm  unfolding fp by auto
  1598       ultimately have "x \<noteq> j" using j jm  by (metis 0 wo_rel.max2_def wo_rel.max2_equals1)
  1599       thus "x \<in> Field p" using x unfolding fp by auto
  1600     qed(unfold p_def Field_def, auto)
  1601     have "p <o r" using j ofilter_ordLess[OF 00 of] unfolding fp p_def[symmetric] by auto
  1602     hence 2: "|Field p| <o r" using c by (metis BNF_Cardinal_Order_Relation.ordLess_Field)
  1603     have "|Field p| =o |Field r|" unfolding fp using i by (metis infinite_card_of_diff_singl)
  1604     also have "|Field r| =o r"
  1605     using c by (metis card_of_unique ordIso_symmetric)
  1606     finally have "|Field p| =o r" .
  1607     with 2 show False by (metis not_ordLess_ordIso)
  1608   qed
  1609 qed
  1610 
  1611 lemma insert_Chain:
  1612 assumes "Refl r" "C \<in> Chains r" and "i \<in> Field r" and "\<And>j. j \<in> C \<Longrightarrow> (j,i) \<in> r \<or> (i,j) \<in> r"
  1613 shows "insert i C \<in> Chains r"
  1614 using assms unfolding Chains_def by (auto dest: refl_onD)
  1615 
  1616 lemma Collect_insert: "{R j |j. j \<in> insert j1 J} = insert (R j1) {R j |j. j \<in> J}"
  1617 by auto
  1618 
  1619 lemma Field_init_seg_of[simp]:
  1620 "Field init_seg_of = UNIV"
  1621 unfolding Field_def init_seg_of_def by auto
  1622 
  1623 lemma refl_init_seg_of[intro, simp]: "refl init_seg_of"
  1624 unfolding refl_on_def Field_def by auto
  1625 
  1626 lemma regularCard_all_ex:
  1627 assumes r: "Card_order r"   "regularCard r"
  1628 and As: "\<And> i j b. b \<in> B \<Longrightarrow> (i,j) \<in> r \<Longrightarrow> P i b \<Longrightarrow> P j b"
  1629 and Bsub: "\<forall> b \<in> B. \<exists> i \<in> Field r. P i b"
  1630 and cardB: "|B| <o r"
  1631 shows "\<exists> i \<in> Field r. \<forall> b \<in> B. P i b"
  1632 proof-
  1633   let ?As = "\<lambda>i. {b \<in> B. P i b}"
  1634   have "EX i : Field r. B \<le> ?As i"
  1635   apply(rule regularCard_UNION) using assms unfolding relChain_def by auto
  1636   thus ?thesis by auto
  1637 qed
  1638 
  1639 lemma relChain_stabilize:
  1640 assumes rc: "relChain r As" and AsB: "(\<Union> i \<in> Field r. As i) \<subseteq> B" and Br: "|B| <o r"
  1641 and ir: "\<not>finite (Field r)" and cr: "Card_order r"
  1642 shows "\<exists> i \<in> Field r. As (succ r i) = As i"
  1643 proof(rule ccontr, auto)
  1644   have 0: "wo_rel r" and 00: "Well_order r"
  1645   unfolding wo_rel_def by (metis card_order_on_well_order_on cr)+
  1646   have L: "isLimOrd r" using ir cr by (metis card_order_infinite_isLimOrd)
  1647   have AsBs: "(\<Union> i \<in> Field r. As (succ r i)) \<subseteq> B"
  1648   using AsB L apply safe by (metis "0" UN_I set_mp wo_rel.isLimOrd_succ)
  1649   assume As_s: "\<forall>i\<in>Field r. As (succ r i) \<noteq> As i"
  1650   have 1: "\<forall>i j. (i,j) \<in> r \<and> i \<noteq> j \<longrightarrow> As i \<subset> As j"
  1651   proof safe
  1652     fix i j assume 1: "(i, j) \<in> r" "i \<noteq> j" and Asij: "As i = As j"
  1653     hence rij: "(succ r i, j) \<in> r" by (metis "0" wo_rel.succ_smallest)
  1654     hence "As (succ r i) \<subseteq> As j" using rc unfolding relChain_def by auto
  1655     moreover
  1656     {have "(i,succ r i) \<in> r" apply(rule wo_rel.succ_in[OF 0])
  1657      using 1 unfolding aboveS_def by auto
  1658      hence "As i \<subset> As (succ r i)" using As_s rc rij unfolding relChain_def Field_def by auto
  1659     }
  1660     ultimately show False unfolding Asij by auto
  1661   qed (insert rc, unfold relChain_def, auto)
  1662   hence "\<forall> i \<in> Field r. \<exists> a. a \<in> As (succ r i) - As i"
  1663   using wo_rel.succ_in[OF 0] AsB
  1664   by(metis 0 card_order_infinite_isLimOrd cr ir psubset_imp_ex_mem
  1665             wo_rel.isLimOrd_aboveS wo_rel.succ_diff)
  1666   then obtain f where f: "\<forall> i \<in> Field r. f i \<in> As (succ r i) - As i" by metis
  1667   have "inj_on f (Field r)" unfolding inj_on_def proof safe
  1668     fix i j assume ij: "i \<in> Field r" "j \<in> Field r" and fij: "f i = f j"
  1669     show "i = j"
  1670     proof(cases rule: wo_rel.cases_Total3[OF 0], safe)
  1671       assume "(i, j) \<in> r" and ijd: "i \<noteq> j"
  1672       hence rij: "(succ r i, j) \<in> r" by (metis "0" wo_rel.succ_smallest)
  1673       hence "As (succ r i) \<subseteq> As j" using rc unfolding relChain_def by auto
  1674       thus "i = j" using ij ijd fij f by auto
  1675     next
  1676       assume "(j, i) \<in> r" and ijd: "i \<noteq> j"
  1677       hence rij: "(succ r j, i) \<in> r" by (metis "0" wo_rel.succ_smallest)
  1678       hence "As (succ r j) \<subseteq> As i" using rc unfolding relChain_def by auto
  1679       thus "j = i" using ij ijd fij f by fastforce
  1680     qed(insert ij, auto)
  1681   qed
  1682   moreover have "f ` (Field r) \<subseteq> B" using f AsBs by auto
  1683   moreover have "|B| <o |Field r|" using Br cr by (metis card_of_unique ordLess_ordIso_trans)
  1684   ultimately show False unfolding card_of_ordLess[symmetric] by auto
  1685 qed
  1686 
  1687 section {* Regular vs. Stable Cardinals *}
  1688 
  1689 definition stable :: "'a rel \<Rightarrow> bool"
  1690 where
  1691 "stable r \<equiv> \<forall>(A::'a set) (F :: 'a \<Rightarrow> 'a set).
  1692                |A| <o r \<and> (\<forall>a \<in> A. |F a| <o r)
  1693                \<longrightarrow> |SIGMA a : A. F a| <o r"
  1694 
  1695 lemma regularCard_stable:
  1696 assumes cr: "Card_order r" and ir: "\<not>finite (Field r)" and reg: "regularCard r"
  1697 shows "stable r"
  1698 unfolding stable_def proof safe
  1699   fix A :: "'a set" and F :: "'a \<Rightarrow> 'a set" assume A: "|A| <o r" and F: "\<forall>a\<in>A. |F a| <o r"
  1700   {assume "r \<le>o |Sigma A F|"
  1701    hence "|Field r| \<le>o |Sigma A F|" using card_of_Field_ordIso[OF cr]
  1702    by (metis Field_card_of card_of_cong ordLeq_iff_ordLess_or_ordIso ordLeq_ordLess_trans)
  1703    moreover have Fi: "Field r \<noteq> {}" using ir by auto
  1704    ultimately obtain f where f: "f ` Sigma A F = Field r" using card_of_ordLeq2 by metis
  1705    have r: "wo_rel r" using cr unfolding card_order_on_def wo_rel_def by auto
  1706    {fix a assume a: "a \<in> A"
  1707     def L \<equiv> "{(a,u) | u. u \<in> F a}"
  1708     have fL: "f ` L \<subseteq> Field r" using f a unfolding L_def by auto
  1709     have "|L| =o |F a|" unfolding L_def card_of_ordIso[symmetric]
  1710     apply(rule exI[of _ snd]) unfolding bij_betw_def inj_on_def by (auto simp: image_def)
  1711     hence "|L| <o r" using F a ordIso_ordLess_trans[of "|L|" "|F a|"] unfolding L_def by auto
  1712     hence "|f ` L| <o r" using ordLeq_ordLess_trans[OF card_of_image, of "L"] unfolding L_def by auto
  1713     hence "\<not> cofinal (f ` L) r" using reg fL unfolding regularCard_def by (metis not_ordLess_ordIso)
  1714     then obtain k where k: "k \<in> Field r" and "\<forall> l \<in> L. \<not> (f l \<noteq> k \<and> (k, f l) \<in> r)"
  1715     unfolding cofinal_def image_def by auto
  1716     hence "\<exists> k \<in> Field r. \<forall> l \<in> L. (f l, k) \<in> r" using r by (metis fL image_subset_iff wo_rel.in_notinI)
  1717     hence "\<exists> k \<in> Field r. \<forall> u \<in> F a. (f (a,u), k) \<in> r" unfolding L_def by auto
  1718    }
  1719    then obtain gg where gg: "\<forall> a \<in> A. \<forall> u \<in> F a. (f (a,u), gg a) \<in> r" by metis
  1720    obtain j0 where j0: "j0 \<in> Field r" using Fi by auto
  1721    def g \<equiv> "\<lambda> a. if F a \<noteq> {} then gg a else j0"
  1722    have g: "\<forall> a \<in> A. \<forall> u \<in> F a. (f (a,u),g a) \<in> r" using gg unfolding g_def by auto
  1723    hence 1: "Field r \<subseteq> (\<Union> a \<in> A. under r (g a))"
  1724    using f[symmetric] unfolding under_def image_def by auto
  1725    have gA: "g ` A \<subseteq> Field r" using gg j0 unfolding Field_def g_def by auto
  1726    moreover have "cofinal (g ` A) r" unfolding cofinal_def proof safe
  1727      fix i assume "i \<in> Field r"
  1728      then obtain j where ij: "(i,j) \<in> r" "i \<noteq> j" using cr ir by (metis infinite_Card_order_limit)
  1729      hence "j \<in> Field r" by (metis card_order_on_def cr well_order_on_domain)
  1730      then obtain a where a: "a \<in> A" and j: "(j, g a) \<in> r" using 1 unfolding under_def by auto
  1731      hence "(i, g a) \<in> r" using ij wo_rel.TRANS[OF r] unfolding trans_def by blast
  1732      moreover have "i \<noteq> g a"
  1733      using ij j r unfolding wo_rel_def unfolding well_order_on_def linear_order_on_def
  1734      partial_order_on_def antisym_def by auto
  1735      ultimately show "\<exists>j\<in>g ` A. i \<noteq> j \<and> (i, j) \<in> r" using a by auto
  1736    qed
  1737    ultimately have "|g ` A| =o r" using reg unfolding regularCard_def by auto
  1738    moreover have "|g ` A| \<le>o |A|" by (metis card_of_image)
  1739    ultimately have False using A by (metis not_ordLess_ordIso ordLeq_ordLess_trans)
  1740   }
  1741   thus "|Sigma A F| <o r"
  1742   using cr not_ordLess_iff_ordLeq by (metis card_of_Well_order card_order_on_well_order_on)
  1743 qed
  1744 
  1745 lemma stable_regularCard:
  1746 assumes cr: "Card_order r" and ir: "\<not>finite (Field r)" and st: "stable r"
  1747 shows "regularCard r"
  1748 unfolding regularCard_def proof safe
  1749   fix K assume K: "K \<subseteq> Field r" and cof: "cofinal K r"
  1750   have "|K| \<le>o r" using K by (metis card_of_Field_ordIso card_of_mono1 cr ordLeq_ordIso_trans)
  1751   moreover
  1752   {assume Kr: "|K| <o r"
  1753    then obtain f where "\<forall> a \<in> Field r. f a \<in> K \<and> a \<noteq> f a \<and> (a, f a) \<in> r"
  1754    using cof unfolding cofinal_def by metis
  1755    hence "Field r \<subseteq> (\<Union> a \<in> K. underS r a)" unfolding underS_def by auto
  1756    hence "r \<le>o |\<Union> a \<in> K. underS r a|" using cr
  1757    by (metis Card_order_iff_ordLeq_card_of card_of_mono1 ordLeq_transitive)
  1758    also have "|\<Union> a \<in> K. underS r a| \<le>o |SIGMA a: K. underS r a|" by (rule card_of_UNION_Sigma)
  1759    also
  1760    {have "\<forall> a \<in> K. |underS r a| <o r" using K by (metis card_of_underS cr subsetD)
  1761     hence "|SIGMA a: K. underS r a| <o r" using st Kr unfolding stable_def by auto
  1762    }
  1763    finally have "r <o r" .
  1764    hence False by (metis ordLess_irreflexive)
  1765   }
  1766   ultimately show "|K| =o r" by (metis ordLeq_iff_ordLess_or_ordIso)
  1767 qed
  1768 
  1769 (* Note that below the types of A and F are now unconstrained: *)
  1770 lemma stable_elim:
  1771 assumes ST: "stable r" and A_LESS: "|A| <o r" and
  1772         F_LESS: "\<And> a. a \<in> A \<Longrightarrow> |F a| <o r"
  1773 shows "|SIGMA a : A. F a| <o r"
  1774 proof-
  1775   obtain A' where 1: "A' < Field r \<and> |A'| <o r" and 2: " |A| =o |A'|"
  1776   using internalize_card_of_ordLess[of A r] A_LESS by blast
  1777   then obtain G where 3: "bij_betw G A' A"
  1778   using card_of_ordIso  ordIso_symmetric by blast
  1779   (*  *)
  1780   {fix a assume "a \<in> A"
  1781    hence "\<exists>B'. B' \<le> Field r \<and> |F a| =o |B'| \<and> |B'| <o r"
  1782    using internalize_card_of_ordLess[of "F a" r] F_LESS by blast
  1783   }
  1784   then obtain F' where
  1785   temp: "\<forall>a \<in> A. F' a \<le> Field r \<and> |F a| =o |F' a| \<and> |F' a| <o r"
  1786   using bchoice[of A "\<lambda> a B'. B' \<le> Field r \<and> |F a| =o |B'| \<and> |B'| <o r"] by blast
  1787   hence 4: "\<forall>a \<in> A. F' a \<le> Field r \<and> |F' a| <o r" by auto
  1788   have 5: "\<forall>a \<in> A. |F' a| =o |F a|" using temp ordIso_symmetric by auto
  1789   (*  *)
  1790   have "\<forall>a' \<in> A'. F'(G a') \<le> Field r \<and> |F'(G a')| <o r"
  1791   using 3 4 bij_betw_ball[of G A' A] by auto
  1792   hence "|SIGMA a' : A'. F'(G a')| <o r"
  1793   using ST 1 unfolding stable_def by auto
  1794   moreover have "|SIGMA a' : A'. F'(G a')| =o |SIGMA a : A. F a|"
  1795   using card_of_Sigma_cong[of G A' A F' F] 5 3 by blast
  1796   ultimately show ?thesis using ordIso_symmetric ordIso_ordLess_trans by blast
  1797 qed
  1798 
  1799 lemma stable_natLeq: "stable natLeq"
  1800 proof(unfold stable_def, safe)
  1801   fix A :: "'a set" and F :: "'a \<Rightarrow> 'a set"
  1802   assume "|A| <o natLeq" and "\<forall>a\<in>A. |F a| <o natLeq"
  1803   hence "finite A \<and> (\<forall>a \<in> A. finite(F a))"
  1804   by (auto simp add: finite_iff_ordLess_natLeq)
  1805   hence "finite(Sigma A F)" by (simp only: finite_SigmaI[of A F])
  1806   thus "|Sigma A F | <o natLeq"
  1807   by (auto simp add: finite_iff_ordLess_natLeq)
  1808 qed
  1809 
  1810 corollary regularCard_natLeq: "regularCard natLeq"
  1811 using stable_regularCard[OF natLeq_Card_order _ stable_natLeq] Field_natLeq by simp
  1812 
  1813 lemma stable_cardSuc:
  1814 assumes CARD: "Card_order r" and INF: "\<not>finite (Field r)"
  1815 shows "stable(cardSuc r)"
  1816 using infinite_cardSuc_regularCard regularCard_stable
  1817 by (metis CARD INF cardSuc_Card_order cardSuc_finite)
  1818 
  1819 lemma stable_UNION:
  1820 assumes ST: "stable r" and A_LESS: "|A| <o r" and
  1821         F_LESS: "\<And> a. a \<in> A \<Longrightarrow> |F a| <o r"
  1822 shows "|\<Union> a \<in> A. F a| <o r"
  1823 proof-
  1824   have "|\<Union> a \<in> A. F a| \<le>o |SIGMA a : A. F a|"
  1825   using card_of_UNION_Sigma by blast
  1826   thus ?thesis using assms stable_elim ordLeq_ordLess_trans by blast
  1827 qed
  1828 
  1829 lemma stable_ordIso1:
  1830 assumes ST: "stable r" and ISO: "r' =o r"
  1831 shows "stable r'"
  1832 proof(unfold stable_def, auto)
  1833   fix A::"'b set" and F::"'b \<Rightarrow> 'b set"
  1834   assume "|A| <o r'" and "\<forall>a \<in> A. |F a| <o r'"
  1835   hence "( |A| <o r) \<and> (\<forall>a \<in> A. |F a| <o r)"
  1836   using ISO ordLess_ordIso_trans by blast
  1837   hence "|SIGMA a : A. F a| <o r" using assms stable_elim by blast
  1838   thus "|SIGMA a : A. F a| <o r'"
  1839   using ISO ordIso_symmetric ordLess_ordIso_trans by blast
  1840 qed
  1841 
  1842 lemma stable_ordIso2:
  1843 assumes ST: "stable r" and ISO: "r =o r'"
  1844 shows "stable r'"
  1845 using assms stable_ordIso1 ordIso_symmetric by blast
  1846 
  1847 lemma stable_ordIso:
  1848 assumes "r =o r'"
  1849 shows "stable r = stable r'"
  1850 using assms stable_ordIso1 stable_ordIso2 by blast
  1851 
  1852 lemma stable_nat: "stable |UNIV::nat set|"
  1853 using stable_natLeq card_of_nat stable_ordIso by auto
  1854 
  1855 text{* Below, the type of "A" is not important -- we just had to choose an appropriate
  1856    type to make "A" possible. What is important is that arbitrarily large
  1857    infinite sets of stable cardinality exist. *}
  1858 
  1859 lemma infinite_stable_exists:
  1860 assumes CARD: "\<forall>r \<in> R. Card_order (r::'a rel)"
  1861 shows "\<exists>(A :: (nat + 'a set)set).
  1862           \<not>finite A \<and> stable |A| \<and> (\<forall>r \<in> R. r <o |A| )"
  1863 proof-
  1864   have "\<exists>(A :: (nat + 'a set)set).
  1865           \<not>finite A \<and> stable |A| \<and> |UNIV::'a set| <o |A|"
  1866   proof(cases "finite (UNIV::'a set)")
  1867     assume Case1: "finite (UNIV::'a set)"
  1868     let ?B = "UNIV::nat set"
  1869     have "\<not>finite(?B <+> {})" using finite_Plus_iff by blast
  1870     moreover
  1871     have "stable |?B|" using stable_natLeq card_of_nat stable_ordIso1 by blast
  1872     hence "stable |?B <+> {}|" using stable_ordIso card_of_Plus_empty1 by blast
  1873     moreover
  1874     have "\<not>finite(Field |?B| ) \<and> finite(Field |UNIV::'a set| )" using Case1 by simp
  1875     hence "|UNIV::'a set| <o |?B|" by (simp add: finite_ordLess_infinite)
  1876     hence "|UNIV::'a set| <o |?B <+> {}|" using card_of_Plus_empty1 ordLess_ordIso_trans by blast
  1877     ultimately show ?thesis by blast
  1878   next
  1879     assume Case1: "\<not>finite (UNIV::'a set)"
  1880     hence *: "\<not>finite(Field |UNIV::'a set| )" by simp
  1881     let ?B = "Field(cardSuc |UNIV::'a set| )"
  1882     have 0: "|?B| =o |{} <+> ?B|" using card_of_Plus_empty2 by blast
  1883     have 1: "\<not>finite ?B" using Case1 card_of_cardSuc_finite by blast
  1884     hence 2: "\<not>finite({} <+> ?B)" using 0 card_of_ordIso_finite by blast
  1885     have "|?B| =o cardSuc |UNIV::'a set|"
  1886     using card_of_Card_order cardSuc_Card_order card_of_Field_ordIso by blast
  1887     moreover have "stable(cardSuc |UNIV::'a set| )"
  1888     using stable_cardSuc * card_of_Card_order by blast
  1889     ultimately have "stable |?B|" using stable_ordIso by blast
  1890     hence 3: "stable |{} <+> ?B|" using stable_ordIso 0 by blast
  1891     have "|UNIV::'a set| <o cardSuc |UNIV::'a set|"
  1892     using card_of_Card_order cardSuc_greater by blast
  1893     moreover have "|?B| =o  cardSuc |UNIV::'a set|"
  1894     using card_of_Card_order cardSuc_Card_order  card_of_Field_ordIso by blast
  1895     ultimately have "|UNIV::'a set| <o |?B|"
  1896     using ordIso_symmetric ordLess_ordIso_trans by blast
  1897     hence "|UNIV::'a set| <o |{} <+> ?B|" using 0 ordLess_ordIso_trans by blast
  1898     thus ?thesis using 2 3 by blast
  1899   qed
  1900   thus ?thesis using CARD card_of_UNIV2 ordLeq_ordLess_trans by blast
  1901 qed
  1902 
  1903 corollary infinite_regularCard_exists:
  1904 assumes CARD: "\<forall>r \<in> R. Card_order (r::'a rel)"
  1905 shows "\<exists>(A :: (nat + 'a set)set).
  1906           \<not>finite A \<and> regularCard |A| \<and> (\<forall>r \<in> R. r <o |A| )"
  1907 using infinite_stable_exists[OF CARD] stable_regularCard by (metis Field_card_of card_of_card_order_on)
  1908 
  1909 end