src/HOL/BNF_Cardinal_Arithmetic.thy
 author blanchet Mon Jan 20 18:24:56 2014 +0100 (2014-01-20) changeset 55059 ef2e0fb783c6 parent 55056 b5c94200d081 child 55604 42e4e8c2e8dc permissions -rw-r--r--
```     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 by (auto intro: card_of_ordLeqI)
```
```   404     thus ?thesis using `p1 ^c p2 \<le>o cone` ordLeq_transitive by auto
```
```   405   next
```
```   406     case False with True have "|Field (p1 ^c p2)| =o czero"
```
```   407       unfolding card_of_ordIso_czero_iff_empty cexp_def Field_card_of Func_def by auto
```
```   408     thus ?thesis unfolding cexp_def card_of_ordIso_czero_iff_empty Field_card_of
```
```   409       by (simp add: card_of_empty)
```
```   410   qed
```
```   411 next
```
```   412   case False
```
```   413   have 1: "|Field p1| \<le>o |Field r1|" and 2: "|Field p2| \<le>o |Field r2|"
```
```   414     using 1 2 by (auto simp: card_of_mono2)
```
```   415   obtain f1 where f1: "f1 ` Field r1 = Field p1"
```
```   416     using 1 unfolding card_of_ordLeq2[OF False, symmetric] by auto
```
```   417   obtain f2 where f2: "inj_on f2 (Field p2)" "f2 ` Field p2 \<subseteq> Field r2"
```
```   418     using 2 unfolding card_of_ordLeq[symmetric] by blast
```
```   419   have 0: "Func_map (Field p2) f1 f2 ` (Field (r1 ^c r2)) = Field (p1 ^c p2)"
```
```   420     unfolding cexp_def Field_card_of using Func_map_surj[OF f1 f2 n, symmetric] .
```
```   421   have 00: "Field (p1 ^c p2) \<noteq> {}" unfolding cexp_def Field_card_of Func_is_emp
```
```   422     using False by simp
```
```   423   show ?thesis
```
```   424     using 0 card_of_ordLeq2[OF 00] unfolding cexp_def Field_card_of by blast
```
```   425 qed
```
```   426
```
```   427 lemma cexp_mono:
```
```   428   assumes 1: "p1 \<le>o r1" and 2: "p2 \<le>o r2"
```
```   429   and n: "p2 =o czero \<Longrightarrow> r2 =o czero" and card: "Card_order p2"
```
```   430   shows "p1 ^c p2 \<le>o r1 ^c r2"
```
```   431   by (metis (full_types) "1" "2" card cexp_mono' czeroE czeroI n)
```
```   432
```
```   433 lemma cexp_mono1:
```
```   434   assumes 1: "p1 \<le>o r1" and q: "Card_order q"
```
```   435   shows "p1 ^c q \<le>o r1 ^c q"
```
```   436 using ordLeq_refl[OF q] by (rule cexp_mono[OF 1]) (auto simp: q)
```
```   437
```
```   438 lemma cexp_mono2':
```
```   439   assumes 2: "p2 \<le>o r2" and q: "Card_order q"
```
```   440   and n: "Field p2 = {} \<Longrightarrow> Field r2 = {}"
```
```   441   shows "q ^c p2 \<le>o q ^c r2"
```
```   442 using ordLeq_refl[OF q] by (rule cexp_mono'[OF _ 2 n]) auto
```
```   443
```
```   444 lemma cexp_mono2:
```
```   445   assumes 2: "p2 \<le>o r2" and q: "Card_order q"
```
```   446   and n: "p2 =o czero \<Longrightarrow> r2 =o czero" and card: "Card_order p2"
```
```   447   shows "q ^c p2 \<le>o q ^c r2"
```
```   448 using ordLeq_refl[OF q] by (rule cexp_mono[OF _ 2 n card]) auto
```
```   449
```
```   450 lemma cexp_mono2_Cnotzero:
```
```   451   assumes "p2 \<le>o r2" "Card_order q" "Cnotzero p2"
```
```   452   shows "q ^c p2 \<le>o q ^c r2"
```
```   453 by (metis assms cexp_mono2' czeroI)
```
```   454
```
```   455 lemma cexp_cong:
```
```   456   assumes 1: "p1 =o r1" and 2: "p2 =o r2"
```
```   457   and Cr: "Card_order r2"
```
```   458   and Cp: "Card_order p2"
```
```   459   shows "p1 ^c p2 =o r1 ^c r2"
```
```   460 proof -
```
```   461   obtain f where "bij_betw f (Field p2) (Field r2)"
```
```   462     using 2 card_of_ordIso[of "Field p2" "Field r2"] card_of_cong by auto
```
```   463   hence 0: "Field p2 = {} \<longleftrightarrow> Field r2 = {}" unfolding bij_betw_def by auto
```
```   464   have r: "p2 =o czero \<Longrightarrow> r2 =o czero"
```
```   465     and p: "r2 =o czero \<Longrightarrow> p2 =o czero"
```
```   466      using 0 Cr Cp czeroE czeroI by auto
```
```   467   show ?thesis using 0 1 2 unfolding ordIso_iff_ordLeq
```
```   468     using r p cexp_mono[OF _ _ _ Cp] cexp_mono[OF _ _ _ Cr] by metis
```
```   469 qed
```
```   470
```
```   471 lemma cexp_cong1:
```
```   472   assumes 1: "p1 =o r1" and q: "Card_order q"
```
```   473   shows "p1 ^c q =o r1 ^c q"
```
```   474 by (rule cexp_cong[OF 1 _ q q]) (rule ordIso_refl[OF q])
```
```   475
```
```   476 lemma cexp_cong2:
```
```   477   assumes 2: "p2 =o r2" and q: "Card_order q" and p: "Card_order p2"
```
```   478   shows "q ^c p2 =o q ^c r2"
```
```   479 by (rule cexp_cong[OF _ 2]) (auto simp only: ordIso_refl Card_order_ordIso2[OF p 2] q p)
```
```   480
```
```   481 lemma cexp_cone:
```
```   482   assumes "Card_order r"
```
```   483   shows "r ^c cone =o r"
```
```   484 proof -
```
```   485   have "r ^c cone =o |Field r|"
```
```   486     unfolding cexp_def cone_def Field_card_of Func_empty
```
```   487       card_of_ordIso[symmetric] bij_betw_def Func_def inj_on_def image_def
```
```   488     by (rule exI[of _ "\<lambda>f. f ()"]) auto
```
```   489   also have "|Field r| =o r" by (rule card_of_Field_ordIso[OF assms])
```
```   490   finally show ?thesis .
```
```   491 qed
```
```   492
```
```   493 lemma cexp_cprod:
```
```   494   assumes r1: "Card_order r1"
```
```   495   shows "(r1 ^c r2) ^c r3 =o r1 ^c (r2 *c r3)" (is "?L =o ?R")
```
```   496 proof -
```
```   497   have "?L =o r1 ^c (r3 *c r2)"
```
```   498     unfolding cprod_def cexp_def Field_card_of
```
```   499     using card_of_Func_Times by(rule ordIso_symmetric)
```
```   500   also have "r1 ^c (r3 *c r2) =o ?R"
```
```   501     apply(rule cexp_cong2) using cprod_com r1 by (auto simp: Card_order_cprod)
```
```   502   finally show ?thesis .
```
```   503 qed
```
```   504
```
```   505 lemma cprod_infinite1': "\<lbrakk>Cinfinite r; Cnotzero p; p \<le>o r\<rbrakk> \<Longrightarrow> r *c p =o r"
```
```   506 unfolding cinfinite_def cprod_def
```
```   507 by (rule Card_order_Times_infinite[THEN conjunct1]) (blast intro: czeroI)+
```
```   508
```
```   509 lemma cexp_cprod_ordLeq:
```
```   510   assumes r1: "Card_order r1" and r2: "Cinfinite r2"
```
```   511   and r3: "Cnotzero r3" "r3 \<le>o r2"
```
```   512   shows "(r1 ^c r2) ^c r3 =o r1 ^c r2" (is "?L =o ?R")
```
```   513 proof-
```
```   514   have "?L =o r1 ^c (r2 *c r3)" using cexp_cprod[OF r1] .
```
```   515   also have "r1 ^c (r2 *c r3) =o ?R"
```
```   516   apply(rule cexp_cong2)
```
```   517   apply(rule cprod_infinite1'[OF r2 r3]) using r1 r2 by (fastforce simp: Card_order_cprod)+
```
```   518   finally show ?thesis .
```
```   519 qed
```
```   520
```
```   521 lemma Cnotzero_UNIV: "Cnotzero |UNIV|"
```
```   522 by (auto simp: card_of_Card_order card_of_ordIso_czero_iff_empty)
```
```   523
```
```   524 lemma ordLess_ctwo_cexp:
```
```   525   assumes "Card_order r"
```
```   526   shows "r <o ctwo ^c r"
```
```   527 proof -
```
```   528   have "r <o |Pow (Field r)|" using assms by (rule Card_order_Pow)
```
```   529   also have "|Pow (Field r)| =o ctwo ^c r"
```
```   530     unfolding ctwo_def cexp_def Field_card_of by (rule card_of_Pow_Func)
```
```   531   finally show ?thesis .
```
```   532 qed
```
```   533
```
```   534 lemma ordLeq_cexp1:
```
```   535   assumes "Cnotzero r" "Card_order q"
```
```   536   shows "q \<le>o q ^c r"
```
```   537 proof (cases "q =o (czero :: 'a rel)")
```
```   538   case True thus ?thesis by (simp only: card_of_empty cexp_def czero_def ordIso_ordLeq_trans)
```
```   539 next
```
```   540   case False
```
```   541   thus ?thesis
```
```   542     apply -
```
```   543     apply (rule ordIso_ordLeq_trans)
```
```   544     apply (rule ordIso_symmetric)
```
```   545     apply (rule cexp_cone)
```
```   546     apply (rule assms(2))
```
```   547     apply (rule cexp_mono2)
```
```   548     apply (rule cone_ordLeq_Cnotzero)
```
```   549     apply (rule assms(1))
```
```   550     apply (rule assms(2))
```
```   551     apply (rule notE)
```
```   552     apply (rule cone_not_czero)
```
```   553     apply assumption
```
```   554     apply (rule Card_order_cone)
```
```   555   done
```
```   556 qed
```
```   557
```
```   558 lemma ordLeq_cexp2:
```
```   559   assumes "ctwo \<le>o q" "Card_order r"
```
```   560   shows "r \<le>o q ^c r"
```
```   561 proof (cases "r =o (czero :: 'a rel)")
```
```   562   case True thus ?thesis by (simp only: card_of_empty cexp_def czero_def ordIso_ordLeq_trans)
```
```   563 next
```
```   564   case False thus ?thesis
```
```   565     apply -
```
```   566     apply (rule ordLess_imp_ordLeq)
```
```   567     apply (rule ordLess_ordLeq_trans)
```
```   568     apply (rule ordLess_ctwo_cexp)
```
```   569     apply (rule assms(2))
```
```   570     apply (rule cexp_mono1)
```
```   571     apply (rule assms(1))
```
```   572     apply (rule assms(2))
```
```   573   done
```
```   574 qed
```
```   575
```
```   576 lemma cinfinite_cexp: "\<lbrakk>ctwo \<le>o q; Cinfinite r\<rbrakk> \<Longrightarrow> cinfinite (q ^c r)"
```
```   577 by (metis assms cinfinite_mono ordLeq_cexp2)
```
```   578
```
```   579 lemma Cinfinite_cexp:
```
```   580   "\<lbrakk>ctwo \<le>o q; Cinfinite r\<rbrakk> \<Longrightarrow> Cinfinite (q ^c r)"
```
```   581 by (simp add: cinfinite_cexp Card_order_cexp)
```
```   582
```
```   583 lemma ctwo_ordLess_natLeq: "ctwo <o natLeq"
```
```   584 unfolding ctwo_def using finite_UNIV natLeq_cinfinite natLeq_Card_order
```
```   585 by (intro Cfinite_ordLess_Cinfinite) (auto simp: cfinite_def card_of_Card_order)
```
```   586
```
```   587 lemma ctwo_ordLess_Cinfinite: "Cinfinite r \<Longrightarrow> ctwo <o r"
```
```   588 by (metis ctwo_ordLess_natLeq natLeq_ordLeq_cinfinite ordLess_ordLeq_trans)
```
```   589
```
```   590 lemma ctwo_ordLeq_Cinfinite:
```
```   591   assumes "Cinfinite r"
```
```   592   shows "ctwo \<le>o r"
```
```   593 by (rule ordLess_imp_ordLeq[OF ctwo_ordLess_Cinfinite[OF assms]])
```
```   594
```
```   595 lemma Un_Cinfinite_bound: "\<lbrakk>|A| \<le>o r; |B| \<le>o r; Cinfinite r\<rbrakk> \<Longrightarrow> |A \<union> B| \<le>o r"
```
```   596 by (auto simp add: cinfinite_def card_of_Un_ordLeq_infinite_Field)
```
```   597
```
```   598 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"
```
```   599 by (auto simp add: card_of_UNION_ordLeq_infinite_Field cinfinite_def)
```
```   600
```
```   601 lemma csum_cinfinite_bound:
```
```   602   assumes "p \<le>o r" "q \<le>o r" "Card_order p" "Card_order q" "Cinfinite r"
```
```   603   shows "p +c q \<le>o r"
```
```   604 proof -
```
```   605   from assms(1-4) have "|Field p| \<le>o r" "|Field q| \<le>o r"
```
```   606     unfolding card_order_on_def using card_of_least ordLeq_transitive by blast+
```
```   607   with assms show ?thesis unfolding cinfinite_def csum_def
```
```   608     by (blast intro: card_of_Plus_ordLeq_infinite_Field)
```
```   609 qed
```
```   610
```
```   611 lemma cprod_cinfinite_bound:
```
```   612   assumes "p \<le>o r" "q \<le>o r" "Card_order p" "Card_order q" "Cinfinite r"
```
```   613   shows "p *c q \<le>o r"
```
```   614 proof -
```
```   615   from assms(1-4) have "|Field p| \<le>o r" "|Field q| \<le>o r"
```
```   616     unfolding card_order_on_def using card_of_least ordLeq_transitive by blast+
```
```   617   with assms show ?thesis unfolding cinfinite_def cprod_def
```
```   618     by (blast intro: card_of_Times_ordLeq_infinite_Field)
```
```   619 qed
```
```   620
```
```   621 lemma cprod_csum_cexp:
```
```   622   "r1 *c r2 \<le>o (r1 +c r2) ^c ctwo"
```
```   623 unfolding cprod_def csum_def cexp_def ctwo_def Field_card_of
```
```   624 proof -
```
```   625   let ?f = "\<lambda>(a, b). %x. if x then Inl a else Inr b"
```
```   626   have "inj_on ?f (Field r1 \<times> Field r2)" (is "inj_on _ ?LHS")
```
```   627     by (auto simp: inj_on_def fun_eq_iff split: bool.split)
```
```   628   moreover
```
```   629   have "?f ` ?LHS \<subseteq> Func (UNIV :: bool set) (Field r1 <+> Field r2)" (is "_ \<subseteq> ?RHS")
```
```   630     by (auto simp: Func_def)
```
```   631   ultimately show "|?LHS| \<le>o |?RHS|" using card_of_ordLeq by blast
```
```   632 qed
```
```   633
```
```   634 lemma Cfinite_cprod_Cinfinite: "\<lbrakk>Cfinite r; Cinfinite s\<rbrakk> \<Longrightarrow> r *c s \<le>o s"
```
```   635 by (intro cprod_cinfinite_bound)
```
```   636   (auto intro: ordLeq_refl ordLess_imp_ordLeq[OF Cfinite_ordLess_Cinfinite])
```
```   637
```
```   638 lemma cprod_cexp: "(r *c s) ^c t =o r ^c t *c s ^c t"
```
```   639   unfolding cprod_def cexp_def Field_card_of by (rule Func_Times_Range)
```
```   640
```
```   641 lemma cprod_cexp_csum_cexp_Cinfinite:
```
```   642   assumes t: "Cinfinite t"
```
```   643   shows "(r *c s) ^c t \<le>o (r +c s) ^c t"
```
```   644 proof -
```
```   645   have "(r *c s) ^c t \<le>o ((r +c s) ^c ctwo) ^c t"
```
```   646     by (rule cexp_mono1[OF cprod_csum_cexp conjunct2[OF t]])
```
```   647   also have "((r +c s) ^c ctwo) ^c t =o (r +c s) ^c (ctwo *c t)"
```
```   648     by (rule cexp_cprod[OF Card_order_csum])
```
```   649   also have "(r +c s) ^c (ctwo *c t) =o (r +c s) ^c (t *c ctwo)"
```
```   650     by (rule cexp_cong2[OF cprod_com Card_order_csum Card_order_cprod])
```
```   651   also have "(r +c s) ^c (t *c ctwo) =o ((r +c s) ^c t) ^c ctwo"
```
```   652     by (rule ordIso_symmetric[OF cexp_cprod[OF Card_order_csum]])
```
```   653   also have "((r +c s) ^c t) ^c ctwo =o (r +c s) ^c t"
```
```   654     by (rule cexp_cprod_ordLeq[OF Card_order_csum t ctwo_Cnotzero ctwo_ordLeq_Cinfinite[OF t]])
```
```   655   finally show ?thesis .
```
```   656 qed
```
```   657
```
```   658 lemma Cfinite_cexp_Cinfinite:
```
```   659   assumes s: "Cfinite s" and t: "Cinfinite t"
```
```   660   shows "s ^c t \<le>o ctwo ^c t"
```
```   661 proof (cases "s \<le>o ctwo")
```
```   662   case True thus ?thesis using t by (blast intro: cexp_mono1)
```
```   663 next
```
```   664   case False
```
```   665   hence "ctwo \<le>o s" by (metis card_order_on_well_order_on ctwo_Cnotzero ordLeq_total s)
```
```   666   hence "Cnotzero s" by (metis Cnotzero_mono ctwo_Cnotzero s)
```
```   667   hence st: "Cnotzero (s *c t)" by (metis Cinfinite_cprod2 cinfinite_not_czero t)
```
```   668   have "s ^c t \<le>o (ctwo ^c s) ^c t"
```
```   669     using assms by (blast intro: cexp_mono1 ordLess_imp_ordLeq[OF ordLess_ctwo_cexp])
```
```   670   also have "(ctwo ^c s) ^c t =o ctwo ^c (s *c t)"
```
```   671     by (blast intro: Card_order_ctwo cexp_cprod)
```
```   672   also have "ctwo ^c (s *c t) \<le>o ctwo ^c t"
```
```   673     using assms st by (intro cexp_mono2_Cnotzero Cfinite_cprod_Cinfinite Card_order_ctwo)
```
```   674   finally show ?thesis .
```
```   675 qed
```
```   676
```
```   677 lemma csum_Cfinite_cexp_Cinfinite:
```
```   678   assumes r: "Card_order r" and s: "Cfinite s" and t: "Cinfinite t"
```
```   679   shows "(r +c s) ^c t \<le>o (r +c ctwo) ^c t"
```
```   680 proof (cases "Cinfinite r")
```
```   681   case True
```
```   682   hence "r +c s =o r" by (intro csum_absorb1 ordLess_imp_ordLeq[OF Cfinite_ordLess_Cinfinite] s)
```
```   683   hence "(r +c s) ^c t =o r ^c t" using t by (blast intro: cexp_cong1)
```
```   684   also have "r ^c t \<le>o (r +c ctwo) ^c t" using t by (blast intro: cexp_mono1 ordLeq_csum1 r)
```
```   685   finally show ?thesis .
```
```   686 next
```
```   687   case False
```
```   688   with r have "Cfinite r" unfolding cinfinite_def cfinite_def by auto
```
```   689   hence "Cfinite (r +c s)" by (intro Cfinite_csum s)
```
```   690   hence "(r +c s) ^c t \<le>o ctwo ^c t" by (intro Cfinite_cexp_Cinfinite t)
```
```   691   also have "ctwo ^c t \<le>o (r +c ctwo) ^c t" using t
```
```   692     by (blast intro: cexp_mono1 ordLeq_csum2 Card_order_ctwo)
```
```   693   finally show ?thesis .
```
```   694 qed
```
```   695
```
```   696 (* cardSuc *)
```
```   697
```
```   698 lemma Cinfinite_cardSuc: "Cinfinite r \<Longrightarrow> Cinfinite (cardSuc r)"
```
```   699 by (simp add: cinfinite_def cardSuc_Card_order cardSuc_finite)
```
```   700
```
```   701 lemma cardSuc_UNION_Cinfinite:
```
```   702   assumes "Cinfinite r" "relChain (cardSuc r) As" "B \<le> (UN i : Field (cardSuc r). As i)" "|B| <=o r"
```
```   703   shows "EX i : Field (cardSuc r). B \<le> As i"
```
```   704 using cardSuc_UNION assms unfolding cinfinite_def by blast
```
```   705
```
```   706 end
```