src/HOL/BNF_Cardinal_Arithmetic.thy
author noschinl
Thu Feb 20 15:14:37 2014 +0100 (2014-02-20)
changeset 55604 42e4e8c2e8dc
parent 55059 ef2e0fb783c6
child 55811 aa1acc25126b
permissions -rw-r--r--
less flex-flex pairs
     1 (*  Title:      HOL/BNF_Cardinal_Arithmetic.thy
     2     Author:     Dmitriy Traytel, TU Muenchen
     3     Copyright   2012
     4 
     5 Cardinal arithmetic as needed by bounded natural functors.
     6 *)
     7 
     8 header {* Cardinal Arithmetic as Needed by Bounded Natural Functors *}
     9 
    10 theory BNF_Cardinal_Arithmetic
    11 imports BNF_Cardinal_Order_Relation
    12 begin
    13 
    14 lemma dir_image: "\<lbrakk>\<And>x y. (f x = f y) = (x = y); Card_order r\<rbrakk> \<Longrightarrow> r =o dir_image r f"
    15 by (rule dir_image_ordIso) (auto simp add: inj_on_def card_order_on_def)
    16 
    17 (*should supersede a weaker lemma from the library*)
    18 lemma dir_image_Field: "Field (dir_image r f) = f ` Field r"
    19 unfolding dir_image_def Field_def Range_def Domain_def by fast
    20 
    21 lemma card_order_dir_image:
    22   assumes bij: "bij f" and co: "card_order r"
    23   shows "card_order (dir_image r f)"
    24 proof -
    25   from assms have "Field (dir_image r f) = UNIV"
    26     using card_order_on_Card_order[of UNIV r] unfolding bij_def dir_image_Field by auto
    27   moreover from bij have "\<And>x y. (f x = f y) = (x = y)" unfolding bij_def inj_on_def by auto
    28   with co have "Card_order (dir_image r f)"
    29     using card_order_on_Card_order[of UNIV r] Card_order_ordIso2[OF _ dir_image] by blast
    30   ultimately show ?thesis by auto
    31 qed
    32 
    33 lemma ordIso_refl: "Card_order r \<Longrightarrow> r =o r"
    34 by (rule card_order_on_ordIso)
    35 
    36 lemma ordLeq_refl: "Card_order r \<Longrightarrow> r \<le>o r"
    37 by (rule ordIso_imp_ordLeq, rule card_order_on_ordIso)
    38 
    39 lemma card_of_ordIso_subst: "A = B \<Longrightarrow> |A| =o |B|"
    40 by (simp only: ordIso_refl card_of_Card_order)
    41 
    42 lemma Field_card_order: "card_order r \<Longrightarrow> Field r = UNIV"
    43 using card_order_on_Card_order[of UNIV r] by simp
    44 
    45 lemma card_of_Times_Plus_distrib:
    46   "|A <*> (B <+> C)| =o |A <*> B <+> A <*> C|" (is "|?RHS| =o |?LHS|")
    47 proof -
    48   let ?f = "\<lambda>(a, bc). case bc of Inl b \<Rightarrow> Inl (a, b) | Inr c \<Rightarrow> Inr (a, c)"
    49   have "bij_betw ?f ?RHS ?LHS" unfolding bij_betw_def inj_on_def by force
    50   thus ?thesis using card_of_ordIso by blast
    51 qed
    52 
    53 lemma Func_Times_Range:
    54   "|Func A (B <*> C)| =o |Func A B <*> Func A C|" (is "|?LHS| =o |?RHS|")
    55 proof -
    56   let ?F = "\<lambda>fg. (\<lambda>x. if x \<in> A then fst (fg x) else undefined,
    57                   \<lambda>x. if x \<in> A then snd (fg x) else undefined)"
    58   let ?G = "\<lambda>(f, g) x. if x \<in> A then (f x, g x) else undefined"
    59   have "bij_betw ?F ?LHS ?RHS" unfolding bij_betw_def inj_on_def
    60   apply safe
    61      apply (simp add: Func_def fun_eq_iff)
    62      apply (metis (no_types) pair_collapse)
    63     apply (auto simp: Func_def fun_eq_iff)[2]
    64   proof -
    65     fix f g assume "f \<in> Func A B" "g \<in> Func A C"
    66     thus "(f, g) \<in> ?F ` Func A (B \<times> C)"
    67       by (intro image_eqI[of _ _ "?G (f, g)"]) (auto simp: Func_def)
    68   qed
    69   thus ?thesis using card_of_ordIso by blast
    70 qed
    71 
    72 
    73 subsection {* Zero *}
    74 
    75 definition czero where
    76   "czero = card_of {}"
    77 
    78 lemma czero_ordIso:
    79   "czero =o czero"
    80 using card_of_empty_ordIso by (simp add: czero_def)
    81 
    82 lemma card_of_ordIso_czero_iff_empty:
    83   "|A| =o (czero :: 'b rel) \<longleftrightarrow> A = ({} :: 'a set)"
    84 unfolding czero_def by (rule iffI[OF card_of_empty2]) (auto simp: card_of_refl card_of_empty_ordIso)
    85 
    86 (* A "not czero" Cardinal predicate *)
    87 abbreviation Cnotzero where
    88   "Cnotzero (r :: 'a rel) \<equiv> \<not>(r =o (czero :: 'a rel)) \<and> Card_order r"
    89 
    90 (*helper*)
    91 lemma Cnotzero_imp_not_empty: "Cnotzero r \<Longrightarrow> Field r \<noteq> {}"
    92 by (metis Card_order_iff_ordIso_card_of czero_def)
    93 
    94 lemma czeroI:
    95   "\<lbrakk>Card_order r; Field r = {}\<rbrakk> \<Longrightarrow> r =o czero"
    96 using Cnotzero_imp_not_empty ordIso_transitive[OF _ czero_ordIso] by blast
    97 
    98 lemma czeroE:
    99   "r =o czero \<Longrightarrow> Field r = {}"
   100 unfolding czero_def
   101 by (drule card_of_cong) (simp only: Field_card_of card_of_empty2)
   102 
   103 lemma Cnotzero_mono:
   104   "\<lbrakk>Cnotzero r; Card_order q; r \<le>o q\<rbrakk> \<Longrightarrow> Cnotzero q"
   105 apply (rule ccontr)
   106 apply auto
   107 apply (drule czeroE)
   108 apply (erule notE)
   109 apply (erule czeroI)
   110 apply (drule card_of_mono2)
   111 apply (simp only: card_of_empty3)
   112 done
   113 
   114 subsection {* (In)finite cardinals *}
   115 
   116 definition cinfinite where
   117   "cinfinite r = (\<not> finite (Field r))"
   118 
   119 abbreviation Cinfinite where
   120   "Cinfinite r \<equiv> cinfinite r \<and> Card_order r"
   121 
   122 definition cfinite where
   123   "cfinite r = finite (Field r)"
   124 
   125 abbreviation Cfinite where
   126   "Cfinite r \<equiv> cfinite r \<and> Card_order r"
   127 
   128 lemma Cfinite_ordLess_Cinfinite: "\<lbrakk>Cfinite r; Cinfinite s\<rbrakk> \<Longrightarrow> r <o s"
   129   unfolding cfinite_def cinfinite_def
   130   by (metis card_order_on_well_order_on finite_ordLess_infinite)
   131 
   132 lemmas natLeq_card_order = natLeq_Card_order[unfolded Field_natLeq]
   133 
   134 lemma natLeq_cinfinite: "cinfinite natLeq"
   135 unfolding cinfinite_def Field_natLeq by (metis infinite_UNIV_nat)
   136 
   137 lemma natLeq_ordLeq_cinfinite:
   138   assumes inf: "Cinfinite r"
   139   shows "natLeq \<le>o r"
   140 proof -
   141   from inf have "natLeq \<le>o |Field r|" by (metis cinfinite_def infinite_iff_natLeq_ordLeq)
   142   also from inf have "|Field r| =o r" by (simp add: card_of_unique ordIso_symmetric)
   143   finally show ?thesis .
   144 qed
   145 
   146 lemma cinfinite_not_czero: "cinfinite r \<Longrightarrow> \<not> (r =o (czero :: 'a rel))"
   147 unfolding cinfinite_def by (metis czeroE finite.emptyI)
   148 
   149 lemma Cinfinite_Cnotzero: "Cinfinite r \<Longrightarrow> Cnotzero r"
   150 by (metis cinfinite_not_czero)
   151 
   152 lemma Cinfinite_cong: "\<lbrakk>r1 =o r2; Cinfinite r1\<rbrakk> \<Longrightarrow> Cinfinite r2"
   153 by (metis Card_order_ordIso2 card_of_mono2 card_of_ordLeq_infinite cinfinite_def ordIso_iff_ordLeq)
   154 
   155 lemma cinfinite_mono: "\<lbrakk>r1 \<le>o r2; cinfinite r1\<rbrakk> \<Longrightarrow> cinfinite r2"
   156 by (metis card_of_mono2 card_of_ordLeq_infinite cinfinite_def)
   157 
   158 
   159 subsection {* Binary sum *}
   160 
   161 definition csum (infixr "+c" 65) where
   162   "r1 +c r2 \<equiv> |Field r1 <+> Field r2|"
   163 
   164 lemma Field_csum: "Field (r +c s) = Inl ` Field r \<union> Inr ` Field s"
   165   unfolding csum_def Field_card_of by auto
   166 
   167 lemma Card_order_csum:
   168   "Card_order (r1 +c r2)"
   169 unfolding csum_def by (simp add: card_of_Card_order)
   170 
   171 lemma csum_Cnotzero1:
   172   "Cnotzero r1 \<Longrightarrow> Cnotzero (r1 +c r2)"
   173 unfolding csum_def
   174 by (metis Cnotzero_imp_not_empty Plus_eq_empty_conv card_of_Card_order card_of_ordIso_czero_iff_empty)
   175 
   176 lemma card_order_csum:
   177   assumes "card_order r1" "card_order r2"
   178   shows "card_order (r1 +c r2)"
   179 proof -
   180   have "Field r1 = UNIV" "Field r2 = UNIV" using assms card_order_on_Card_order by auto
   181   thus ?thesis unfolding csum_def by (auto simp: card_of_card_order_on)
   182 qed
   183 
   184 lemma cinfinite_csum:
   185   "cinfinite r1 \<or> cinfinite r2 \<Longrightarrow> cinfinite (r1 +c r2)"
   186 unfolding cinfinite_def csum_def by (auto simp: Field_card_of)
   187 
   188 lemma Cinfinite_csum1:
   189   "Cinfinite r1 \<Longrightarrow> Cinfinite (r1 +c r2)"
   190 unfolding cinfinite_def csum_def by (metis Field_card_of card_of_Card_order finite_Plus_iff)
   191 
   192 lemma Cinfinite_csum:
   193   "Cinfinite r1 \<or> Cinfinite r2 \<Longrightarrow> Cinfinite (r1 +c r2)"
   194 unfolding cinfinite_def csum_def by (metis Field_card_of card_of_Card_order finite_Plus_iff)
   195 
   196 lemma Cinfinite_csum_strong:
   197   "\<lbrakk>Cinfinite r1; Cinfinite r2\<rbrakk> \<Longrightarrow> Cinfinite (r1 +c r2)"
   198 by (metis Cinfinite_csum)
   199 
   200 lemma csum_cong: "\<lbrakk>p1 =o r1; p2 =o r2\<rbrakk> \<Longrightarrow> p1 +c p2 =o r1 +c r2"
   201 by (simp only: csum_def ordIso_Plus_cong)
   202 
   203 lemma csum_cong1: "p1 =o r1 \<Longrightarrow> p1 +c q =o r1 +c q"
   204 by (simp only: csum_def ordIso_Plus_cong1)
   205 
   206 lemma csum_cong2: "p2 =o r2 \<Longrightarrow> q +c p2 =o q +c r2"
   207 by (simp only: csum_def ordIso_Plus_cong2)
   208 
   209 lemma csum_mono: "\<lbrakk>p1 \<le>o r1; p2 \<le>o r2\<rbrakk> \<Longrightarrow> p1 +c p2 \<le>o r1 +c r2"
   210 by (simp only: csum_def ordLeq_Plus_mono)
   211 
   212 lemma csum_mono1: "p1 \<le>o r1 \<Longrightarrow> p1 +c q \<le>o r1 +c q"
   213 by (simp only: csum_def ordLeq_Plus_mono1)
   214 
   215 lemma csum_mono2: "p2 \<le>o r2 \<Longrightarrow> q +c p2 \<le>o q +c r2"
   216 by (simp only: csum_def ordLeq_Plus_mono2)
   217 
   218 lemma ordLeq_csum1: "Card_order p1 \<Longrightarrow> p1 \<le>o p1 +c p2"
   219 by (simp only: csum_def Card_order_Plus1)
   220 
   221 lemma ordLeq_csum2: "Card_order p2 \<Longrightarrow> p2 \<le>o p1 +c p2"
   222 by (simp only: csum_def Card_order_Plus2)
   223 
   224 lemma csum_com: "p1 +c p2 =o p2 +c p1"
   225 by (simp only: csum_def card_of_Plus_commute)
   226 
   227 lemma csum_assoc: "(p1 +c p2) +c p3 =o p1 +c p2 +c p3"
   228 by (simp only: csum_def Field_card_of card_of_Plus_assoc)
   229 
   230 lemma Cfinite_csum: "\<lbrakk>Cfinite r; Cfinite s\<rbrakk> \<Longrightarrow> Cfinite (r +c s)"
   231   unfolding cfinite_def csum_def Field_card_of using card_of_card_order_on by simp
   232 
   233 lemma csum_csum: "(r1 +c r2) +c (r3 +c r4) =o (r1 +c r3) +c (r2 +c r4)"
   234 proof -
   235   have "(r1 +c r2) +c (r3 +c r4) =o r1 +c r2 +c (r3 +c r4)"
   236     by (metis csum_assoc)
   237   also have "r1 +c r2 +c (r3 +c r4) =o r1 +c (r2 +c r3) +c r4"
   238     by (metis csum_assoc csum_cong2 ordIso_symmetric)
   239   also have "r1 +c (r2 +c r3) +c r4 =o r1 +c (r3 +c r2) +c r4"
   240     by (metis csum_com csum_cong1 csum_cong2)
   241   also have "r1 +c (r3 +c r2) +c r4 =o r1 +c r3 +c r2 +c r4"
   242     by (metis csum_assoc csum_cong2 ordIso_symmetric)
   243   also have "r1 +c r3 +c r2 +c r4 =o (r1 +c r3) +c (r2 +c r4)"
   244     by (metis csum_assoc ordIso_symmetric)
   245   finally show ?thesis .
   246 qed
   247 
   248 lemma Plus_csum: "|A <+> B| =o |A| +c |B|"
   249 by (simp only: csum_def Field_card_of card_of_refl)
   250 
   251 lemma Un_csum: "|A \<union> B| \<le>o |A| +c |B|"
   252 using ordLeq_ordIso_trans[OF card_of_Un_Plus_ordLeq Plus_csum] by blast
   253 
   254 
   255 subsection {* One *}
   256 
   257 definition cone where
   258   "cone = card_of {()}"
   259 
   260 lemma Card_order_cone: "Card_order cone"
   261 unfolding cone_def by (rule card_of_Card_order)
   262 
   263 lemma Cfinite_cone: "Cfinite cone"
   264   unfolding cfinite_def by (simp add: Card_order_cone)
   265 
   266 lemma cone_not_czero: "\<not> (cone =o czero)"
   267 unfolding czero_def cone_def by (metis empty_not_insert card_of_empty3[of "{()}"] ordIso_iff_ordLeq)
   268 
   269 lemma cone_ordLeq_Cnotzero: "Cnotzero r \<Longrightarrow> cone \<le>o r"
   270 unfolding cone_def by (metis Card_order_singl_ordLeq czeroI)
   271 
   272 
   273 subsection {* Two *}
   274 
   275 definition ctwo where
   276   "ctwo = |UNIV :: bool set|"
   277 
   278 lemma Card_order_ctwo: "Card_order ctwo"
   279 unfolding ctwo_def by (rule card_of_Card_order)
   280 
   281 lemma ctwo_not_czero: "\<not> (ctwo =o czero)"
   282 using card_of_empty3[of "UNIV :: bool set"] ordIso_iff_ordLeq
   283 unfolding czero_def ctwo_def by (metis UNIV_not_empty)
   284 
   285 lemma ctwo_Cnotzero: "Cnotzero ctwo"
   286 by (simp add: ctwo_not_czero Card_order_ctwo)
   287 
   288 
   289 subsection {* Family sum *}
   290 
   291 definition Csum where
   292   "Csum r rs \<equiv> |SIGMA i : Field r. Field (rs i)|"
   293 
   294 (* Similar setup to the one for SIGMA from theory Big_Operators: *)
   295 syntax "_Csum" ::
   296   "pttrn => ('a * 'a) set => 'b * 'b set => (('a * 'b) * ('a * 'b)) set"
   297   ("(3CSUM _:_. _)" [0, 51, 10] 10)
   298 
   299 translations
   300   "CSUM i:r. rs" == "CONST Csum r (%i. rs)"
   301 
   302 lemma SIGMA_CSUM: "|SIGMA i : I. As i| = (CSUM i : |I|. |As i| )"
   303 by (auto simp: Csum_def Field_card_of)
   304 
   305 (* NB: Always, under the cardinal operator,
   306 operations on sets are reduced automatically to operations on cardinals.
   307 This should make cardinal reasoning more direct and natural.  *)
   308 
   309 
   310 subsection {* Product *}
   311 
   312 definition cprod (infixr "*c" 80) where
   313   "r1 *c r2 = |Field r1 <*> Field r2|"
   314 
   315 lemma card_order_cprod:
   316   assumes "card_order r1" "card_order r2"
   317   shows "card_order (r1 *c r2)"
   318 proof -
   319   have "Field r1 = UNIV" "Field r2 = UNIV" using assms card_order_on_Card_order by auto
   320   thus ?thesis by (auto simp: cprod_def card_of_card_order_on)
   321 qed
   322 
   323 lemma Card_order_cprod: "Card_order (r1 *c r2)"
   324 by (simp only: cprod_def Field_card_of card_of_card_order_on)
   325 
   326 lemma cprod_mono1: "p1 \<le>o r1 \<Longrightarrow> p1 *c q \<le>o r1 *c q"
   327 by (simp only: cprod_def ordLeq_Times_mono1)
   328 
   329 lemma cprod_mono2: "p2 \<le>o r2 \<Longrightarrow> q *c p2 \<le>o q *c r2"
   330 by (simp only: cprod_def ordLeq_Times_mono2)
   331 
   332 lemma ordLeq_cprod2: "\<lbrakk>Cnotzero p1; Card_order p2\<rbrakk> \<Longrightarrow> p2 \<le>o p1 *c p2"
   333 unfolding cprod_def by (metis Card_order_Times2 czeroI)
   334 
   335 lemma cinfinite_cprod: "\<lbrakk>cinfinite r1; cinfinite r2\<rbrakk> \<Longrightarrow> cinfinite (r1 *c r2)"
   336 by (simp add: cinfinite_def cprod_def Field_card_of infinite_cartesian_product)
   337 
   338 lemma cinfinite_cprod2: "\<lbrakk>Cnotzero r1; Cinfinite r2\<rbrakk> \<Longrightarrow> cinfinite (r1 *c r2)"
   339 by (metis cinfinite_mono ordLeq_cprod2)
   340 
   341 lemma Cinfinite_cprod2: "\<lbrakk>Cnotzero r1; Cinfinite r2\<rbrakk> \<Longrightarrow> Cinfinite (r1 *c r2)"
   342 by (blast intro: cinfinite_cprod2 Card_order_cprod)
   343 
   344 lemma cprod_com: "p1 *c p2 =o p2 *c p1"
   345 by (simp only: cprod_def card_of_Times_commute)
   346 
   347 lemma card_of_Csum_Times:
   348   "\<forall>i \<in> I. |A i| \<le>o |B| \<Longrightarrow> (CSUM i : |I|. |A i| ) \<le>o |I| *c |B|"
   349 by (simp only: Csum_def cprod_def Field_card_of card_of_Sigma_Times)
   350 
   351 lemma card_of_Csum_Times':
   352   assumes "Card_order r" "\<forall>i \<in> I. |A i| \<le>o r"
   353   shows "(CSUM i : |I|. |A i| ) \<le>o |I| *c r"
   354 proof -
   355   from assms(1) have *: "r =o |Field r|" by (simp add: card_of_unique)
   356   with assms(2) have "\<forall>i \<in> I. |A i| \<le>o |Field r|" by (blast intro: ordLeq_ordIso_trans)
   357   hence "(CSUM i : |I|. |A i| ) \<le>o |I| *c |Field r|" by (simp only: card_of_Csum_Times)
   358   also from * have "|I| *c |Field r| \<le>o |I| *c r"
   359     by (simp only: Field_card_of card_of_refl cprod_def ordIso_imp_ordLeq)
   360   finally show ?thesis .
   361 qed
   362 
   363 lemma cprod_csum_distrib1: "r1 *c r2 +c r1 *c r3 =o r1 *c (r2 +c r3)"
   364 unfolding csum_def cprod_def by (simp add: Field_card_of card_of_Times_Plus_distrib ordIso_symmetric)
   365 
   366 lemma csum_absorb2': "\<lbrakk>Card_order r2; r1 \<le>o r2; cinfinite r1 \<or> cinfinite r2\<rbrakk> \<Longrightarrow> r1 +c r2 =o r2"
   367 unfolding csum_def by (metis Card_order_Plus_infinite cinfinite_def cinfinite_mono)
   368 
   369 lemma csum_absorb1':
   370   assumes card: "Card_order r2"
   371   and r12: "r1 \<le>o r2" and cr12: "cinfinite r1 \<or> cinfinite r2"
   372   shows "r2 +c r1 =o r2"
   373 by (rule ordIso_transitive, rule csum_com, rule csum_absorb2', (simp only: assms)+)
   374 
   375 lemma csum_absorb1: "\<lbrakk>Cinfinite r2; r1 \<le>o r2\<rbrakk> \<Longrightarrow> r2 +c r1 =o r2"
   376 by (rule csum_absorb1') auto
   377 
   378 
   379 subsection {* Exponentiation *}
   380 
   381 definition cexp (infixr "^c" 90) where
   382   "r1 ^c r2 \<equiv> |Func (Field r2) (Field r1)|"
   383 
   384 lemma Card_order_cexp: "Card_order (r1 ^c r2)"
   385 unfolding cexp_def by (rule card_of_Card_order)
   386 
   387 lemma cexp_mono':
   388   assumes 1: "p1 \<le>o r1" and 2: "p2 \<le>o r2"
   389   and n: "Field p2 = {} \<Longrightarrow> Field r2 = {}"
   390   shows "p1 ^c p2 \<le>o r1 ^c r2"
   391 proof(cases "Field p1 = {}")
   392   case True
   393   hence "|Field |Func (Field p2) (Field p1)|| \<le>o cone"
   394     unfolding cone_def Field_card_of
   395     by (cases "Field p2 = {}", auto intro: card_of_ordLeqI2 simp: Func_empty)
   396        (metis Func_is_emp card_of_empty ex_in_conv)
   397   hence "|Func (Field p2) (Field p1)| \<le>o cone" by (simp add: Field_card_of cexp_def)
   398   hence "p1 ^c p2 \<le>o cone" unfolding cexp_def .
   399   thus ?thesis
   400   proof (cases "Field p2 = {}")
   401     case True
   402     with n have "Field r2 = {}" .
   403     hence "cone \<le>o r1 ^c r2" unfolding cone_def cexp_def Func_def
   404       by (auto intro: card_of_ordLeqI[where f="\<lambda>_ _. undefined"])
   405     thus ?thesis using `p1 ^c p2 \<le>o cone` ordLeq_transitive by auto
   406   next
   407     case False with True have "|Field (p1 ^c p2)| =o czero"
   408       unfolding card_of_ordIso_czero_iff_empty cexp_def Field_card_of Func_def by auto
   409     thus ?thesis unfolding cexp_def card_of_ordIso_czero_iff_empty Field_card_of
   410       by (simp add: card_of_empty)
   411   qed
   412 next
   413   case False
   414   have 1: "|Field p1| \<le>o |Field r1|" and 2: "|Field p2| \<le>o |Field r2|"
   415     using 1 2 by (auto simp: card_of_mono2)
   416   obtain f1 where f1: "f1 ` Field r1 = Field p1"
   417     using 1 unfolding card_of_ordLeq2[OF False, symmetric] by auto
   418   obtain f2 where f2: "inj_on f2 (Field p2)" "f2 ` Field p2 \<subseteq> Field r2"
   419     using 2 unfolding card_of_ordLeq[symmetric] by blast
   420   have 0: "Func_map (Field p2) f1 f2 ` (Field (r1 ^c r2)) = Field (p1 ^c p2)"
   421     unfolding cexp_def Field_card_of using Func_map_surj[OF f1 f2 n, symmetric] .
   422   have 00: "Field (p1 ^c p2) \<noteq> {}" unfolding cexp_def Field_card_of Func_is_emp
   423     using False by simp
   424   show ?thesis
   425     using 0 card_of_ordLeq2[OF 00] unfolding cexp_def Field_card_of by blast
   426 qed
   427 
   428 lemma cexp_mono:
   429   assumes 1: "p1 \<le>o r1" and 2: "p2 \<le>o r2"
   430   and n: "p2 =o czero \<Longrightarrow> r2 =o czero" and card: "Card_order p2"
   431   shows "p1 ^c p2 \<le>o r1 ^c r2"
   432   by (metis (full_types) "1" "2" card cexp_mono' czeroE czeroI n)
   433 
   434 lemma cexp_mono1:
   435   assumes 1: "p1 \<le>o r1" and q: "Card_order q"
   436   shows "p1 ^c q \<le>o r1 ^c q"
   437 using ordLeq_refl[OF q] by (rule cexp_mono[OF 1]) (auto simp: q)
   438 
   439 lemma cexp_mono2':
   440   assumes 2: "p2 \<le>o r2" and q: "Card_order q"
   441   and n: "Field p2 = {} \<Longrightarrow> Field r2 = {}"
   442   shows "q ^c p2 \<le>o q ^c r2"
   443 using ordLeq_refl[OF q] by (rule cexp_mono'[OF _ 2 n]) auto
   444 
   445 lemma cexp_mono2:
   446   assumes 2: "p2 \<le>o r2" and q: "Card_order q"
   447   and n: "p2 =o czero \<Longrightarrow> r2 =o czero" and card: "Card_order p2"
   448   shows "q ^c p2 \<le>o q ^c r2"
   449 using ordLeq_refl[OF q] by (rule cexp_mono[OF _ 2 n card]) auto
   450 
   451 lemma cexp_mono2_Cnotzero:
   452   assumes "p2 \<le>o r2" "Card_order q" "Cnotzero p2"
   453   shows "q ^c p2 \<le>o q ^c r2"
   454 by (metis assms cexp_mono2' czeroI)
   455 
   456 lemma cexp_cong:
   457   assumes 1: "p1 =o r1" and 2: "p2 =o r2"
   458   and Cr: "Card_order r2"
   459   and Cp: "Card_order p2"
   460   shows "p1 ^c p2 =o r1 ^c r2"
   461 proof -
   462   obtain f where "bij_betw f (Field p2) (Field r2)"
   463     using 2 card_of_ordIso[of "Field p2" "Field r2"] card_of_cong by auto
   464   hence 0: "Field p2 = {} \<longleftrightarrow> Field r2 = {}" unfolding bij_betw_def by auto
   465   have r: "p2 =o czero \<Longrightarrow> r2 =o czero"
   466     and p: "r2 =o czero \<Longrightarrow> p2 =o czero"
   467      using 0 Cr Cp czeroE czeroI by auto
   468   show ?thesis using 0 1 2 unfolding ordIso_iff_ordLeq
   469     using r p cexp_mono[OF _ _ _ Cp] cexp_mono[OF _ _ _ Cr] by metis
   470 qed
   471 
   472 lemma cexp_cong1:
   473   assumes 1: "p1 =o r1" and q: "Card_order q"
   474   shows "p1 ^c q =o r1 ^c q"
   475 by (rule cexp_cong[OF 1 _ q q]) (rule ordIso_refl[OF q])
   476 
   477 lemma cexp_cong2:
   478   assumes 2: "p2 =o r2" and q: "Card_order q" and p: "Card_order p2"
   479   shows "q ^c p2 =o q ^c r2"
   480 by (rule cexp_cong[OF _ 2]) (auto simp only: ordIso_refl Card_order_ordIso2[OF p 2] q p)
   481 
   482 lemma cexp_cone:
   483   assumes "Card_order r"
   484   shows "r ^c cone =o r"
   485 proof -
   486   have "r ^c cone =o |Field r|"
   487     unfolding cexp_def cone_def Field_card_of Func_empty
   488       card_of_ordIso[symmetric] bij_betw_def Func_def inj_on_def image_def
   489     by (rule exI[of _ "\<lambda>f. f ()"]) auto
   490   also have "|Field r| =o r" by (rule card_of_Field_ordIso[OF assms])
   491   finally show ?thesis .
   492 qed
   493 
   494 lemma cexp_cprod:
   495   assumes r1: "Card_order r1"
   496   shows "(r1 ^c r2) ^c r3 =o r1 ^c (r2 *c r3)" (is "?L =o ?R")
   497 proof -
   498   have "?L =o r1 ^c (r3 *c r2)"
   499     unfolding cprod_def cexp_def Field_card_of
   500     using card_of_Func_Times by(rule ordIso_symmetric)
   501   also have "r1 ^c (r3 *c r2) =o ?R"
   502     apply(rule cexp_cong2) using cprod_com r1 by (auto simp: Card_order_cprod)
   503   finally show ?thesis .
   504 qed
   505 
   506 lemma cprod_infinite1': "\<lbrakk>Cinfinite r; Cnotzero p; p \<le>o r\<rbrakk> \<Longrightarrow> r *c p =o r"
   507 unfolding cinfinite_def cprod_def
   508 by (rule Card_order_Times_infinite[THEN conjunct1]) (blast intro: czeroI)+
   509 
   510 lemma cexp_cprod_ordLeq:
   511   assumes r1: "Card_order r1" and r2: "Cinfinite r2"
   512   and r3: "Cnotzero r3" "r3 \<le>o r2"
   513   shows "(r1 ^c r2) ^c r3 =o r1 ^c r2" (is "?L =o ?R")
   514 proof-
   515   have "?L =o r1 ^c (r2 *c r3)" using cexp_cprod[OF r1] .
   516   also have "r1 ^c (r2 *c r3) =o ?R"
   517   apply(rule cexp_cong2)
   518   apply(rule cprod_infinite1'[OF r2 r3]) using r1 r2 by (fastforce simp: Card_order_cprod)+
   519   finally show ?thesis .
   520 qed
   521 
   522 lemma Cnotzero_UNIV: "Cnotzero |UNIV|"
   523 by (auto simp: card_of_Card_order card_of_ordIso_czero_iff_empty)
   524 
   525 lemma ordLess_ctwo_cexp:
   526   assumes "Card_order r"
   527   shows "r <o ctwo ^c r"
   528 proof -
   529   have "r <o |Pow (Field r)|" using assms by (rule Card_order_Pow)
   530   also have "|Pow (Field r)| =o ctwo ^c r"
   531     unfolding ctwo_def cexp_def Field_card_of by (rule card_of_Pow_Func)
   532   finally show ?thesis .
   533 qed
   534 
   535 lemma ordLeq_cexp1:
   536   assumes "Cnotzero r" "Card_order q"
   537   shows "q \<le>o q ^c r"
   538 proof (cases "q =o (czero :: 'a rel)")
   539   case True thus ?thesis by (simp only: card_of_empty cexp_def czero_def ordIso_ordLeq_trans)
   540 next
   541   case False
   542   thus ?thesis
   543     apply -
   544     apply (rule ordIso_ordLeq_trans)
   545     apply (rule ordIso_symmetric)
   546     apply (rule cexp_cone)
   547     apply (rule assms(2))
   548     apply (rule cexp_mono2)
   549     apply (rule cone_ordLeq_Cnotzero)
   550     apply (rule assms(1))
   551     apply (rule assms(2))
   552     apply (rule notE)
   553     apply (rule cone_not_czero)
   554     apply assumption
   555     apply (rule Card_order_cone)
   556   done
   557 qed
   558 
   559 lemma ordLeq_cexp2:
   560   assumes "ctwo \<le>o q" "Card_order r"
   561   shows "r \<le>o q ^c r"
   562 proof (cases "r =o (czero :: 'a rel)")
   563   case True thus ?thesis by (simp only: card_of_empty cexp_def czero_def ordIso_ordLeq_trans)
   564 next
   565   case False thus ?thesis
   566     apply -
   567     apply (rule ordLess_imp_ordLeq)
   568     apply (rule ordLess_ordLeq_trans)
   569     apply (rule ordLess_ctwo_cexp)
   570     apply (rule assms(2))
   571     apply (rule cexp_mono1)
   572     apply (rule assms(1))
   573     apply (rule assms(2))
   574   done
   575 qed
   576 
   577 lemma cinfinite_cexp: "\<lbrakk>ctwo \<le>o q; Cinfinite r\<rbrakk> \<Longrightarrow> cinfinite (q ^c r)"
   578 by (metis assms cinfinite_mono ordLeq_cexp2)
   579 
   580 lemma Cinfinite_cexp:
   581   "\<lbrakk>ctwo \<le>o q; Cinfinite r\<rbrakk> \<Longrightarrow> Cinfinite (q ^c r)"
   582 by (simp add: cinfinite_cexp Card_order_cexp)
   583 
   584 lemma ctwo_ordLess_natLeq: "ctwo <o natLeq"
   585 unfolding ctwo_def using finite_UNIV natLeq_cinfinite natLeq_Card_order
   586 by (intro Cfinite_ordLess_Cinfinite) (auto simp: cfinite_def card_of_Card_order)
   587 
   588 lemma ctwo_ordLess_Cinfinite: "Cinfinite r \<Longrightarrow> ctwo <o r"
   589 by (metis ctwo_ordLess_natLeq natLeq_ordLeq_cinfinite ordLess_ordLeq_trans)
   590 
   591 lemma ctwo_ordLeq_Cinfinite:
   592   assumes "Cinfinite r"
   593   shows "ctwo \<le>o r"
   594 by (rule ordLess_imp_ordLeq[OF ctwo_ordLess_Cinfinite[OF assms]])
   595 
   596 lemma Un_Cinfinite_bound: "\<lbrakk>|A| \<le>o r; |B| \<le>o r; Cinfinite r\<rbrakk> \<Longrightarrow> |A \<union> B| \<le>o r"
   597 by (auto simp add: cinfinite_def card_of_Un_ordLeq_infinite_Field)
   598 
   599 lemma UNION_Cinfinite_bound: "\<lbrakk>|I| \<le>o r; \<forall>i \<in> I. |A i| \<le>o r; Cinfinite r\<rbrakk> \<Longrightarrow> |\<Union>i \<in> I. A i| \<le>o r"
   600 by (auto simp add: card_of_UNION_ordLeq_infinite_Field cinfinite_def)
   601 
   602 lemma csum_cinfinite_bound:
   603   assumes "p \<le>o r" "q \<le>o r" "Card_order p" "Card_order q" "Cinfinite r"
   604   shows "p +c q \<le>o r"
   605 proof -
   606   from assms(1-4) have "|Field p| \<le>o r" "|Field q| \<le>o r"
   607     unfolding card_order_on_def using card_of_least ordLeq_transitive by blast+
   608   with assms show ?thesis unfolding cinfinite_def csum_def
   609     by (blast intro: card_of_Plus_ordLeq_infinite_Field)
   610 qed
   611 
   612 lemma cprod_cinfinite_bound:
   613   assumes "p \<le>o r" "q \<le>o r" "Card_order p" "Card_order q" "Cinfinite r"
   614   shows "p *c q \<le>o r"
   615 proof -
   616   from assms(1-4) have "|Field p| \<le>o r" "|Field q| \<le>o r"
   617     unfolding card_order_on_def using card_of_least ordLeq_transitive by blast+
   618   with assms show ?thesis unfolding cinfinite_def cprod_def
   619     by (blast intro: card_of_Times_ordLeq_infinite_Field)
   620 qed
   621 
   622 lemma cprod_csum_cexp:
   623   "r1 *c r2 \<le>o (r1 +c r2) ^c ctwo"
   624 unfolding cprod_def csum_def cexp_def ctwo_def Field_card_of
   625 proof -
   626   let ?f = "\<lambda>(a, b). %x. if x then Inl a else Inr b"
   627   have "inj_on ?f (Field r1 \<times> Field r2)" (is "inj_on _ ?LHS")
   628     by (auto simp: inj_on_def fun_eq_iff split: bool.split)
   629   moreover
   630   have "?f ` ?LHS \<subseteq> Func (UNIV :: bool set) (Field r1 <+> Field r2)" (is "_ \<subseteq> ?RHS")
   631     by (auto simp: Func_def)
   632   ultimately show "|?LHS| \<le>o |?RHS|" using card_of_ordLeq by blast
   633 qed
   634 
   635 lemma Cfinite_cprod_Cinfinite: "\<lbrakk>Cfinite r; Cinfinite s\<rbrakk> \<Longrightarrow> r *c s \<le>o s"
   636 by (intro cprod_cinfinite_bound)
   637   (auto intro: ordLeq_refl ordLess_imp_ordLeq[OF Cfinite_ordLess_Cinfinite])
   638 
   639 lemma cprod_cexp: "(r *c s) ^c t =o r ^c t *c s ^c t"
   640   unfolding cprod_def cexp_def Field_card_of by (rule Func_Times_Range)
   641 
   642 lemma cprod_cexp_csum_cexp_Cinfinite:
   643   assumes t: "Cinfinite t"
   644   shows "(r *c s) ^c t \<le>o (r +c s) ^c t"
   645 proof -
   646   have "(r *c s) ^c t \<le>o ((r +c s) ^c ctwo) ^c t"
   647     by (rule cexp_mono1[OF cprod_csum_cexp conjunct2[OF t]])
   648   also have "((r +c s) ^c ctwo) ^c t =o (r +c s) ^c (ctwo *c t)"
   649     by (rule cexp_cprod[OF Card_order_csum])
   650   also have "(r +c s) ^c (ctwo *c t) =o (r +c s) ^c (t *c ctwo)"
   651     by (rule cexp_cong2[OF cprod_com Card_order_csum Card_order_cprod])
   652   also have "(r +c s) ^c (t *c ctwo) =o ((r +c s) ^c t) ^c ctwo"
   653     by (rule ordIso_symmetric[OF cexp_cprod[OF Card_order_csum]])
   654   also have "((r +c s) ^c t) ^c ctwo =o (r +c s) ^c t"
   655     by (rule cexp_cprod_ordLeq[OF Card_order_csum t ctwo_Cnotzero ctwo_ordLeq_Cinfinite[OF t]])
   656   finally show ?thesis .
   657 qed
   658 
   659 lemma Cfinite_cexp_Cinfinite:
   660   assumes s: "Cfinite s" and t: "Cinfinite t"
   661   shows "s ^c t \<le>o ctwo ^c t"
   662 proof (cases "s \<le>o ctwo")
   663   case True thus ?thesis using t by (blast intro: cexp_mono1)
   664 next
   665   case False
   666   hence "ctwo \<le>o s" by (metis card_order_on_well_order_on ctwo_Cnotzero ordLeq_total s)
   667   hence "Cnotzero s" by (metis Cnotzero_mono ctwo_Cnotzero s)
   668   hence st: "Cnotzero (s *c t)" by (metis Cinfinite_cprod2 cinfinite_not_czero t)
   669   have "s ^c t \<le>o (ctwo ^c s) ^c t"
   670     using assms by (blast intro: cexp_mono1 ordLess_imp_ordLeq[OF ordLess_ctwo_cexp])
   671   also have "(ctwo ^c s) ^c t =o ctwo ^c (s *c t)"
   672     by (blast intro: Card_order_ctwo cexp_cprod)
   673   also have "ctwo ^c (s *c t) \<le>o ctwo ^c t"
   674     using assms st by (intro cexp_mono2_Cnotzero Cfinite_cprod_Cinfinite Card_order_ctwo)
   675   finally show ?thesis .
   676 qed
   677 
   678 lemma csum_Cfinite_cexp_Cinfinite:
   679   assumes r: "Card_order r" and s: "Cfinite s" and t: "Cinfinite t"
   680   shows "(r +c s) ^c t \<le>o (r +c ctwo) ^c t"
   681 proof (cases "Cinfinite r")
   682   case True
   683   hence "r +c s =o r" by (intro csum_absorb1 ordLess_imp_ordLeq[OF Cfinite_ordLess_Cinfinite] s)
   684   hence "(r +c s) ^c t =o r ^c t" using t by (blast intro: cexp_cong1)
   685   also have "r ^c t \<le>o (r +c ctwo) ^c t" using t by (blast intro: cexp_mono1 ordLeq_csum1 r)
   686   finally show ?thesis .
   687 next
   688   case False
   689   with r have "Cfinite r" unfolding cinfinite_def cfinite_def by auto
   690   hence "Cfinite (r +c s)" by (intro Cfinite_csum s)
   691   hence "(r +c s) ^c t \<le>o ctwo ^c t" by (intro Cfinite_cexp_Cinfinite t)
   692   also have "ctwo ^c t \<le>o (r +c ctwo) ^c t" using t
   693     by (blast intro: cexp_mono1 ordLeq_csum2 Card_order_ctwo)
   694   finally show ?thesis .
   695 qed
   696 
   697 (* cardSuc *)
   698 
   699 lemma Cinfinite_cardSuc: "Cinfinite r \<Longrightarrow> Cinfinite (cardSuc r)"
   700 by (simp add: cinfinite_def cardSuc_Card_order cardSuc_finite)
   701 
   702 lemma cardSuc_UNION_Cinfinite:
   703   assumes "Cinfinite r" "relChain (cardSuc r) As" "B \<le> (UN i : Field (cardSuc r). As i)" "|B| <=o r"
   704   shows "EX i : Field (cardSuc r). B \<le> As i"
   705 using cardSuc_UNION assms unfolding cinfinite_def by blast
   706 
   707 end