src/HOL/Cardinals/Cardinal_Order_Relation_LFP.thy
author blanchet
Mon Nov 18 18:04:45 2013 +0100 (2013-11-18)
changeset 54475 b4d644be252c
parent 54473 8bee5ca99e63
permissions -rw-r--r--
moved theorems out of LFP
blanchet@54473
     1
(*  Title:      HOL/Cardinals/Cardinal_Order_Relation_LFP.thy
blanchet@48975
     2
    Author:     Andrei Popescu, TU Muenchen
blanchet@48975
     3
    Copyright   2012
blanchet@48975
     4
blanchet@54473
     5
Cardinal-order relations (LFP).
blanchet@48975
     6
*)
blanchet@48975
     7
blanchet@54473
     8
header {* Cardinal-Order Relations (LFP)  *}
blanchet@54473
     9
blanchet@54473
    10
theory Cardinal_Order_Relation_LFP
blanchet@54473
    11
imports Constructions_on_Wellorders_LFP
blanchet@48975
    12
begin
blanchet@48975
    13
blanchet@48975
    14
blanchet@48975
    15
text{* In this section, we define cardinal-order relations to be minim well-orders
blanchet@48975
    16
on their field.  Then we define the cardinal of a set to be {\em some} cardinal-order
blanchet@48975
    17
relation on that set, which will be unique up to order isomorphism.  Then we study
blanchet@48975
    18
the connection between cardinals and:
blanchet@48975
    19
\begin{itemize}
blanchet@48975
    20
\item standard set-theoretic constructions: products,
blanchet@48975
    21
sums, unions, lists, powersets, set-of finite sets operator;
blanchet@48975
    22
\item finiteness and infiniteness (in particular, with the numeric cardinal operator
blanchet@48975
    23
for finite sets, @{text "card"}, from the theory @{text "Finite_Sets.thy"}).
blanchet@48975
    24
\end{itemize}
blanchet@48975
    25
%
blanchet@48975
    26
On the way, we define the canonical $\omega$ cardinal and finite cardinals.  We also
blanchet@48975
    27
define (again, up to order isomorphism) the successor of a cardinal, and show that
blanchet@48975
    28
any cardinal admits a successor.
blanchet@48975
    29
blanchet@48975
    30
Main results of this section are the existence of cardinal relations and the
blanchet@48975
    31
facts that, in the presence of infiniteness,
blanchet@48975
    32
most of the standard set-theoretic constructions (except for the powerset)
blanchet@48975
    33
{\em do not increase cardinality}.  In particular, e.g., the set of words/lists over
blanchet@48975
    34
any infinite set has the same cardinality (hence, is in bijection) with that set.
blanchet@48975
    35
*}
blanchet@48975
    36
blanchet@48975
    37
blanchet@48975
    38
subsection {* Cardinal orders *}
blanchet@48975
    39
blanchet@48975
    40
blanchet@48975
    41
text{* A cardinal order in our setting shall be a well-order {\em minim} w.r.t. the
blanchet@48975
    42
order-embedding relation, @{text "\<le>o"} (which is the same as being {\em minimal} w.r.t. the
blanchet@48975
    43
strict order-embedding relation, @{text "<o"}), among all the well-orders on its field.  *}
blanchet@48975
    44
blanchet@48975
    45
definition card_order_on :: "'a set \<Rightarrow> 'a rel \<Rightarrow> bool"
blanchet@48975
    46
where
blanchet@48975
    47
"card_order_on A r \<equiv> well_order_on A r \<and> (\<forall>r'. well_order_on A r' \<longrightarrow> r \<le>o r')"
blanchet@48975
    48
blanchet@48975
    49
blanchet@48975
    50
abbreviation "Card_order r \<equiv> card_order_on (Field r) r"
blanchet@48975
    51
abbreviation "card_order r \<equiv> card_order_on UNIV r"
blanchet@48975
    52
blanchet@48975
    53
blanchet@48975
    54
lemma card_order_on_well_order_on:
blanchet@48975
    55
assumes "card_order_on A r"
blanchet@48975
    56
shows "well_order_on A r"
blanchet@48975
    57
using assms unfolding card_order_on_def by simp
blanchet@48975
    58
blanchet@48975
    59
blanchet@48975
    60
lemma card_order_on_Card_order:
blanchet@48975
    61
"card_order_on A r \<Longrightarrow> A = Field r \<and> Card_order r"
blanchet@48975
    62
unfolding card_order_on_def using rel.well_order_on_Field by blast
blanchet@48975
    63
blanchet@48975
    64
blanchet@48975
    65
text{* The existence of a cardinal relation on any given set (which will mean
blanchet@48975
    66
that any set has a cardinal) follows from two facts:
blanchet@48975
    67
\begin{itemize}
blanchet@48975
    68
\item Zermelo's theorem (proved in @{text "Zorn.thy"} as theorem @{text "well_order_on"}),
blanchet@48975
    69
which states that on any given set there exists a well-order;
blanchet@48975
    70
\item The well-founded-ness of @{text "<o"}, ensuring that then there exists a minimal
blanchet@48975
    71
such well-order, i.e., a cardinal order.
blanchet@48975
    72
\end{itemize}
blanchet@48975
    73
*}
blanchet@48975
    74
blanchet@48975
    75
blanchet@48975
    76
theorem card_order_on: "\<exists>r. card_order_on A r"
blanchet@48975
    77
proof-
blanchet@48975
    78
  obtain R where R_def: "R = {r. well_order_on A r}" by blast
blanchet@48975
    79
  have 1: "R \<noteq> {} \<and> (\<forall>r \<in> R. Well_order r)"
blanchet@48975
    80
  using well_order_on[of A] R_def rel.well_order_on_Well_order by blast
blanchet@48975
    81
  hence "\<exists>r \<in> R. \<forall>r' \<in> R. r \<le>o r'"
blanchet@48975
    82
  using  exists_minim_Well_order[of R] by auto
blanchet@48975
    83
  thus ?thesis using R_def unfolding card_order_on_def by auto
blanchet@48975
    84
qed
blanchet@48975
    85
blanchet@48975
    86
blanchet@48975
    87
lemma card_order_on_ordIso:
blanchet@48975
    88
assumes CO: "card_order_on A r" and CO': "card_order_on A r'"
blanchet@48975
    89
shows "r =o r'"
blanchet@48975
    90
using assms unfolding card_order_on_def
blanchet@48975
    91
using ordIso_iff_ordLeq by blast
blanchet@48975
    92
blanchet@48975
    93
blanchet@48975
    94
lemma Card_order_ordIso:
blanchet@48975
    95
assumes CO: "Card_order r" and ISO: "r' =o r"
blanchet@48975
    96
shows "Card_order r'"
blanchet@48975
    97
using ISO unfolding ordIso_def
blanchet@48975
    98
proof(unfold card_order_on_def, auto)
blanchet@48975
    99
  fix p' assume "well_order_on (Field r') p'"
blanchet@48975
   100
  hence 0: "Well_order p' \<and> Field p' = Field r'"
blanchet@48975
   101
  using rel.well_order_on_Well_order by blast
blanchet@48975
   102
  obtain f where 1: "iso r' r f" and 2: "Well_order r \<and> Well_order r'"
blanchet@48975
   103
  using ISO unfolding ordIso_def by auto
blanchet@48975
   104
  hence 3: "inj_on f (Field r') \<and> f ` (Field r') = Field r"
blanchet@48975
   105
  by (auto simp add: iso_iff embed_inj_on)
blanchet@48975
   106
  let ?p = "dir_image p' f"
blanchet@48975
   107
  have 4: "p' =o ?p \<and> Well_order ?p"
blanchet@48975
   108
  using 0 2 3 by (auto simp add: dir_image_ordIso Well_order_dir_image)
blanchet@48975
   109
  moreover have "Field ?p =  Field r"
blanchet@48975
   110
  using 0 3 by (auto simp add: dir_image_Field2 order_on_defs)
blanchet@48975
   111
  ultimately have "well_order_on (Field r) ?p" by auto
blanchet@48975
   112
  hence "r \<le>o ?p" using CO unfolding card_order_on_def by auto
blanchet@48975
   113
  thus "r' \<le>o p'"
blanchet@48975
   114
  using ISO 4 ordLeq_ordIso_trans ordIso_ordLeq_trans ordIso_symmetric by blast
blanchet@48975
   115
qed
blanchet@48975
   116
blanchet@48975
   117
blanchet@48975
   118
lemma Card_order_ordIso2:
blanchet@48975
   119
assumes CO: "Card_order r" and ISO: "r =o r'"
blanchet@48975
   120
shows "Card_order r'"
blanchet@48975
   121
using assms Card_order_ordIso ordIso_symmetric by blast
blanchet@48975
   122
blanchet@48975
   123
blanchet@48975
   124
subsection {* Cardinal of a set *}
blanchet@48975
   125
blanchet@48975
   126
blanchet@48975
   127
text{* We define the cardinal of set to be {\em some} cardinal order on that set.
blanchet@48975
   128
We shall prove that this notion is unique up to order isomorphism, meaning
blanchet@48975
   129
that order isomorphism shall be the true identity of cardinals.  *}
blanchet@48975
   130
blanchet@48975
   131
blanchet@48975
   132
definition card_of :: "'a set \<Rightarrow> 'a rel" ("|_|" )
blanchet@48975
   133
where "card_of A = (SOME r. card_order_on A r)"
blanchet@48975
   134
blanchet@48975
   135
blanchet@48975
   136
lemma card_of_card_order_on: "card_order_on A |A|"
blanchet@48975
   137
unfolding card_of_def by (auto simp add: card_order_on someI_ex)
blanchet@48975
   138
blanchet@48975
   139
blanchet@48975
   140
lemma card_of_well_order_on: "well_order_on A |A|"
blanchet@48975
   141
using card_of_card_order_on card_order_on_def by blast
blanchet@48975
   142
blanchet@48975
   143
blanchet@48975
   144
lemma Field_card_of: "Field |A| = A"
blanchet@48975
   145
using card_of_card_order_on[of A] unfolding card_order_on_def
blanchet@48975
   146
using rel.well_order_on_Field by blast
blanchet@48975
   147
blanchet@48975
   148
blanchet@48975
   149
lemma card_of_Card_order: "Card_order |A|"
blanchet@48975
   150
by (simp only: card_of_card_order_on Field_card_of)
blanchet@48975
   151
blanchet@48975
   152
blanchet@48975
   153
corollary ordIso_card_of_imp_Card_order:
blanchet@48975
   154
"r =o |A| \<Longrightarrow> Card_order r"
blanchet@48975
   155
using card_of_Card_order Card_order_ordIso by blast
blanchet@48975
   156
blanchet@48975
   157
blanchet@48975
   158
lemma card_of_Well_order: "Well_order |A|"
blanchet@54475
   159
using card_of_Card_order unfolding card_order_on_def by auto
blanchet@48975
   160
blanchet@48975
   161
blanchet@48975
   162
lemma card_of_refl: "|A| =o |A|"
blanchet@48975
   163
using card_of_Well_order ordIso_reflexive by blast
blanchet@48975
   164
blanchet@48975
   165
blanchet@48975
   166
lemma card_of_least: "well_order_on A r \<Longrightarrow> |A| \<le>o r"
blanchet@48975
   167
using card_of_card_order_on unfolding card_order_on_def by blast
blanchet@48975
   168
blanchet@48975
   169
blanchet@48975
   170
lemma card_of_ordIso:
blanchet@48975
   171
"(\<exists>f. bij_betw f A B) = ( |A| =o |B| )"
blanchet@48975
   172
proof(auto)
blanchet@48975
   173
  fix f assume *: "bij_betw f A B"
blanchet@48975
   174
  then obtain r where "well_order_on B r \<and> |A| =o r"
blanchet@48975
   175
  using Well_order_iso_copy card_of_well_order_on by blast
blanchet@48975
   176
  hence "|B| \<le>o |A|" using card_of_least
blanchet@48975
   177
  ordLeq_ordIso_trans ordIso_symmetric by blast
blanchet@48975
   178
  moreover
blanchet@48975
   179
  {let ?g = "inv_into A f"
blanchet@48975
   180
   have "bij_betw ?g B A" using * bij_betw_inv_into by blast
blanchet@48975
   181
   then obtain r where "well_order_on A r \<and> |B| =o r"
blanchet@48975
   182
   using Well_order_iso_copy card_of_well_order_on by blast
blanchet@48975
   183
   hence "|A| \<le>o |B|" using card_of_least
blanchet@48975
   184
   ordLeq_ordIso_trans ordIso_symmetric by blast
blanchet@48975
   185
  }
blanchet@48975
   186
  ultimately show "|A| =o |B|" using ordIso_iff_ordLeq by blast
blanchet@48975
   187
next
blanchet@48975
   188
  assume "|A| =o |B|"
blanchet@48975
   189
  then obtain f where "iso ( |A| ) ( |B| ) f"
blanchet@48975
   190
  unfolding ordIso_def by auto
blanchet@48975
   191
  hence "bij_betw f A B" unfolding iso_def Field_card_of by simp
blanchet@48975
   192
  thus "\<exists>f. bij_betw f A B" by auto
blanchet@48975
   193
qed
blanchet@48975
   194
blanchet@48975
   195
blanchet@48975
   196
lemma card_of_ordLeq:
blanchet@48975
   197
"(\<exists>f. inj_on f A \<and> f ` A \<le> B) = ( |A| \<le>o |B| )"
blanchet@48975
   198
proof(auto)
blanchet@48975
   199
  fix f assume *: "inj_on f A" and **: "f ` A \<le> B"
blanchet@48975
   200
  {assume "|B| <o |A|"
blanchet@48975
   201
   hence "|B| \<le>o |A|" using ordLeq_iff_ordLess_or_ordIso by blast
blanchet@48975
   202
   then obtain g where "embed ( |B| ) ( |A| ) g"
blanchet@48975
   203
   unfolding ordLeq_def by auto
blanchet@48975
   204
   hence 1: "inj_on g B \<and> g ` B \<le> A" using embed_inj_on[of "|B|" "|A|" "g"]
blanchet@48975
   205
   card_of_Well_order[of "B"] Field_card_of[of "B"] Field_card_of[of "A"]
blanchet@48975
   206
   embed_Field[of "|B|" "|A|" g] by auto
blanchet@48975
   207
   obtain h where "bij_betw h A B"
blanchet@48975
   208
   using * ** 1 Cantor_Bernstein[of f] by fastforce
blanchet@48975
   209
   hence "|A| =o |B|" using card_of_ordIso by blast
blanchet@48975
   210
   hence "|A| \<le>o |B|" using ordIso_iff_ordLeq by auto
blanchet@48975
   211
  }
blanchet@48975
   212
  thus "|A| \<le>o |B|" using ordLess_or_ordLeq[of "|B|" "|A|"]
blanchet@48975
   213
  by (auto simp: card_of_Well_order)
blanchet@48975
   214
next
blanchet@48975
   215
  assume *: "|A| \<le>o |B|"
blanchet@48975
   216
  obtain f where "embed ( |A| ) ( |B| ) f"
blanchet@48975
   217
  using * unfolding ordLeq_def by auto
blanchet@48975
   218
  hence "inj_on f A \<and> f ` A \<le> B" using embed_inj_on[of "|A|" "|B|" f]
blanchet@48975
   219
  card_of_Well_order[of "A"] Field_card_of[of "A"] Field_card_of[of "B"]
blanchet@48975
   220
  embed_Field[of "|A|" "|B|" f] by auto
blanchet@48975
   221
  thus "\<exists>f. inj_on f A \<and> f ` A \<le> B" by auto
blanchet@48975
   222
qed
blanchet@48975
   223
blanchet@48975
   224
blanchet@48975
   225
lemma card_of_ordLeq2:
blanchet@48975
   226
"A \<noteq> {} \<Longrightarrow> (\<exists>g. g ` B = A) = ( |A| \<le>o |B| )"
blanchet@48975
   227
using card_of_ordLeq[of A B] inj_on_iff_surj[of A B] by auto
blanchet@48975
   228
blanchet@48975
   229
blanchet@48975
   230
lemma card_of_ordLess:
blanchet@48975
   231
"(\<not>(\<exists>f. inj_on f A \<and> f ` A \<le> B)) = ( |B| <o |A| )"
blanchet@48975
   232
proof-
blanchet@48975
   233
  have "(\<not>(\<exists>f. inj_on f A \<and> f ` A \<le> B)) = (\<not> |A| \<le>o |B| )"
blanchet@48975
   234
  using card_of_ordLeq by blast
blanchet@48975
   235
  also have "\<dots> = ( |B| <o |A| )"
blanchet@48975
   236
  using card_of_Well_order[of A] card_of_Well_order[of B]
blanchet@48975
   237
        not_ordLeq_iff_ordLess by blast
blanchet@48975
   238
  finally show ?thesis .
blanchet@48975
   239
qed
blanchet@48975
   240
blanchet@48975
   241
blanchet@48975
   242
lemma card_of_ordLess2:
blanchet@48975
   243
"B \<noteq> {} \<Longrightarrow> (\<not>(\<exists>f. f ` A = B)) = ( |A| <o |B| )"
blanchet@48975
   244
using card_of_ordLess[of B A] inj_on_iff_surj[of B A] by auto
blanchet@48975
   245
blanchet@48975
   246
blanchet@48975
   247
lemma card_of_ordIsoI:
blanchet@48975
   248
assumes "bij_betw f A B"
blanchet@48975
   249
shows "|A| =o |B|"
blanchet@48975
   250
using assms unfolding card_of_ordIso[symmetric] by auto
blanchet@48975
   251
blanchet@48975
   252
blanchet@48975
   253
lemma card_of_ordLeqI:
blanchet@48975
   254
assumes "inj_on f A" and "\<And> a. a \<in> A \<Longrightarrow> f a \<in> B"
blanchet@48975
   255
shows "|A| \<le>o |B|"
blanchet@48975
   256
using assms unfolding card_of_ordLeq[symmetric] by auto
blanchet@48975
   257
blanchet@48975
   258
blanchet@48975
   259
lemma card_of_unique:
blanchet@48975
   260
"card_order_on A r \<Longrightarrow> r =o |A|"
blanchet@48975
   261
by (simp only: card_order_on_ordIso card_of_card_order_on)
blanchet@48975
   262
blanchet@48975
   263
blanchet@48975
   264
lemma card_of_mono1:
blanchet@48975
   265
"A \<le> B \<Longrightarrow> |A| \<le>o |B|"
blanchet@48975
   266
using inj_on_id[of A] card_of_ordLeq[of A B] by fastforce
blanchet@48975
   267
blanchet@48975
   268
blanchet@48975
   269
lemma card_of_mono2:
blanchet@48975
   270
assumes "r \<le>o r'"
blanchet@48975
   271
shows "|Field r| \<le>o |Field r'|"
blanchet@48975
   272
proof-
blanchet@48975
   273
  obtain f where
blanchet@48975
   274
  1: "well_order_on (Field r) r \<and> well_order_on (Field r) r \<and> embed r r' f"
blanchet@48975
   275
  using assms unfolding ordLeq_def
blanchet@48975
   276
  by (auto simp add: rel.well_order_on_Well_order)
blanchet@48975
   277
  hence "inj_on f (Field r) \<and> f ` (Field r) \<le> Field r'"
blanchet@48975
   278
  by (auto simp add: embed_inj_on embed_Field)
blanchet@48975
   279
  thus "|Field r| \<le>o |Field r'|" using card_of_ordLeq by blast
blanchet@48975
   280
qed
blanchet@48975
   281
blanchet@48975
   282
blanchet@48975
   283
lemma card_of_cong: "r =o r' \<Longrightarrow> |Field r| =o |Field r'|"
blanchet@48975
   284
by (simp add: ordIso_iff_ordLeq card_of_mono2)
blanchet@48975
   285
blanchet@48975
   286
blanchet@48975
   287
lemma card_of_Field_ordLess: "Well_order r \<Longrightarrow> |Field r| \<le>o r"
blanchet@48975
   288
using card_of_least card_of_well_order_on rel.well_order_on_Well_order by blast
blanchet@48975
   289
blanchet@48975
   290
blanchet@48975
   291
lemma card_of_Field_ordIso:
blanchet@48975
   292
assumes "Card_order r"
blanchet@48975
   293
shows "|Field r| =o r"
blanchet@48975
   294
proof-
blanchet@48975
   295
  have "card_order_on (Field r) r"
blanchet@48975
   296
  using assms card_order_on_Card_order by blast
blanchet@48975
   297
  moreover have "card_order_on (Field r) |Field r|"
blanchet@48975
   298
  using card_of_card_order_on by blast
blanchet@48975
   299
  ultimately show ?thesis using card_order_on_ordIso by blast
blanchet@48975
   300
qed
blanchet@48975
   301
blanchet@48975
   302
blanchet@48975
   303
lemma Card_order_iff_ordIso_card_of:
blanchet@48975
   304
"Card_order r = (r =o |Field r| )"
blanchet@48975
   305
using ordIso_card_of_imp_Card_order card_of_Field_ordIso ordIso_symmetric by blast
blanchet@48975
   306
blanchet@48975
   307
blanchet@48975
   308
lemma Card_order_iff_ordLeq_card_of:
blanchet@48975
   309
"Card_order r = (r \<le>o |Field r| )"
blanchet@48975
   310
proof-
blanchet@48975
   311
  have "Card_order r = (r =o |Field r| )"
blanchet@48975
   312
  unfolding Card_order_iff_ordIso_card_of by simp
blanchet@48975
   313
  also have "... = (r \<le>o |Field r| \<and> |Field r| \<le>o r)"
blanchet@48975
   314
  unfolding ordIso_iff_ordLeq by simp
blanchet@48975
   315
  also have "... = (r \<le>o |Field r| )"
blanchet@48975
   316
  using card_of_Field_ordLess
blanchet@48975
   317
  by (auto simp: card_of_Field_ordLess ordLeq_Well_order_simp)
blanchet@48975
   318
  finally show ?thesis .
blanchet@48975
   319
qed
blanchet@48975
   320
blanchet@48975
   321
blanchet@48975
   322
lemma Card_order_iff_Restr_underS:
blanchet@48975
   323
assumes "Well_order r"
blanchet@48975
   324
shows "Card_order r = (\<forall>a \<in> Field r. Restr r (rel.underS r a) <o |Field r| )"
blanchet@48975
   325
using assms unfolding Card_order_iff_ordLeq_card_of
blanchet@48975
   326
using ordLeq_iff_ordLess_Restr card_of_Well_order by blast
blanchet@48975
   327
blanchet@48975
   328
blanchet@48975
   329
lemma card_of_underS:
blanchet@48975
   330
assumes r: "Card_order r" and a: "a : Field r"
blanchet@48975
   331
shows "|rel.underS r a| <o r"
blanchet@48975
   332
proof-
blanchet@48975
   333
  let ?A = "rel.underS r a"  let ?r' = "Restr r ?A"
blanchet@48975
   334
  have 1: "Well_order r"
blanchet@48975
   335
  using r unfolding card_order_on_def by simp
blanchet@48975
   336
  have "Well_order ?r'" using 1 Well_order_Restr by auto
blanchet@48975
   337
  moreover have "card_order_on (Field ?r') |Field ?r'|"
blanchet@48975
   338
  using card_of_card_order_on .
blanchet@48975
   339
  ultimately have "|Field ?r'| \<le>o ?r'"
blanchet@48975
   340
  unfolding card_order_on_def by simp
blanchet@48975
   341
  moreover have "Field ?r' = ?A"
blanchet@48975
   342
  using 1 wo_rel.underS_ofilter Field_Restr_ofilter
blanchet@48975
   343
  unfolding wo_rel_def by fastforce
blanchet@48975
   344
  ultimately have "|?A| \<le>o ?r'" by simp
blanchet@48975
   345
  also have "?r' <o |Field r|"
blanchet@48975
   346
  using 1 a r Card_order_iff_Restr_underS by blast
blanchet@48975
   347
  also have "|Field r| =o r"
blanchet@48975
   348
  using r ordIso_symmetric unfolding Card_order_iff_ordIso_card_of by auto
blanchet@48975
   349
  finally show ?thesis .
blanchet@48975
   350
qed
blanchet@48975
   351
blanchet@48975
   352
blanchet@48975
   353
lemma ordLess_Field:
blanchet@48975
   354
assumes "r <o r'"
blanchet@48975
   355
shows "|Field r| <o r'"
blanchet@48975
   356
proof-
blanchet@48975
   357
  have "well_order_on (Field r) r" using assms unfolding ordLess_def
blanchet@48975
   358
  by (auto simp add: rel.well_order_on_Well_order)
blanchet@48975
   359
  hence "|Field r| \<le>o r" using card_of_least by blast
blanchet@48975
   360
  thus ?thesis using assms ordLeq_ordLess_trans by blast
blanchet@48975
   361
qed
blanchet@48975
   362
blanchet@48975
   363
blanchet@48975
   364
lemma internalize_card_of_ordLeq:
blanchet@48975
   365
"( |A| \<le>o r) = (\<exists>B \<le> Field r. |A| =o |B| \<and> |B| \<le>o r)"
blanchet@48975
   366
proof
blanchet@48975
   367
  assume "|A| \<le>o r"
blanchet@48975
   368
  then obtain p where 1: "Field p \<le> Field r \<and> |A| =o p \<and> p \<le>o r"
blanchet@48975
   369
  using internalize_ordLeq[of "|A|" r] by blast
blanchet@48975
   370
  hence "Card_order p" using card_of_Card_order Card_order_ordIso2 by blast
blanchet@48975
   371
  hence "|Field p| =o p" using card_of_Field_ordIso by blast
blanchet@48975
   372
  hence "|A| =o |Field p| \<and> |Field p| \<le>o r"
blanchet@48975
   373
  using 1 ordIso_equivalence ordIso_ordLeq_trans by blast
blanchet@48975
   374
  thus "\<exists>B \<le> Field r. |A| =o |B| \<and> |B| \<le>o r" using 1 by blast
blanchet@48975
   375
next
blanchet@48975
   376
  assume "\<exists>B \<le> Field r. |A| =o |B| \<and> |B| \<le>o r"
blanchet@48975
   377
  thus "|A| \<le>o r" using ordIso_ordLeq_trans by blast
blanchet@48975
   378
qed
blanchet@48975
   379
blanchet@48975
   380
blanchet@48975
   381
lemma internalize_card_of_ordLeq2:
blanchet@48975
   382
"( |A| \<le>o |C| ) = (\<exists>B \<le> C. |A| =o |B| \<and> |B| \<le>o |C| )"
blanchet@48975
   383
using internalize_card_of_ordLeq[of "A" "|C|"] Field_card_of[of C] by auto
blanchet@48975
   384
blanchet@48975
   385
blanchet@48975
   386
blanchet@48975
   387
subsection {* Cardinals versus set operations on arbitrary sets *}
blanchet@48975
   388
blanchet@48975
   389
blanchet@48975
   390
text{* Here we embark in a long journey of simple results showing
blanchet@48975
   391
that the standard set-theoretic operations are well-behaved w.r.t. the notion of
blanchet@48975
   392
cardinal -- essentially, this means that they preserve the ``cardinal identity"
blanchet@48975
   393
@{text "=o"} and are monotonic w.r.t. @{text "\<le>o"}.
blanchet@48975
   394
*}
blanchet@48975
   395
blanchet@48975
   396
blanchet@48975
   397
lemma card_of_empty: "|{}| \<le>o |A|"
blanchet@48975
   398
using card_of_ordLeq inj_on_id by blast
blanchet@48975
   399
blanchet@48975
   400
blanchet@48975
   401
lemma card_of_empty1:
blanchet@48975
   402
assumes "Well_order r \<or> Card_order r"
blanchet@48975
   403
shows "|{}| \<le>o r"
blanchet@48975
   404
proof-
blanchet@48975
   405
  have "Well_order r" using assms unfolding card_order_on_def by auto
blanchet@48975
   406
  hence "|Field r| <=o r"
blanchet@48975
   407
  using assms card_of_Field_ordLess by blast
blanchet@48975
   408
  moreover have "|{}| \<le>o |Field r|" by (simp add: card_of_empty)
blanchet@48975
   409
  ultimately show ?thesis using ordLeq_transitive by blast
blanchet@48975
   410
qed
blanchet@48975
   411
blanchet@48975
   412
blanchet@48975
   413
corollary Card_order_empty:
blanchet@48975
   414
"Card_order r \<Longrightarrow> |{}| \<le>o r" by (simp add: card_of_empty1)
blanchet@48975
   415
blanchet@48975
   416
blanchet@48975
   417
lemma card_of_empty2:
blanchet@48975
   418
assumes LEQ: "|A| =o |{}|"
blanchet@48975
   419
shows "A = {}"
blanchet@48975
   420
using assms card_of_ordIso[of A] bij_betw_empty2 by blast
blanchet@48975
   421
blanchet@48975
   422
blanchet@48975
   423
lemma card_of_empty3:
blanchet@48975
   424
assumes LEQ: "|A| \<le>o |{}|"
blanchet@48975
   425
shows "A = {}"
blanchet@48975
   426
using assms
blanchet@48975
   427
by (simp add: ordIso_iff_ordLeq card_of_empty1 card_of_empty2
blanchet@48975
   428
              ordLeq_Well_order_simp)
blanchet@48975
   429
blanchet@48975
   430
blanchet@48975
   431
lemma card_of_empty_ordIso:
blanchet@48975
   432
"|{}::'a set| =o |{}::'b set|"
blanchet@48975
   433
using card_of_ordIso unfolding bij_betw_def inj_on_def by blast
blanchet@48975
   434
blanchet@48975
   435
blanchet@48975
   436
lemma card_of_image:
blanchet@48975
   437
"|f ` A| <=o |A|"
blanchet@48975
   438
proof(cases "A = {}", simp add: card_of_empty)
blanchet@48975
   439
  assume "A ~= {}"
blanchet@48975
   440
  hence "f ` A ~= {}" by auto
blanchet@48975
   441
  thus "|f ` A| \<le>o |A|"
blanchet@48975
   442
  using card_of_ordLeq2[of "f ` A" A] by auto
blanchet@48975
   443
qed
blanchet@48975
   444
blanchet@48975
   445
blanchet@48975
   446
lemma surj_imp_ordLeq:
blanchet@48975
   447
assumes "B <= f ` A"
blanchet@48975
   448
shows "|B| <=o |A|"
blanchet@48975
   449
proof-
blanchet@48975
   450
  have "|B| <=o |f ` A|" using assms card_of_mono1 by auto
blanchet@48975
   451
  thus ?thesis using card_of_image ordLeq_transitive by blast
blanchet@48975
   452
qed
blanchet@48975
   453
blanchet@48975
   454
blanchet@48975
   455
lemma card_of_ordLeqI2:
blanchet@48975
   456
assumes "B \<subseteq> f ` A"
blanchet@48975
   457
shows "|B| \<le>o |A|"
blanchet@48975
   458
using assms by (metis surj_imp_ordLeq)
blanchet@48975
   459
blanchet@48975
   460
blanchet@48975
   461
lemma card_of_singl_ordLeq:
blanchet@48975
   462
assumes "A \<noteq> {}"
blanchet@48975
   463
shows "|{b}| \<le>o |A|"
blanchet@48975
   464
proof-
blanchet@48975
   465
  obtain a where *: "a \<in> A" using assms by auto
blanchet@48975
   466
  let ?h = "\<lambda> b'::'b. if b' = b then a else undefined"
blanchet@48975
   467
  have "inj_on ?h {b} \<and> ?h ` {b} \<le> A"
blanchet@48975
   468
  using * unfolding inj_on_def by auto
blanchet@48975
   469
  thus ?thesis using card_of_ordLeq by blast
blanchet@48975
   470
qed
blanchet@48975
   471
blanchet@48975
   472
blanchet@48975
   473
corollary Card_order_singl_ordLeq:
blanchet@48975
   474
"\<lbrakk>Card_order r; Field r \<noteq> {}\<rbrakk> \<Longrightarrow> |{b}| \<le>o r"
blanchet@48975
   475
using card_of_singl_ordLeq[of "Field r" b]
blanchet@48975
   476
      card_of_Field_ordIso[of r] ordLeq_ordIso_trans by blast
blanchet@48975
   477
blanchet@48975
   478
blanchet@48975
   479
lemma card_of_Pow: "|A| <o |Pow A|"
blanchet@48975
   480
using card_of_ordLess2[of "Pow A" A]  Cantors_paradox[of A]
blanchet@48975
   481
      Pow_not_empty[of A] by auto
blanchet@48975
   482
blanchet@48975
   483
blanchet@48975
   484
corollary Card_order_Pow:
blanchet@48975
   485
"Card_order r \<Longrightarrow> r <o |Pow(Field r)|"
blanchet@48975
   486
using card_of_Pow card_of_Field_ordIso ordIso_ordLess_trans ordIso_symmetric by blast
blanchet@48975
   487
blanchet@48975
   488
blanchet@48975
   489
lemma card_of_Plus1: "|A| \<le>o |A <+> B|"
blanchet@48975
   490
proof-
blanchet@48975
   491
  have "Inl ` A \<le> A <+> B" by auto
blanchet@48975
   492
  thus ?thesis using inj_Inl[of A] card_of_ordLeq by blast
blanchet@48975
   493
qed
blanchet@48975
   494
blanchet@48975
   495
blanchet@48975
   496
corollary Card_order_Plus1:
blanchet@48975
   497
"Card_order r \<Longrightarrow> r \<le>o |(Field r) <+> B|"
blanchet@48975
   498
using card_of_Plus1 card_of_Field_ordIso ordIso_ordLeq_trans ordIso_symmetric by blast
blanchet@48975
   499
blanchet@48975
   500
blanchet@48975
   501
lemma card_of_Plus2: "|B| \<le>o |A <+> B|"
blanchet@48975
   502
proof-
blanchet@48975
   503
  have "Inr ` B \<le> A <+> B" by auto
blanchet@48975
   504
  thus ?thesis using inj_Inr[of B] card_of_ordLeq by blast
blanchet@48975
   505
qed
blanchet@48975
   506
blanchet@48975
   507
blanchet@48975
   508
corollary Card_order_Plus2:
blanchet@48975
   509
"Card_order r \<Longrightarrow> r \<le>o |A <+> (Field r)|"
blanchet@48975
   510
using card_of_Plus2 card_of_Field_ordIso ordIso_ordLeq_trans ordIso_symmetric by blast
blanchet@48975
   511
blanchet@48975
   512
blanchet@48975
   513
lemma card_of_Plus_empty1: "|A| =o |A <+> {}|"
blanchet@48975
   514
proof-
blanchet@48975
   515
  have "bij_betw Inl A (A <+> {})" unfolding bij_betw_def inj_on_def by auto
blanchet@48975
   516
  thus ?thesis using card_of_ordIso by auto
blanchet@48975
   517
qed
blanchet@48975
   518
blanchet@48975
   519
blanchet@48975
   520
lemma card_of_Plus_empty2: "|A| =o |{} <+> A|"
blanchet@48975
   521
proof-
blanchet@48975
   522
  have "bij_betw Inr A ({} <+> A)" unfolding bij_betw_def inj_on_def by auto
blanchet@48975
   523
  thus ?thesis using card_of_ordIso by auto
blanchet@48975
   524
qed
blanchet@48975
   525
blanchet@48975
   526
blanchet@48975
   527
lemma card_of_Plus_commute: "|A <+> B| =o |B <+> A|"
blanchet@48975
   528
proof-
blanchet@48975
   529
  let ?f = "\<lambda>(c::'a + 'b). case c of Inl a \<Rightarrow> Inr a
blanchet@48975
   530
                                   | Inr b \<Rightarrow> Inl b"
blanchet@48975
   531
  have "bij_betw ?f (A <+> B) (B <+> A)"
blanchet@48975
   532
  unfolding bij_betw_def inj_on_def by force
blanchet@48975
   533
  thus ?thesis using card_of_ordIso by blast
blanchet@48975
   534
qed
blanchet@48975
   535
blanchet@48975
   536
blanchet@48975
   537
lemma card_of_Plus_assoc:
blanchet@48975
   538
fixes A :: "'a set" and B :: "'b set" and C :: "'c set"
blanchet@48975
   539
shows "|(A <+> B) <+> C| =o |A <+> B <+> C|"
blanchet@48975
   540
proof -
blanchet@48975
   541
  def f \<equiv> "\<lambda>(k::('a + 'b) + 'c).
blanchet@48975
   542
  case k of Inl ab \<Rightarrow> (case ab of Inl a \<Rightarrow> Inl a
blanchet@48975
   543
                                 |Inr b \<Rightarrow> Inr (Inl b))
blanchet@48975
   544
           |Inr c \<Rightarrow> Inr (Inr c)"
blanchet@48975
   545
  have "A <+> B <+> C \<subseteq> f ` ((A <+> B) <+> C)"
blanchet@48975
   546
  proof
blanchet@48975
   547
    fix x assume x: "x \<in> A <+> B <+> C"
blanchet@48975
   548
    show "x \<in> f ` ((A <+> B) <+> C)"
blanchet@48975
   549
    proof(cases x)
blanchet@48975
   550
      case (Inl a)
blanchet@48975
   551
      hence "a \<in> A" "x = f (Inl (Inl a))"
blanchet@48975
   552
      using x unfolding f_def by auto
blanchet@48975
   553
      thus ?thesis by auto
blanchet@48975
   554
    next
blanchet@48975
   555
      case (Inr bc) note 1 = Inr show ?thesis
blanchet@48975
   556
      proof(cases bc)
blanchet@48975
   557
        case (Inl b)
blanchet@48975
   558
        hence "b \<in> B" "x = f (Inl (Inr b))"
blanchet@48975
   559
        using x 1 unfolding f_def by auto
blanchet@48975
   560
        thus ?thesis by auto
blanchet@48975
   561
      next
blanchet@48975
   562
        case (Inr c)
blanchet@48975
   563
        hence "c \<in> C" "x = f (Inr c)"
blanchet@48975
   564
        using x 1 unfolding f_def by auto
blanchet@48975
   565
        thus ?thesis by auto
blanchet@48975
   566
      qed
blanchet@48975
   567
    qed
blanchet@48975
   568
  qed
blanchet@48975
   569
  hence "bij_betw f ((A <+> B) <+> C) (A <+> B <+> C)"
traytel@51764
   570
  unfolding bij_betw_def inj_on_def f_def by force
blanchet@48975
   571
  thus ?thesis using card_of_ordIso by blast
blanchet@48975
   572
qed
blanchet@48975
   573
blanchet@48975
   574
blanchet@48975
   575
lemma card_of_Plus_mono1:
blanchet@48975
   576
assumes "|A| \<le>o |B|"
blanchet@48975
   577
shows "|A <+> C| \<le>o |B <+> C|"
blanchet@48975
   578
proof-
blanchet@48975
   579
  obtain f where 1: "inj_on f A \<and> f ` A \<le> B"
blanchet@48975
   580
  using assms card_of_ordLeq[of A] by fastforce
blanchet@48975
   581
  obtain g where g_def:
blanchet@48975
   582
  "g = (\<lambda>d. case d of Inl a \<Rightarrow> Inl(f a) | Inr (c::'c) \<Rightarrow> Inr c)" by blast
blanchet@48975
   583
  have "inj_on g (A <+> C) \<and> g ` (A <+> C) \<le> (B <+> C)"
blanchet@48975
   584
  proof-
blanchet@48975
   585
    {fix d1 and d2 assume "d1 \<in> A <+> C \<and> d2 \<in> A <+> C" and
blanchet@48975
   586
                          "g d1 = g d2"
blanchet@48975
   587
     hence "d1 = d2" using 1 unfolding inj_on_def
blanchet@48975
   588
     by(case_tac d1, case_tac d2, auto simp add: g_def)
blanchet@48975
   589
    }
blanchet@48975
   590
    moreover
blanchet@48975
   591
    {fix d assume "d \<in> A <+> C"
blanchet@48975
   592
     hence "g d \<in> B <+> C"  using 1
blanchet@48975
   593
     by(case_tac d, auto simp add: g_def)
blanchet@48975
   594
    }
blanchet@48975
   595
    ultimately show ?thesis unfolding inj_on_def by auto
blanchet@48975
   596
  qed
blanchet@48975
   597
  thus ?thesis using card_of_ordLeq by metis
blanchet@48975
   598
qed
blanchet@48975
   599
blanchet@48975
   600
blanchet@48975
   601
corollary ordLeq_Plus_mono1:
blanchet@48975
   602
assumes "r \<le>o r'"
blanchet@48975
   603
shows "|(Field r) <+> C| \<le>o |(Field r') <+> C|"
blanchet@48975
   604
using assms card_of_mono2 card_of_Plus_mono1 by blast
blanchet@48975
   605
blanchet@48975
   606
blanchet@48975
   607
lemma card_of_Plus_mono2:
blanchet@48975
   608
assumes "|A| \<le>o |B|"
blanchet@48975
   609
shows "|C <+> A| \<le>o |C <+> B|"
blanchet@48975
   610
using assms card_of_Plus_mono1[of A B C]
blanchet@48975
   611
      card_of_Plus_commute[of C A]  card_of_Plus_commute[of B C]
blanchet@48975
   612
      ordIso_ordLeq_trans[of "|C <+> A|"] ordLeq_ordIso_trans[of "|C <+> A|"]
blanchet@48975
   613
by blast
blanchet@48975
   614
blanchet@48975
   615
blanchet@48975
   616
corollary ordLeq_Plus_mono2:
blanchet@48975
   617
assumes "r \<le>o r'"
blanchet@48975
   618
shows "|A <+> (Field r)| \<le>o |A <+> (Field r')|"
blanchet@48975
   619
using assms card_of_mono2 card_of_Plus_mono2 by blast
blanchet@48975
   620
blanchet@48975
   621
blanchet@48975
   622
lemma card_of_Plus_mono:
blanchet@48975
   623
assumes "|A| \<le>o |B|" and "|C| \<le>o |D|"
blanchet@48975
   624
shows "|A <+> C| \<le>o |B <+> D|"
blanchet@48975
   625
using assms card_of_Plus_mono1[of A B C] card_of_Plus_mono2[of C D B]
blanchet@48975
   626
      ordLeq_transitive[of "|A <+> C|"] by blast
blanchet@48975
   627
blanchet@48975
   628
blanchet@48975
   629
corollary ordLeq_Plus_mono:
blanchet@48975
   630
assumes "r \<le>o r'" and "p \<le>o p'"
blanchet@48975
   631
shows "|(Field r) <+> (Field p)| \<le>o |(Field r') <+> (Field p')|"
blanchet@48975
   632
using assms card_of_mono2[of r r'] card_of_mono2[of p p'] card_of_Plus_mono by blast
blanchet@48975
   633
blanchet@48975
   634
blanchet@48975
   635
lemma card_of_Plus_cong1:
blanchet@48975
   636
assumes "|A| =o |B|"
blanchet@48975
   637
shows "|A <+> C| =o |B <+> C|"
blanchet@48975
   638
using assms by (simp add: ordIso_iff_ordLeq card_of_Plus_mono1)
blanchet@48975
   639
blanchet@48975
   640
blanchet@48975
   641
corollary ordIso_Plus_cong1:
blanchet@48975
   642
assumes "r =o r'"
blanchet@48975
   643
shows "|(Field r) <+> C| =o |(Field r') <+> C|"
blanchet@48975
   644
using assms card_of_cong card_of_Plus_cong1 by blast
blanchet@48975
   645
blanchet@48975
   646
blanchet@48975
   647
lemma card_of_Plus_cong2:
blanchet@48975
   648
assumes "|A| =o |B|"
blanchet@48975
   649
shows "|C <+> A| =o |C <+> B|"
blanchet@48975
   650
using assms by (simp add: ordIso_iff_ordLeq card_of_Plus_mono2)
blanchet@48975
   651
blanchet@48975
   652
blanchet@48975
   653
corollary ordIso_Plus_cong2:
blanchet@48975
   654
assumes "r =o r'"
blanchet@48975
   655
shows "|A <+> (Field r)| =o |A <+> (Field r')|"
blanchet@48975
   656
using assms card_of_cong card_of_Plus_cong2 by blast
blanchet@48975
   657
blanchet@48975
   658
blanchet@48975
   659
lemma card_of_Plus_cong:
blanchet@48975
   660
assumes "|A| =o |B|" and "|C| =o |D|"
blanchet@48975
   661
shows "|A <+> C| =o |B <+> D|"
blanchet@48975
   662
using assms by (simp add: ordIso_iff_ordLeq card_of_Plus_mono)
blanchet@48975
   663
blanchet@48975
   664
blanchet@48975
   665
corollary ordIso_Plus_cong:
blanchet@48975
   666
assumes "r =o r'" and "p =o p'"
blanchet@48975
   667
shows "|(Field r) <+> (Field p)| =o |(Field r') <+> (Field p')|"
blanchet@48975
   668
using assms card_of_cong[of r r'] card_of_cong[of p p'] card_of_Plus_cong by blast
blanchet@48975
   669
blanchet@48975
   670
blanchet@48975
   671
lemma card_of_Un_Plus_ordLeq:
blanchet@48975
   672
"|A \<union> B| \<le>o |A <+> B|"
blanchet@48975
   673
proof-
blanchet@48975
   674
   let ?f = "\<lambda> c. if c \<in> A then Inl c else Inr c"
blanchet@48975
   675
   have "inj_on ?f (A \<union> B) \<and> ?f ` (A \<union> B) \<le> A <+> B"
blanchet@48975
   676
   unfolding inj_on_def by auto
blanchet@48975
   677
   thus ?thesis using card_of_ordLeq by blast
blanchet@48975
   678
qed
blanchet@48975
   679
blanchet@48975
   680
blanchet@48975
   681
lemma card_of_Times1:
blanchet@48975
   682
assumes "A \<noteq> {}"
blanchet@48975
   683
shows "|B| \<le>o |B \<times> A|"
blanchet@48975
   684
proof(cases "B = {}", simp add: card_of_empty)
blanchet@48975
   685
  assume *: "B \<noteq> {}"
blanchet@48975
   686
  have "fst `(B \<times> A) = B" unfolding image_def using assms by auto
blanchet@48975
   687
  thus ?thesis using inj_on_iff_surj[of B "B \<times> A"]
blanchet@48975
   688
                     card_of_ordLeq[of B "B \<times> A"] * by blast
blanchet@48975
   689
qed
blanchet@48975
   690
blanchet@48975
   691
blanchet@48975
   692
lemma card_of_Times_commute: "|A \<times> B| =o |B \<times> A|"
blanchet@48975
   693
proof-
blanchet@48975
   694
  let ?f = "\<lambda>(a::'a,b::'b). (b,a)"
blanchet@48975
   695
  have "bij_betw ?f (A \<times> B) (B \<times> A)"
blanchet@48975
   696
  unfolding bij_betw_def inj_on_def by auto
blanchet@48975
   697
  thus ?thesis using card_of_ordIso by blast
blanchet@48975
   698
qed
blanchet@48975
   699
blanchet@48975
   700
blanchet@48975
   701
lemma card_of_Times2:
blanchet@48975
   702
assumes "A \<noteq> {}"   shows "|B| \<le>o |A \<times> B|"
blanchet@48975
   703
using assms card_of_Times1[of A B] card_of_Times_commute[of B A]
blanchet@48975
   704
      ordLeq_ordIso_trans by blast
blanchet@48975
   705
blanchet@48975
   706
blanchet@54475
   707
corollary Card_order_Times1:
blanchet@54475
   708
"\<lbrakk>Card_order r; B \<noteq> {}\<rbrakk> \<Longrightarrow> r \<le>o |(Field r) \<times> B|"
blanchet@54475
   709
using card_of_Times1[of B] card_of_Field_ordIso
blanchet@54475
   710
      ordIso_ordLeq_trans ordIso_symmetric by blast
blanchet@54475
   711
blanchet@54475
   712
blanchet@48975
   713
corollary Card_order_Times2:
blanchet@48975
   714
"\<lbrakk>Card_order r; A \<noteq> {}\<rbrakk> \<Longrightarrow> r \<le>o |A \<times> (Field r)|"
blanchet@48975
   715
using card_of_Times2[of A] card_of_Field_ordIso
blanchet@48975
   716
      ordIso_ordLeq_trans ordIso_symmetric by blast
blanchet@48975
   717
blanchet@48975
   718
blanchet@48975
   719
lemma card_of_Times3: "|A| \<le>o |A \<times> A|"
blanchet@48975
   720
using card_of_Times1[of A]
blanchet@48975
   721
by(cases "A = {}", simp add: card_of_empty, blast)
blanchet@48975
   722
blanchet@48975
   723
blanchet@48975
   724
lemma card_of_Plus_Times_bool: "|A <+> A| =o |A \<times> (UNIV::bool set)|"
blanchet@48975
   725
proof-
blanchet@48975
   726
  let ?f = "\<lambda>c::'a + 'a. case c of Inl a \<Rightarrow> (a,True)
blanchet@48975
   727
                                  |Inr a \<Rightarrow> (a,False)"
blanchet@48975
   728
  have "bij_betw ?f (A <+> A) (A \<times> (UNIV::bool set))"
blanchet@48975
   729
  proof-
blanchet@48975
   730
    {fix  c1 and c2 assume "?f c1 = ?f c2"
blanchet@48975
   731
     hence "c1 = c2"
blanchet@48975
   732
     by(case_tac "c1", case_tac "c2", auto, case_tac "c2", auto)
blanchet@48975
   733
    }
blanchet@48975
   734
    moreover
blanchet@48975
   735
    {fix c assume "c \<in> A <+> A"
blanchet@48975
   736
     hence "?f c \<in> A \<times> (UNIV::bool set)"
blanchet@48975
   737
     by(case_tac c, auto)
blanchet@48975
   738
    }
blanchet@48975
   739
    moreover
blanchet@48975
   740
    {fix a bl assume *: "(a,bl) \<in> A \<times> (UNIV::bool set)"
blanchet@48975
   741
     have "(a,bl) \<in> ?f ` ( A <+> A)"
blanchet@48975
   742
     proof(cases bl)
blanchet@48975
   743
       assume bl hence "?f(Inl a) = (a,bl)" by auto
blanchet@48975
   744
       thus ?thesis using * by force
blanchet@48975
   745
     next
blanchet@48975
   746
       assume "\<not> bl" hence "?f(Inr a) = (a,bl)" by auto
blanchet@48975
   747
       thus ?thesis using * by force
blanchet@48975
   748
     qed
blanchet@48975
   749
    }
blanchet@48975
   750
    ultimately show ?thesis unfolding bij_betw_def inj_on_def by auto
blanchet@48975
   751
  qed
blanchet@48975
   752
  thus ?thesis using card_of_ordIso by blast
blanchet@48975
   753
qed
blanchet@48975
   754
blanchet@48975
   755
blanchet@48975
   756
lemma card_of_Times_mono1:
blanchet@48975
   757
assumes "|A| \<le>o |B|"
blanchet@48975
   758
shows "|A \<times> C| \<le>o |B \<times> C|"
blanchet@48975
   759
proof-
blanchet@48975
   760
  obtain f where 1: "inj_on f A \<and> f ` A \<le> B"
blanchet@48975
   761
  using assms card_of_ordLeq[of A] by fastforce
blanchet@48975
   762
  obtain g where g_def:
blanchet@48975
   763
  "g = (\<lambda>(a,c::'c). (f a,c))" by blast
blanchet@48975
   764
  have "inj_on g (A \<times> C) \<and> g ` (A \<times> C) \<le> (B \<times> C)"
blanchet@48975
   765
  using 1 unfolding inj_on_def using g_def by auto
blanchet@48975
   766
  thus ?thesis using card_of_ordLeq by metis
blanchet@48975
   767
qed
blanchet@48975
   768
blanchet@48975
   769
blanchet@48975
   770
corollary ordLeq_Times_mono1:
blanchet@48975
   771
assumes "r \<le>o r'"
blanchet@48975
   772
shows "|(Field r) \<times> C| \<le>o |(Field r') \<times> C|"
blanchet@48975
   773
using assms card_of_mono2 card_of_Times_mono1 by blast
blanchet@48975
   774
blanchet@48975
   775
blanchet@48975
   776
lemma card_of_Times_mono2:
blanchet@48975
   777
assumes "|A| \<le>o |B|"
blanchet@48975
   778
shows "|C \<times> A| \<le>o |C \<times> B|"
blanchet@48975
   779
using assms card_of_Times_mono1[of A B C]
blanchet@48975
   780
      card_of_Times_commute[of C A]  card_of_Times_commute[of B C]
blanchet@48975
   781
      ordIso_ordLeq_trans[of "|C \<times> A|"] ordLeq_ordIso_trans[of "|C \<times> A|"]
blanchet@48975
   782
by blast
blanchet@48975
   783
blanchet@48975
   784
blanchet@48975
   785
corollary ordLeq_Times_mono2:
blanchet@48975
   786
assumes "r \<le>o r'"
blanchet@48975
   787
shows "|A \<times> (Field r)| \<le>o |A \<times> (Field r')|"
blanchet@48975
   788
using assms card_of_mono2 card_of_Times_mono2 by blast
blanchet@48975
   789
blanchet@48975
   790
blanchet@48975
   791
lemma card_of_Sigma_mono1:
blanchet@48975
   792
assumes "\<forall>i \<in> I. |A i| \<le>o |B i|"
blanchet@48975
   793
shows "|SIGMA i : I. A i| \<le>o |SIGMA i : I. B i|"
blanchet@48975
   794
proof-
blanchet@48975
   795
  have "\<forall>i. i \<in> I \<longrightarrow> (\<exists>f. inj_on f (A i) \<and> f ` (A i) \<le> B i)"
blanchet@48975
   796
  using assms by (auto simp add: card_of_ordLeq)
blanchet@48975
   797
  with choice[of "\<lambda> i f. i \<in> I \<longrightarrow> inj_on f (A i) \<and> f ` (A i) \<le> B i"]
traytel@51764
   798
  obtain F where 1: "\<forall>i \<in> I. inj_on (F i) (A i) \<and> (F i) ` (A i) \<le> B i" by metis
blanchet@48975
   799
  obtain g where g_def: "g = (\<lambda>(i,a::'b). (i,F i a))" by blast
blanchet@48975
   800
  have "inj_on g (Sigma I A) \<and> g ` (Sigma I A) \<le> (Sigma I B)"
blanchet@48975
   801
  using 1 unfolding inj_on_def using g_def by force
blanchet@48975
   802
  thus ?thesis using card_of_ordLeq by metis
blanchet@48975
   803
qed
blanchet@48975
   804
blanchet@48975
   805
blanchet@48975
   806
corollary card_of_Sigma_Times:
blanchet@48975
   807
"\<forall>i \<in> I. |A i| \<le>o |B| \<Longrightarrow> |SIGMA i : I. A i| \<le>o |I \<times> B|"
blanchet@48975
   808
using card_of_Sigma_mono1[of I A "\<lambda>i. B"] .
blanchet@48975
   809
blanchet@48975
   810
blanchet@48975
   811
lemma card_of_UNION_Sigma:
blanchet@48975
   812
"|\<Union>i \<in> I. A i| \<le>o |SIGMA i : I. A i|"
blanchet@48975
   813
using Ex_inj_on_UNION_Sigma[of I A] card_of_ordLeq by metis
blanchet@48975
   814
blanchet@48975
   815
blanchet@48975
   816
lemma card_of_bool:
blanchet@48975
   817
assumes "a1 \<noteq> a2"
blanchet@48975
   818
shows "|UNIV::bool set| =o |{a1,a2}|"
blanchet@48975
   819
proof-
blanchet@48975
   820
  let ?f = "\<lambda> bl. case bl of True \<Rightarrow> a1 | False \<Rightarrow> a2"
blanchet@48975
   821
  have "bij_betw ?f UNIV {a1,a2}"
blanchet@48975
   822
  proof-
blanchet@48975
   823
    {fix bl1 and bl2 assume "?f  bl1 = ?f bl2"
blanchet@48975
   824
     hence "bl1 = bl2" using assms by (case_tac bl1, case_tac bl2, auto)
blanchet@48975
   825
    }
blanchet@48975
   826
    moreover
blanchet@48975
   827
    {fix bl have "?f bl \<in> {a1,a2}" by (case_tac bl, auto)
blanchet@48975
   828
    }
blanchet@48975
   829
    moreover
blanchet@48975
   830
    {fix a assume *: "a \<in> {a1,a2}"
blanchet@48975
   831
     have "a \<in> ?f ` UNIV"
blanchet@48975
   832
     proof(cases "a = a1")
blanchet@48975
   833
       assume "a = a1"
blanchet@48975
   834
       hence "?f True = a" by auto  thus ?thesis by blast
blanchet@48975
   835
     next
blanchet@48975
   836
       assume "a \<noteq> a1" hence "a = a2" using * by auto
blanchet@48975
   837
       hence "?f False = a" by auto  thus ?thesis by blast
blanchet@48975
   838
     qed
blanchet@48975
   839
    }
blanchet@48975
   840
    ultimately show ?thesis unfolding bij_betw_def inj_on_def
blanchet@48975
   841
    by (metis image_subsetI order_eq_iff subsetI)
blanchet@48975
   842
  qed
blanchet@48975
   843
  thus ?thesis using card_of_ordIso by blast
blanchet@48975
   844
qed
blanchet@48975
   845
blanchet@48975
   846
blanchet@48975
   847
lemma card_of_Plus_Times_aux:
blanchet@48975
   848
assumes A2: "a1 \<noteq> a2 \<and> {a1,a2} \<le> A" and
blanchet@48975
   849
        LEQ: "|A| \<le>o |B|"
blanchet@48975
   850
shows "|A <+> B| \<le>o |A \<times> B|"
blanchet@48975
   851
proof-
blanchet@48975
   852
  have 1: "|UNIV::bool set| \<le>o |A|"
blanchet@48975
   853
  using A2 card_of_mono1[of "{a1,a2}"] card_of_bool[of a1 a2]
blanchet@48975
   854
        ordIso_ordLeq_trans[of "|UNIV::bool set|"] by metis
blanchet@48975
   855
  (*  *)
blanchet@48975
   856
  have "|A <+> B| \<le>o |B <+> B|"
blanchet@48975
   857
  using LEQ card_of_Plus_mono1 by blast
blanchet@48975
   858
  moreover have "|B <+> B| =o |B \<times> (UNIV::bool set)|"
blanchet@48975
   859
  using card_of_Plus_Times_bool by blast
blanchet@48975
   860
  moreover have "|B \<times> (UNIV::bool set)| \<le>o |B \<times> A|"
blanchet@48975
   861
  using 1 by (simp add: card_of_Times_mono2)
blanchet@48975
   862
  moreover have " |B \<times> A| =o |A \<times> B|"
blanchet@48975
   863
  using card_of_Times_commute by blast
blanchet@48975
   864
  ultimately show "|A <+> B| \<le>o |A \<times> B|"
blanchet@48975
   865
  using ordLeq_ordIso_trans[of "|A <+> B|" "|B <+> B|" "|B \<times> (UNIV::bool set)|"]
blanchet@48975
   866
        ordLeq_transitive[of "|A <+> B|" "|B \<times> (UNIV::bool set)|" "|B \<times> A|"]
blanchet@48975
   867
        ordLeq_ordIso_trans[of "|A <+> B|" "|B \<times> A|" "|A \<times> B|"]
blanchet@48975
   868
  by blast
blanchet@48975
   869
qed
blanchet@48975
   870
blanchet@48975
   871
blanchet@48975
   872
lemma card_of_Plus_Times:
blanchet@48975
   873
assumes A2: "a1 \<noteq> a2 \<and> {a1,a2} \<le> A" and
blanchet@48975
   874
        B2: "b1 \<noteq> b2 \<and> {b1,b2} \<le> B"
blanchet@48975
   875
shows "|A <+> B| \<le>o |A \<times> B|"
blanchet@48975
   876
proof-
blanchet@48975
   877
  {assume "|A| \<le>o |B|"
blanchet@48975
   878
   hence ?thesis using assms by (auto simp add: card_of_Plus_Times_aux)
blanchet@48975
   879
  }
blanchet@48975
   880
  moreover
blanchet@48975
   881
  {assume "|B| \<le>o |A|"
blanchet@48975
   882
   hence "|B <+> A| \<le>o |B \<times> A|"
blanchet@48975
   883
   using assms by (auto simp add: card_of_Plus_Times_aux)
blanchet@48975
   884
   hence ?thesis
blanchet@48975
   885
   using card_of_Plus_commute card_of_Times_commute
blanchet@48975
   886
         ordIso_ordLeq_trans ordLeq_ordIso_trans by metis
blanchet@48975
   887
  }
blanchet@48975
   888
  ultimately show ?thesis
blanchet@48975
   889
  using card_of_Well_order[of A] card_of_Well_order[of B]
blanchet@48975
   890
        ordLeq_total[of "|A|"] by metis
blanchet@48975
   891
qed
blanchet@48975
   892
blanchet@48975
   893
blanchet@48975
   894
lemma card_of_ordLeq_finite:
blanchet@48975
   895
assumes "|A| \<le>o |B|" and "finite B"
blanchet@48975
   896
shows "finite A"
blanchet@48975
   897
using assms unfolding ordLeq_def
blanchet@48975
   898
using embed_inj_on[of "|A|" "|B|"]  embed_Field[of "|A|" "|B|"]
blanchet@48975
   899
      Field_card_of[of "A"] Field_card_of[of "B"] inj_on_finite[of _ "A" "B"] by fastforce
blanchet@48975
   900
blanchet@48975
   901
blanchet@48975
   902
lemma card_of_ordLeq_infinite:
blanchet@48975
   903
assumes "|A| \<le>o |B|" and "infinite A"
blanchet@48975
   904
shows "infinite B"
blanchet@48975
   905
using assms card_of_ordLeq_finite by auto
blanchet@48975
   906
blanchet@48975
   907
blanchet@48975
   908
lemma card_of_ordIso_finite:
blanchet@48975
   909
assumes "|A| =o |B|"
blanchet@48975
   910
shows "finite A = finite B"
blanchet@48975
   911
using assms unfolding ordIso_def iso_def[abs_def]
blanchet@48975
   912
by (auto simp: bij_betw_finite Field_card_of)
blanchet@48975
   913
blanchet@48975
   914
blanchet@48975
   915
lemma card_of_ordIso_finite_Field:
blanchet@48975
   916
assumes "Card_order r" and "r =o |A|"
blanchet@48975
   917
shows "finite(Field r) = finite A"
blanchet@48975
   918
using assms card_of_Field_ordIso card_of_ordIso_finite ordIso_equivalence by blast
blanchet@48975
   919
blanchet@48975
   920
blanchet@48975
   921
subsection {* Cardinals versus set operations involving infinite sets *}
blanchet@48975
   922
blanchet@48975
   923
blanchet@48975
   924
text{* Here we show that, for infinite sets, most set-theoretic constructions
blanchet@48975
   925
do not increase the cardinality.  The cornerstone for this is
blanchet@48975
   926
theorem @{text "Card_order_Times_same_infinite"}, which states that self-product
blanchet@48975
   927
does not increase cardinality -- the proof of this fact adapts a standard
blanchet@48975
   928
set-theoretic argument, as presented, e.g., in the proof of theorem 1.5.11
blanchet@48975
   929
at page 47 in \cite{card-book}. Then everything else follows fairly easily.  *}
blanchet@48975
   930
blanchet@48975
   931
blanchet@48975
   932
lemma infinite_iff_card_of_nat:
blanchet@48975
   933
"infinite A = ( |UNIV::nat set| \<le>o |A| )"
blanchet@48975
   934
by (auto simp add: infinite_iff_countable_subset card_of_ordLeq)
blanchet@48975
   935
blanchet@48975
   936
blanchet@48975
   937
text{* The next two results correspond to the ZF fact that all infinite cardinals are
blanchet@48975
   938
limit ordinals: *}
blanchet@48975
   939
blanchet@48975
   940
lemma Card_order_infinite_not_under:
blanchet@48975
   941
assumes CARD: "Card_order r" and INF: "infinite (Field r)"
blanchet@48975
   942
shows "\<not> (\<exists>a. Field r = rel.under r a)"
blanchet@48975
   943
proof(auto)
blanchet@48975
   944
  have 0: "Well_order r \<and> wo_rel r \<and> Refl r"
blanchet@48975
   945
  using CARD unfolding wo_rel_def card_order_on_def order_on_defs by auto
blanchet@48975
   946
  fix a assume *: "Field r = rel.under r a"
blanchet@48975
   947
  show False
blanchet@48975
   948
  proof(cases "a \<in> Field r")
blanchet@48975
   949
    assume Case1: "a \<notin> Field r"
blanchet@48975
   950
    hence "rel.under r a = {}" unfolding Field_def rel.under_def by auto
blanchet@48975
   951
    thus False using INF *  by auto
blanchet@48975
   952
  next
blanchet@48975
   953
    let ?r' = "Restr r (rel.underS r a)"
blanchet@48975
   954
    assume Case2: "a \<in> Field r"
blanchet@48975
   955
    hence 1: "rel.under r a = rel.underS r a \<union> {a} \<and> a \<notin> rel.underS r a"
blanchet@48975
   956
    using 0 rel.Refl_under_underS rel.underS_notIn by fastforce
blanchet@48975
   957
    have 2: "wo_rel.ofilter r (rel.underS r a) \<and> rel.underS r a < Field r"
blanchet@48975
   958
    using 0 wo_rel.underS_ofilter * 1 Case2 by auto
blanchet@48975
   959
    hence "?r' <o r" using 0 using ofilter_ordLess by blast
blanchet@48975
   960
    moreover
blanchet@48975
   961
    have "Field ?r' = rel.underS r a \<and> Well_order ?r'"
blanchet@48975
   962
    using  2 0 Field_Restr_ofilter[of r] Well_order_Restr[of r] by blast
blanchet@48975
   963
    ultimately have "|rel.underS r a| <o r" using ordLess_Field[of ?r'] by auto
blanchet@48975
   964
    moreover have "|rel.under r a| =o r" using * CARD card_of_Field_ordIso[of r] by auto
blanchet@48975
   965
    ultimately have "|rel.underS r a| <o |rel.under r a|"
blanchet@48975
   966
    using ordIso_symmetric ordLess_ordIso_trans by blast
blanchet@48975
   967
    moreover
blanchet@48975
   968
    {have "\<exists>f. bij_betw f (rel.under r a) (rel.underS r a)"
blanchet@48975
   969
     using infinite_imp_bij_betw[of "Field r" a] INF * 1 by auto
blanchet@48975
   970
     hence "|rel.under r a| =o |rel.underS r a|" using card_of_ordIso by blast
blanchet@48975
   971
    }
blanchet@48975
   972
    ultimately show False using not_ordLess_ordIso ordIso_symmetric by blast
blanchet@48975
   973
  qed
blanchet@48975
   974
qed
blanchet@48975
   975
blanchet@48975
   976
blanchet@48975
   977
lemma infinite_Card_order_limit:
blanchet@48975
   978
assumes r: "Card_order r" and "infinite (Field r)"
blanchet@48975
   979
and a: "a : Field r"
blanchet@48975
   980
shows "EX b : Field r. a \<noteq> b \<and> (a,b) : r"
blanchet@48975
   981
proof-
blanchet@48975
   982
  have "Field r \<noteq> rel.under r a"
blanchet@48975
   983
  using assms Card_order_infinite_not_under by blast
blanchet@48975
   984
  moreover have "rel.under r a \<le> Field r"
blanchet@48975
   985
  using rel.under_Field .
blanchet@48975
   986
  ultimately have "rel.under r a < Field r" by blast
blanchet@48975
   987
  then obtain b where 1: "b : Field r \<and> ~ (b,a) : r"
blanchet@48975
   988
  unfolding rel.under_def by blast
blanchet@48975
   989
  moreover have ba: "b \<noteq> a"
blanchet@48975
   990
  using 1 r unfolding card_order_on_def well_order_on_def
blanchet@48975
   991
  linear_order_on_def partial_order_on_def preorder_on_def refl_on_def by auto
blanchet@48975
   992
  ultimately have "(a,b) : r"
blanchet@48975
   993
  using a r unfolding card_order_on_def well_order_on_def linear_order_on_def
blanchet@48975
   994
  total_on_def by blast
blanchet@48975
   995
  thus ?thesis using 1 ba by auto
blanchet@48975
   996
qed
blanchet@48975
   997
blanchet@48975
   998
blanchet@48975
   999
theorem Card_order_Times_same_infinite:
blanchet@48975
  1000
assumes CO: "Card_order r" and INF: "infinite(Field r)"
blanchet@48975
  1001
shows "|Field r \<times> Field r| \<le>o r"
blanchet@48975
  1002
proof-
blanchet@48975
  1003
  obtain phi where phi_def:
blanchet@48975
  1004
  "phi = (\<lambda>r::'a rel. Card_order r \<and> infinite(Field r) \<and>
blanchet@48975
  1005
                      \<not> |Field r \<times> Field r| \<le>o r )" by blast
blanchet@48975
  1006
  have temp1: "\<forall>r. phi r \<longrightarrow> Well_order r"
blanchet@48975
  1007
  unfolding phi_def card_order_on_def by auto
blanchet@48975
  1008
  have Ft: "\<not>(\<exists>r. phi r)"
blanchet@48975
  1009
  proof
blanchet@48975
  1010
    assume "\<exists>r. phi r"
blanchet@48975
  1011
    hence "{r. phi r} \<noteq> {} \<and> {r. phi r} \<le> {r. Well_order r}"
blanchet@48975
  1012
    using temp1 by auto
blanchet@48975
  1013
    then obtain r where 1: "phi r" and 2: "\<forall>r'. phi r' \<longrightarrow> r \<le>o r'" and
blanchet@48975
  1014
                   3: "Card_order r \<and> Well_order r"
blanchet@48975
  1015
    using exists_minim_Well_order[of "{r. phi r}"] temp1 phi_def by blast
blanchet@48975
  1016
    let ?A = "Field r"  let ?r' = "bsqr r"
blanchet@48975
  1017
    have 4: "Well_order ?r' \<and> Field ?r' = ?A \<times> ?A \<and> |?A| =o r"
blanchet@48975
  1018
    using 3 bsqr_Well_order Field_bsqr card_of_Field_ordIso by blast
blanchet@48975
  1019
    have 5: "Card_order |?A \<times> ?A| \<and> Well_order |?A \<times> ?A|"
blanchet@48975
  1020
    using card_of_Card_order card_of_Well_order by blast
blanchet@48975
  1021
    (*  *)
blanchet@48975
  1022
    have "r <o |?A \<times> ?A|"
blanchet@48975
  1023
    using 1 3 5 ordLess_or_ordLeq unfolding phi_def by blast
blanchet@48975
  1024
    moreover have "|?A \<times> ?A| \<le>o ?r'"
blanchet@48975
  1025
    using card_of_least[of "?A \<times> ?A"] 4 by auto
blanchet@48975
  1026
    ultimately have "r <o ?r'" using ordLess_ordLeq_trans by auto
blanchet@48975
  1027
    then obtain f where 6: "embed r ?r' f" and 7: "\<not> bij_betw f ?A (?A \<times> ?A)"
blanchet@48975
  1028
    unfolding ordLess_def embedS_def[abs_def]
blanchet@48975
  1029
    by (auto simp add: Field_bsqr)
blanchet@48975
  1030
    let ?B = "f ` ?A"
blanchet@48975
  1031
    have "|?A| =o |?B|"
blanchet@48975
  1032
    using 3 6 embed_inj_on inj_on_imp_bij_betw card_of_ordIso by blast
blanchet@48975
  1033
    hence 8: "r =o |?B|" using 4 ordIso_transitive ordIso_symmetric by blast
blanchet@48975
  1034
    (*  *)
blanchet@48975
  1035
    have "wo_rel.ofilter ?r' ?B"
blanchet@48975
  1036
    using 6 embed_Field_ofilter 3 4 by blast
blanchet@48975
  1037
    hence "wo_rel.ofilter ?r' ?B \<and> ?B \<noteq> ?A \<times> ?A \<and> ?B \<noteq> Field ?r'"
blanchet@48975
  1038
    using 7 unfolding bij_betw_def using 6 3 embed_inj_on 4 by auto
blanchet@48975
  1039
    hence temp2: "wo_rel.ofilter ?r' ?B \<and> ?B < ?A \<times> ?A"
blanchet@48975
  1040
    using 4 wo_rel_def[of ?r'] wo_rel.ofilter_def[of ?r' ?B] by blast
blanchet@48975
  1041
    have "\<not> (\<exists>a. Field r = rel.under r a)"
blanchet@48975
  1042
    using 1 unfolding phi_def using Card_order_infinite_not_under[of r] by auto
blanchet@48975
  1043
    then obtain A1 where temp3: "wo_rel.ofilter r A1 \<and> A1 < ?A" and 9: "?B \<le> A1 \<times> A1"
blanchet@48975
  1044
    using temp2 3 bsqr_ofilter[of r ?B] by blast
blanchet@48975
  1045
    hence "|?B| \<le>o |A1 \<times> A1|" using card_of_mono1 by blast
blanchet@48975
  1046
    hence 10: "r \<le>o |A1 \<times> A1|" using 8 ordIso_ordLeq_trans by blast
blanchet@48975
  1047
    let ?r1 = "Restr r A1"
blanchet@48975
  1048
    have "?r1 <o r" using temp3 ofilter_ordLess 3 by blast
blanchet@48975
  1049
    moreover
blanchet@48975
  1050
    {have "well_order_on A1 ?r1" using 3 temp3 well_order_on_Restr by blast
blanchet@48975
  1051
     hence "|A1| \<le>o ?r1" using 3 Well_order_Restr card_of_least by blast
blanchet@48975
  1052
    }
blanchet@48975
  1053
    ultimately have 11: "|A1| <o r" using ordLeq_ordLess_trans by blast
blanchet@48975
  1054
    (*  *)
blanchet@48975
  1055
    have "infinite (Field r)" using 1 unfolding phi_def by simp
blanchet@48975
  1056
    hence "infinite ?B" using 8 3 card_of_ordIso_finite_Field[of r ?B] by blast
blanchet@48975
  1057
    hence "infinite A1" using 9 infinite_super finite_cartesian_product by blast
blanchet@48975
  1058
    moreover have temp4: "Field |A1| = A1 \<and> Well_order |A1| \<and> Card_order |A1|"
blanchet@48975
  1059
    using card_of_Card_order[of A1] card_of_Well_order[of A1]
blanchet@48975
  1060
    by (simp add: Field_card_of)
blanchet@48975
  1061
    moreover have "\<not> r \<le>o | A1 |"
blanchet@48975
  1062
    using temp4 11 3 using not_ordLeq_iff_ordLess by blast
blanchet@48975
  1063
    ultimately have "infinite(Field |A1| ) \<and> Card_order |A1| \<and> \<not> r \<le>o | A1 |"
blanchet@48975
  1064
    by (simp add: card_of_card_order_on)
blanchet@48975
  1065
    hence "|Field |A1| \<times> Field |A1| | \<le>o |A1|"
blanchet@48975
  1066
    using 2 unfolding phi_def by blast
blanchet@48975
  1067
    hence "|A1 \<times> A1 | \<le>o |A1|" using temp4 by auto
blanchet@48975
  1068
    hence "r \<le>o |A1|" using 10 ordLeq_transitive by blast
blanchet@48975
  1069
    thus False using 11 not_ordLess_ordLeq by auto
blanchet@48975
  1070
  qed
blanchet@48975
  1071
  thus ?thesis using assms unfolding phi_def by blast
blanchet@48975
  1072
qed
blanchet@48975
  1073
blanchet@48975
  1074
blanchet@48975
  1075
corollary card_of_Times_same_infinite:
blanchet@48975
  1076
assumes "infinite A"
blanchet@48975
  1077
shows "|A \<times> A| =o |A|"
blanchet@48975
  1078
proof-
blanchet@48975
  1079
  let ?r = "|A|"
blanchet@48975
  1080
  have "Field ?r = A \<and> Card_order ?r"
blanchet@48975
  1081
  using Field_card_of card_of_Card_order[of A] by fastforce
blanchet@48975
  1082
  hence "|A \<times> A| \<le>o |A|"
blanchet@48975
  1083
  using Card_order_Times_same_infinite[of ?r] assms by auto
blanchet@48975
  1084
  thus ?thesis using card_of_Times3 ordIso_iff_ordLeq by blast
blanchet@48975
  1085
qed
blanchet@48975
  1086
blanchet@48975
  1087
blanchet@48975
  1088
lemma card_of_Times_infinite:
blanchet@48975
  1089
assumes INF: "infinite A" and NE: "B \<noteq> {}" and LEQ: "|B| \<le>o |A|"
blanchet@48975
  1090
shows "|A \<times> B| =o |A| \<and> |B \<times> A| =o |A|"
blanchet@48975
  1091
proof-
blanchet@48975
  1092
  have "|A| \<le>o |A \<times> B| \<and> |A| \<le>o |B \<times> A|"
blanchet@48975
  1093
  using assms by (simp add: card_of_Times1 card_of_Times2)
blanchet@48975
  1094
  moreover
blanchet@48975
  1095
  {have "|A \<times> B| \<le>o |A \<times> A| \<and> |B \<times> A| \<le>o |A \<times> A|"
blanchet@48975
  1096
   using LEQ card_of_Times_mono1 card_of_Times_mono2 by blast
blanchet@48975
  1097
   moreover have "|A \<times> A| =o |A|" using INF card_of_Times_same_infinite by blast
blanchet@48975
  1098
   ultimately have "|A \<times> B| \<le>o |A| \<and> |B \<times> A| \<le>o |A|"
blanchet@48975
  1099
   using ordLeq_ordIso_trans[of "|A \<times> B|"] ordLeq_ordIso_trans[of "|B \<times> A|"] by auto
blanchet@48975
  1100
  }
blanchet@48975
  1101
  ultimately show ?thesis by (simp add: ordIso_iff_ordLeq)
blanchet@48975
  1102
qed
blanchet@48975
  1103
blanchet@48975
  1104
blanchet@48975
  1105
corollary Card_order_Times_infinite:
blanchet@48975
  1106
assumes INF: "infinite(Field r)" and CARD: "Card_order r" and
blanchet@48975
  1107
        NE: "Field p \<noteq> {}" and LEQ: "p \<le>o r"
blanchet@48975
  1108
shows "| (Field r) \<times> (Field p) | =o r \<and> | (Field p) \<times> (Field r) | =o r"
blanchet@48975
  1109
proof-
blanchet@48975
  1110
  have "|Field r \<times> Field p| =o |Field r| \<and> |Field p \<times> Field r| =o |Field r|"
blanchet@48975
  1111
  using assms by (simp add: card_of_Times_infinite card_of_mono2)
blanchet@48975
  1112
  thus ?thesis
blanchet@48975
  1113
  using assms card_of_Field_ordIso[of r]
blanchet@48975
  1114
        ordIso_transitive[of "|Field r \<times> Field p|"]
blanchet@48975
  1115
        ordIso_transitive[of _ "|Field r|"] by blast
blanchet@48975
  1116
qed
blanchet@48975
  1117
blanchet@48975
  1118
blanchet@48975
  1119
lemma card_of_Sigma_ordLeq_infinite:
blanchet@48975
  1120
assumes INF: "infinite B" and
blanchet@48975
  1121
        LEQ_I: "|I| \<le>o |B|" and LEQ: "\<forall>i \<in> I. |A i| \<le>o |B|"
blanchet@48975
  1122
shows "|SIGMA i : I. A i| \<le>o |B|"
blanchet@48975
  1123
proof(cases "I = {}", simp add: card_of_empty)
blanchet@48975
  1124
  assume *: "I \<noteq> {}"
blanchet@48975
  1125
  have "|SIGMA i : I. A i| \<le>o |I \<times> B|"
blanchet@48975
  1126
  using LEQ card_of_Sigma_Times by blast
blanchet@48975
  1127
  moreover have "|I \<times> B| =o |B|"
blanchet@48975
  1128
  using INF * LEQ_I by (auto simp add: card_of_Times_infinite)
blanchet@48975
  1129
  ultimately show ?thesis using ordLeq_ordIso_trans by blast
blanchet@48975
  1130
qed
blanchet@48975
  1131
blanchet@48975
  1132
blanchet@48975
  1133
lemma card_of_Sigma_ordLeq_infinite_Field:
blanchet@48975
  1134
assumes INF: "infinite (Field r)" and r: "Card_order r" and
blanchet@48975
  1135
        LEQ_I: "|I| \<le>o r" and LEQ: "\<forall>i \<in> I. |A i| \<le>o r"
blanchet@48975
  1136
shows "|SIGMA i : I. A i| \<le>o r"
blanchet@48975
  1137
proof-
blanchet@48975
  1138
  let ?B  = "Field r"
blanchet@48975
  1139
  have 1: "r =o |?B| \<and> |?B| =o r" using r card_of_Field_ordIso
blanchet@48975
  1140
  ordIso_symmetric by blast
blanchet@48975
  1141
  hence "|I| \<le>o |?B|"  "\<forall>i \<in> I. |A i| \<le>o |?B|"
blanchet@48975
  1142
  using LEQ_I LEQ ordLeq_ordIso_trans by blast+
blanchet@48975
  1143
  hence  "|SIGMA i : I. A i| \<le>o |?B|" using INF LEQ
blanchet@48975
  1144
  card_of_Sigma_ordLeq_infinite by blast
blanchet@48975
  1145
  thus ?thesis using 1 ordLeq_ordIso_trans by blast
blanchet@48975
  1146
qed
blanchet@48975
  1147
blanchet@48975
  1148
blanchet@48975
  1149
lemma card_of_Times_ordLeq_infinite_Field:
blanchet@48975
  1150
"\<lbrakk>infinite (Field r); |A| \<le>o r; |B| \<le>o r; Card_order r\<rbrakk>
blanchet@48975
  1151
 \<Longrightarrow> |A <*> B| \<le>o r"
blanchet@48975
  1152
by(simp add: card_of_Sigma_ordLeq_infinite_Field)
blanchet@48975
  1153
blanchet@48975
  1154
blanchet@54475
  1155
lemma card_of_Times_infinite_simps:
blanchet@54475
  1156
"\<lbrakk>infinite A; B \<noteq> {}; |B| \<le>o |A|\<rbrakk> \<Longrightarrow> |A \<times> B| =o |A|"
blanchet@54475
  1157
"\<lbrakk>infinite A; B \<noteq> {}; |B| \<le>o |A|\<rbrakk> \<Longrightarrow> |A| =o |A \<times> B|"
blanchet@54475
  1158
"\<lbrakk>infinite A; B \<noteq> {}; |B| \<le>o |A|\<rbrakk> \<Longrightarrow> |B \<times> A| =o |A|"
blanchet@54475
  1159
"\<lbrakk>infinite A; B \<noteq> {}; |B| \<le>o |A|\<rbrakk> \<Longrightarrow> |A| =o |B \<times> A|"
blanchet@54475
  1160
by (auto simp add: card_of_Times_infinite ordIso_symmetric)
blanchet@54475
  1161
blanchet@54475
  1162
blanchet@48975
  1163
lemma card_of_UNION_ordLeq_infinite:
blanchet@48975
  1164
assumes INF: "infinite B" and
blanchet@48975
  1165
        LEQ_I: "|I| \<le>o |B|" and LEQ: "\<forall>i \<in> I. |A i| \<le>o |B|"
blanchet@48975
  1166
shows "|\<Union> i \<in> I. A i| \<le>o |B|"
blanchet@48975
  1167
proof(cases "I = {}", simp add: card_of_empty)
blanchet@48975
  1168
  assume *: "I \<noteq> {}"
blanchet@48975
  1169
  have "|\<Union> i \<in> I. A i| \<le>o |SIGMA i : I. A i|"
blanchet@48975
  1170
  using card_of_UNION_Sigma by blast
blanchet@48975
  1171
  moreover have "|SIGMA i : I. A i| \<le>o |B|"
blanchet@48975
  1172
  using assms card_of_Sigma_ordLeq_infinite by blast
blanchet@48975
  1173
  ultimately show ?thesis using ordLeq_transitive by blast
blanchet@48975
  1174
qed
blanchet@48975
  1175
blanchet@48975
  1176
blanchet@48975
  1177
corollary card_of_UNION_ordLeq_infinite_Field:
blanchet@48975
  1178
assumes INF: "infinite (Field r)" and r: "Card_order r" and
blanchet@48975
  1179
        LEQ_I: "|I| \<le>o r" and LEQ: "\<forall>i \<in> I. |A i| \<le>o r"
blanchet@48975
  1180
shows "|\<Union> i \<in> I. A i| \<le>o r"
blanchet@48975
  1181
proof-
blanchet@48975
  1182
  let ?B  = "Field r"
blanchet@48975
  1183
  have 1: "r =o |?B| \<and> |?B| =o r" using r card_of_Field_ordIso
blanchet@48975
  1184
  ordIso_symmetric by blast
blanchet@48975
  1185
  hence "|I| \<le>o |?B|"  "\<forall>i \<in> I. |A i| \<le>o |?B|"
blanchet@48975
  1186
  using LEQ_I LEQ ordLeq_ordIso_trans by blast+
blanchet@48975
  1187
  hence  "|\<Union> i \<in> I. A i| \<le>o |?B|" using INF LEQ
blanchet@48975
  1188
  card_of_UNION_ordLeq_infinite by blast
blanchet@48975
  1189
  thus ?thesis using 1 ordLeq_ordIso_trans by blast
blanchet@48975
  1190
qed
blanchet@48975
  1191
blanchet@48975
  1192
blanchet@48975
  1193
lemma card_of_Plus_infinite1:
blanchet@48975
  1194
assumes INF: "infinite A" and LEQ: "|B| \<le>o |A|"
blanchet@48975
  1195
shows "|A <+> B| =o |A|"
blanchet@48975
  1196
proof(cases "B = {}", simp add: card_of_Plus_empty1 card_of_Plus_empty2 ordIso_symmetric)
blanchet@48975
  1197
  let ?Inl = "Inl::'a \<Rightarrow> 'a + 'b"  let ?Inr = "Inr::'b \<Rightarrow> 'a + 'b"
blanchet@48975
  1198
  assume *: "B \<noteq> {}"
blanchet@48975
  1199
  then obtain b1 where 1: "b1 \<in> B" by blast
blanchet@48975
  1200
  show ?thesis
blanchet@48975
  1201
  proof(cases "B = {b1}")
blanchet@48975
  1202
    assume Case1: "B = {b1}"
blanchet@48975
  1203
    have 2: "bij_betw ?Inl A ((?Inl ` A))"
blanchet@48975
  1204
    unfolding bij_betw_def inj_on_def by auto
blanchet@48975
  1205
    hence 3: "infinite (?Inl ` A)"
blanchet@48975
  1206
    using INF bij_betw_finite[of ?Inl A] by blast
blanchet@48975
  1207
    let ?A' = "?Inl ` A \<union> {?Inr b1}"
blanchet@48975
  1208
    obtain g where "bij_betw g (?Inl ` A) ?A'"
blanchet@48975
  1209
    using 3 infinite_imp_bij_betw2[of "?Inl ` A"] by auto
blanchet@48975
  1210
    moreover have "?A' = A <+> B" using Case1 by blast
blanchet@48975
  1211
    ultimately have "bij_betw g (?Inl ` A) (A <+> B)" by simp
blanchet@48975
  1212
    hence "bij_betw (g o ?Inl) A (A <+> B)"
blanchet@48975
  1213
    using 2 by (auto simp add: bij_betw_trans)
blanchet@48975
  1214
    thus ?thesis using card_of_ordIso ordIso_symmetric by blast
blanchet@48975
  1215
  next
blanchet@48975
  1216
    assume Case2: "B \<noteq> {b1}"
blanchet@48975
  1217
    with * 1 obtain b2 where 3: "b1 \<noteq> b2 \<and> {b1,b2} \<le> B" by fastforce
blanchet@48975
  1218
    obtain f where "inj_on f B \<and> f ` B \<le> A"
blanchet@48975
  1219
    using LEQ card_of_ordLeq[of B] by fastforce
blanchet@48975
  1220
    with 3 have "f b1 \<noteq> f b2 \<and> {f b1, f b2} \<le> A"
blanchet@48975
  1221
    unfolding inj_on_def by auto
blanchet@48975
  1222
    with 3 have "|A <+> B| \<le>o |A \<times> B|"
blanchet@48975
  1223
    by (auto simp add: card_of_Plus_Times)
blanchet@48975
  1224
    moreover have "|A \<times> B| =o |A|"
blanchet@48975
  1225
    using assms * by (simp add: card_of_Times_infinite_simps)
blanchet@48975
  1226
    ultimately have "|A <+> B| \<le>o |A|" using ordLeq_ordIso_trans by metis
blanchet@48975
  1227
    thus ?thesis using card_of_Plus1 ordIso_iff_ordLeq by blast
blanchet@48975
  1228
  qed
blanchet@48975
  1229
qed
blanchet@48975
  1230
blanchet@48975
  1231
blanchet@48975
  1232
lemma card_of_Plus_infinite2:
blanchet@48975
  1233
assumes INF: "infinite A" and LEQ: "|B| \<le>o |A|"
blanchet@48975
  1234
shows "|B <+> A| =o |A|"
blanchet@48975
  1235
using assms card_of_Plus_commute card_of_Plus_infinite1
blanchet@48975
  1236
ordIso_equivalence by blast
blanchet@48975
  1237
blanchet@48975
  1238
blanchet@48975
  1239
lemma card_of_Plus_infinite:
blanchet@48975
  1240
assumes INF: "infinite A" and LEQ: "|B| \<le>o |A|"
blanchet@48975
  1241
shows "|A <+> B| =o |A| \<and> |B <+> A| =o |A|"
blanchet@48975
  1242
using assms by (auto simp: card_of_Plus_infinite1 card_of_Plus_infinite2)
blanchet@48975
  1243
blanchet@48975
  1244
blanchet@48975
  1245
corollary Card_order_Plus_infinite:
blanchet@48975
  1246
assumes INF: "infinite(Field r)" and CARD: "Card_order r" and
blanchet@48975
  1247
        LEQ: "p \<le>o r"
blanchet@48975
  1248
shows "| (Field r) <+> (Field p) | =o r \<and> | (Field p) <+> (Field r) | =o r"
blanchet@48975
  1249
proof-
blanchet@48975
  1250
  have "| Field r <+> Field p | =o | Field r | \<and>
blanchet@48975
  1251
        | Field p <+> Field r | =o | Field r |"
blanchet@48975
  1252
  using assms by (simp add: card_of_Plus_infinite card_of_mono2)
blanchet@48975
  1253
  thus ?thesis
blanchet@48975
  1254
  using assms card_of_Field_ordIso[of r]
blanchet@48975
  1255
        ordIso_transitive[of "|Field r <+> Field p|"]
blanchet@48975
  1256
        ordIso_transitive[of _ "|Field r|"] by blast
blanchet@48975
  1257
qed
blanchet@48975
  1258
blanchet@48975
  1259
blanchet@48975
  1260
subsection {* The cardinal $\omega$ and the finite cardinals  *}
blanchet@48975
  1261
blanchet@48975
  1262
blanchet@48975
  1263
text{* The cardinal $\omega$, of natural numbers, shall be the standard non-strict
blanchet@48975
  1264
order relation on
blanchet@48975
  1265
@{text "nat"}, that we abbreviate by @{text "natLeq"}.  The finite cardinals
blanchet@48975
  1266
shall be the restrictions of these relations to the numbers smaller than
blanchet@48975
  1267
fixed numbers @{text "n"}, that we abbreviate by @{text "natLeq_on n"}.  *}
blanchet@48975
  1268
blanchet@48975
  1269
abbreviation "(natLeq::(nat * nat) set) \<equiv> {(x,y). x \<le> y}"
blanchet@48975
  1270
abbreviation "(natLess::(nat * nat) set) \<equiv> {(x,y). x < y}"
blanchet@48975
  1271
blanchet@48975
  1272
abbreviation natLeq_on :: "nat \<Rightarrow> (nat * nat) set"
blanchet@48975
  1273
where "natLeq_on n \<equiv> {(x,y). x < n \<and> y < n \<and> x \<le> y}"
blanchet@48975
  1274
blanchet@48975
  1275
lemma infinite_cartesian_product:
blanchet@48975
  1276
assumes "infinite A" "infinite B"
blanchet@48975
  1277
shows "infinite (A \<times> B)"
blanchet@48975
  1278
proof
blanchet@48975
  1279
  assume "finite (A \<times> B)"
blanchet@48975
  1280
  from assms(1) have "A \<noteq> {}" by auto
blanchet@48975
  1281
  with `finite (A \<times> B)` have "finite B" using finite_cartesian_productD2 by auto
blanchet@48975
  1282
  with assms(2) show False by simp
blanchet@48975
  1283
qed
blanchet@48975
  1284
blanchet@48975
  1285
blanchet@48975
  1286
subsubsection {* First as well-orders *}
blanchet@48975
  1287
blanchet@48975
  1288
blanchet@48975
  1289
lemma Field_natLeq: "Field natLeq = (UNIV::nat set)"
blanchet@48975
  1290
by(unfold Field_def, auto)
blanchet@48975
  1291
blanchet@48975
  1292
blanchet@48975
  1293
lemma natLeq_Refl: "Refl natLeq"
blanchet@48975
  1294
unfolding refl_on_def Field_def by auto
blanchet@48975
  1295
blanchet@48975
  1296
blanchet@48975
  1297
lemma natLeq_trans: "trans natLeq"
blanchet@48975
  1298
unfolding trans_def by auto
blanchet@48975
  1299
blanchet@48975
  1300
blanchet@48975
  1301
lemma natLeq_Preorder: "Preorder natLeq"
blanchet@48975
  1302
unfolding preorder_on_def
blanchet@48975
  1303
by (auto simp add: natLeq_Refl natLeq_trans)
blanchet@48975
  1304
blanchet@48975
  1305
blanchet@48975
  1306
lemma natLeq_antisym: "antisym natLeq"
blanchet@48975
  1307
unfolding antisym_def by auto
blanchet@48975
  1308
blanchet@48975
  1309
blanchet@48975
  1310
lemma natLeq_Partial_order: "Partial_order natLeq"
blanchet@48975
  1311
unfolding partial_order_on_def
blanchet@48975
  1312
by (auto simp add: natLeq_Preorder natLeq_antisym)
blanchet@48975
  1313
blanchet@48975
  1314
blanchet@48975
  1315
lemma natLeq_Total: "Total natLeq"
blanchet@48975
  1316
unfolding total_on_def by auto
blanchet@48975
  1317
blanchet@48975
  1318
blanchet@48975
  1319
lemma natLeq_Linear_order: "Linear_order natLeq"
blanchet@48975
  1320
unfolding linear_order_on_def
blanchet@48975
  1321
by (auto simp add: natLeq_Partial_order natLeq_Total)
blanchet@48975
  1322
blanchet@48975
  1323
blanchet@48975
  1324
lemma natLeq_natLess_Id: "natLess = natLeq - Id"
blanchet@48975
  1325
by auto
blanchet@48975
  1326
blanchet@48975
  1327
blanchet@48975
  1328
lemma natLeq_Well_order: "Well_order natLeq"
blanchet@48975
  1329
unfolding well_order_on_def
blanchet@48975
  1330
using natLeq_Linear_order wf_less natLeq_natLess_Id by auto
blanchet@48975
  1331
blanchet@48975
  1332
blanchet@48975
  1333
lemma closed_nat_set_iff:
blanchet@48975
  1334
assumes "\<forall>(m::nat) n. n \<in> A \<and> m \<le> n \<longrightarrow> m \<in> A"
blanchet@48975
  1335
shows "A = UNIV \<or> (\<exists>n. A = {0 ..< n})"
blanchet@48975
  1336
proof-
blanchet@48975
  1337
  {assume "A \<noteq> UNIV" hence "\<exists>n. n \<notin> A" by blast
blanchet@48975
  1338
   moreover obtain n where n_def: "n = (LEAST n. n \<notin> A)" by blast
blanchet@48975
  1339
   ultimately have 1: "n \<notin> A \<and> (\<forall>m. m < n \<longrightarrow> m \<in> A)"
blanchet@48975
  1340
   using LeastI_ex[of "\<lambda> n. n \<notin> A"] n_def Least_le[of "\<lambda> n. n \<notin> A"] by fastforce
blanchet@48975
  1341
   have "A = {0 ..< n}"
blanchet@48975
  1342
   proof(auto simp add: 1)
blanchet@48975
  1343
     fix m assume *: "m \<in> A"
blanchet@48975
  1344
     {assume "n \<le> m" with assms * have "n \<in> A" by blast
blanchet@48975
  1345
      hence False using 1 by auto
blanchet@48975
  1346
     }
blanchet@48975
  1347
     thus "m < n" by fastforce
blanchet@48975
  1348
   qed
blanchet@48975
  1349
   hence "\<exists>n. A = {0 ..< n}" by blast
blanchet@48975
  1350
  }
blanchet@48975
  1351
  thus ?thesis by blast
blanchet@48975
  1352
qed
blanchet@48975
  1353
blanchet@48975
  1354
blanchet@48975
  1355
lemma Field_natLeq_on: "Field (natLeq_on n) = {0 ..< n}"
blanchet@48975
  1356
unfolding Field_def by auto
blanchet@48975
  1357
blanchet@48975
  1358
blanchet@48975
  1359
lemma natLeq_underS_less: "rel.underS natLeq n = {0 ..< n}"
blanchet@48975
  1360
unfolding rel.underS_def by auto
blanchet@48975
  1361
blanchet@48975
  1362
blanchet@48975
  1363
lemma Restr_natLeq: "Restr natLeq {0 ..< n} = natLeq_on n"
blanchet@48975
  1364
by auto
blanchet@48975
  1365
blanchet@48975
  1366
blanchet@48975
  1367
lemma Restr_natLeq2:
blanchet@48975
  1368
"Restr natLeq (rel.underS natLeq n) = natLeq_on n"
blanchet@48975
  1369
by (auto simp add: Restr_natLeq natLeq_underS_less)
blanchet@48975
  1370
blanchet@48975
  1371
blanchet@48975
  1372
lemma natLeq_on_Well_order: "Well_order(natLeq_on n)"
blanchet@48975
  1373
using Restr_natLeq[of n] natLeq_Well_order
blanchet@48975
  1374
      Well_order_Restr[of natLeq "{0..<n}"] by auto
blanchet@48975
  1375
blanchet@48975
  1376
blanchet@48975
  1377
corollary natLeq_on_well_order_on: "well_order_on {0 ..< n} (natLeq_on n)"
blanchet@48975
  1378
using natLeq_on_Well_order Field_natLeq_on by auto
blanchet@48975
  1379
blanchet@48975
  1380
blanchet@48975
  1381
lemma natLeq_on_wo_rel: "wo_rel(natLeq_on n)"
blanchet@48975
  1382
unfolding wo_rel_def using natLeq_on_Well_order .
blanchet@48975
  1383
blanchet@48975
  1384
blanchet@48975
  1385
lemma natLeq_on_ofilter_less_eq:
blanchet@48975
  1386
"n \<le> m \<Longrightarrow> wo_rel.ofilter (natLeq_on m) {0 ..< n}"
blanchet@48975
  1387
by (auto simp add: natLeq_on_wo_rel wo_rel.ofilter_def,
blanchet@48975
  1388
    simp add: Field_natLeq_on, unfold rel.under_def, auto)
blanchet@48975
  1389
blanchet@48975
  1390
blanchet@48975
  1391
lemma natLeq_on_ofilter_iff:
blanchet@48975
  1392
"wo_rel.ofilter (natLeq_on m) A = (\<exists>n \<le> m. A = {0 ..< n})"
blanchet@48975
  1393
proof(rule iffI)
blanchet@48975
  1394
  assume *: "wo_rel.ofilter (natLeq_on m) A"
blanchet@48975
  1395
  hence 1: "A \<le> {0..<m}"
blanchet@48975
  1396
  by (auto simp add: natLeq_on_wo_rel wo_rel.ofilter_def rel.under_def Field_natLeq_on)
blanchet@48975
  1397
  hence "\<forall>n1 n2. n2 \<in> A \<and> n1 \<le> n2 \<longrightarrow> n1 \<in> A"
blanchet@48975
  1398
  using * by(fastforce simp add: natLeq_on_wo_rel wo_rel.ofilter_def rel.under_def)
blanchet@48975
  1399
  hence "A = UNIV \<or> (\<exists>n. A = {0 ..< n})" using closed_nat_set_iff by blast
blanchet@48975
  1400
  thus "\<exists>n \<le> m. A = {0 ..< n}" using 1 atLeastLessThan_less_eq by blast
blanchet@48975
  1401
next
blanchet@48975
  1402
  assume "(\<exists>n\<le>m. A = {0 ..< n})"
blanchet@48975
  1403
  thus "wo_rel.ofilter (natLeq_on m) A" by (auto simp add: natLeq_on_ofilter_less_eq)
blanchet@48975
  1404
qed
blanchet@48975
  1405
blanchet@48975
  1406
blanchet@48975
  1407
blanchet@48975
  1408
subsubsection {* Then as cardinals *}
blanchet@48975
  1409
blanchet@48975
  1410
blanchet@48975
  1411
lemma natLeq_Card_order: "Card_order natLeq"
blanchet@48975
  1412
proof(auto simp add: natLeq_Well_order
blanchet@48975
  1413
      Card_order_iff_Restr_underS Restr_natLeq2, simp add:  Field_natLeq)
blanchet@48975
  1414
  fix n have "finite(Field (natLeq_on n))"
blanchet@48975
  1415
  unfolding Field_natLeq_on by auto
blanchet@48975
  1416
  moreover have "infinite(UNIV::nat set)" by auto
blanchet@48975
  1417
  ultimately show "natLeq_on n <o |UNIV::nat set|"
blanchet@48975
  1418
  using finite_ordLess_infinite[of "natLeq_on n" "|UNIV::nat set|"]
blanchet@48975
  1419
        Field_card_of[of "UNIV::nat set"]
blanchet@48975
  1420
        card_of_Well_order[of "UNIV::nat set"] natLeq_on_Well_order[of n] by auto
blanchet@48975
  1421
qed
blanchet@48975
  1422
blanchet@48975
  1423
blanchet@48975
  1424
corollary card_of_Field_natLeq:
blanchet@48975
  1425
"|Field natLeq| =o natLeq"
blanchet@48975
  1426
using Field_natLeq natLeq_Card_order Card_order_iff_ordIso_card_of[of natLeq]
blanchet@48975
  1427
      ordIso_symmetric[of natLeq] by blast
blanchet@48975
  1428
blanchet@48975
  1429
blanchet@48975
  1430
corollary card_of_nat:
blanchet@48975
  1431
"|UNIV::nat set| =o natLeq"
blanchet@48975
  1432
using Field_natLeq card_of_Field_natLeq by auto
blanchet@48975
  1433
blanchet@48975
  1434
blanchet@48975
  1435
corollary infinite_iff_natLeq_ordLeq:
blanchet@48975
  1436
"infinite A = ( natLeq \<le>o |A| )"
blanchet@48975
  1437
using infinite_iff_card_of_nat[of A] card_of_nat
blanchet@48975
  1438
      ordIso_ordLeq_trans ordLeq_ordIso_trans ordIso_symmetric by blast
blanchet@48975
  1439
blanchet@48975
  1440
blanchet@48975
  1441
corollary finite_iff_ordLess_natLeq:
blanchet@48975
  1442
"finite A = ( |A| <o natLeq)"
blanchet@48975
  1443
using infinite_iff_natLeq_ordLeq not_ordLeq_iff_ordLess
blanchet@48975
  1444
      card_of_Well_order natLeq_Well_order by blast
blanchet@48975
  1445
blanchet@48975
  1446
blanchet@48975
  1447
lemma ordIso_natLeq_on_imp_finite:
blanchet@48975
  1448
"|A| =o natLeq_on n \<Longrightarrow> finite A"
blanchet@48975
  1449
unfolding ordIso_def iso_def[abs_def]
blanchet@48975
  1450
by (auto simp: Field_natLeq_on bij_betw_finite Field_card_of)
blanchet@48975
  1451
blanchet@48975
  1452
blanchet@48975
  1453
lemma natLeq_on_Card_order: "Card_order (natLeq_on n)"
blanchet@48975
  1454
proof(unfold card_order_on_def,
blanchet@48975
  1455
      auto simp add: natLeq_on_Well_order, simp add: Field_natLeq_on)
blanchet@48975
  1456
  fix r assume "well_order_on {0..<n} r"
blanchet@48975
  1457
  thus "natLeq_on n \<le>o r"
blanchet@48975
  1458
  using finite_atLeastLessThan natLeq_on_well_order_on
blanchet@48975
  1459
        finite_well_order_on_ordIso ordIso_iff_ordLeq by blast
blanchet@48975
  1460
qed
blanchet@48975
  1461
blanchet@48975
  1462
blanchet@48975
  1463
corollary card_of_Field_natLeq_on:
blanchet@48975
  1464
"|Field (natLeq_on n)| =o natLeq_on n"
blanchet@48975
  1465
using Field_natLeq_on natLeq_on_Card_order
blanchet@48975
  1466
      Card_order_iff_ordIso_card_of[of "natLeq_on n"]
blanchet@48975
  1467
      ordIso_symmetric[of "natLeq_on n"] by blast
blanchet@48975
  1468
blanchet@48975
  1469
blanchet@48975
  1470
corollary card_of_less:
blanchet@48975
  1471
"|{0 ..< n}| =o natLeq_on n"
blanchet@48975
  1472
using Field_natLeq_on card_of_Field_natLeq_on by auto
blanchet@48975
  1473
blanchet@48975
  1474
blanchet@48975
  1475
lemma natLeq_on_ordLeq_less_eq:
blanchet@48975
  1476
"((natLeq_on m) \<le>o (natLeq_on n)) = (m \<le> n)"
blanchet@48975
  1477
proof
blanchet@48975
  1478
  assume "natLeq_on m \<le>o natLeq_on n"
blanchet@48975
  1479
  then obtain f where "inj_on f {0..<m} \<and> f ` {0..<m} \<le> {0..<n}"
traytel@51764
  1480
  unfolding ordLeq_def using
traytel@51764
  1481
    embed_inj_on[OF natLeq_on_Well_order[of m], of "natLeq_on n", unfolded Field_natLeq_on]
traytel@51764
  1482
     embed_Field[OF natLeq_on_Well_order[of m], of "natLeq_on n", unfolded Field_natLeq_on] by blast
blanchet@48975
  1483
  thus "m \<le> n" using atLeastLessThan_less_eq2 by blast
blanchet@48975
  1484
next
blanchet@48975
  1485
  assume "m \<le> n"
blanchet@48975
  1486
  hence "inj_on id {0..<m} \<and> id ` {0..<m} \<le> {0..<n}" unfolding inj_on_def by auto
blanchet@48975
  1487
  hence "|{0..<m}| \<le>o |{0..<n}|" using card_of_ordLeq by blast
blanchet@48975
  1488
  thus "natLeq_on m \<le>o natLeq_on n"
blanchet@48975
  1489
  using card_of_less ordIso_ordLeq_trans ordLeq_ordIso_trans ordIso_symmetric by blast
blanchet@48975
  1490
qed
blanchet@48975
  1491
blanchet@48975
  1492
blanchet@48975
  1493
lemma natLeq_on_ordLeq_less:
blanchet@48975
  1494
"((natLeq_on m) <o (natLeq_on n)) = (m < n)"
blanchet@48975
  1495
using not_ordLeq_iff_ordLess[of "natLeq_on m" "natLeq_on n"]
blanchet@48975
  1496
natLeq_on_Well_order natLeq_on_ordLeq_less_eq by auto
blanchet@48975
  1497
blanchet@48975
  1498
blanchet@48975
  1499
blanchet@54475
  1500
subsubsection {* "Backward compatibility" with the numeric cardinal operator for finite sets *}
blanchet@48975
  1501
blanchet@48975
  1502
blanchet@48975
  1503
lemma finite_card_of_iff_card2:
blanchet@48975
  1504
assumes FIN: "finite A" and FIN': "finite B"
blanchet@48975
  1505
shows "( |A| \<le>o |B| ) = (card A \<le> card B)"
blanchet@48975
  1506
using assms card_of_ordLeq[of A B] inj_on_iff_card_le[of A B] by blast
blanchet@48975
  1507
blanchet@48975
  1508
blanchet@48975
  1509
lemma finite_imp_card_of_natLeq_on:
blanchet@48975
  1510
assumes "finite A"
blanchet@48975
  1511
shows "|A| =o natLeq_on (card A)"
blanchet@48975
  1512
proof-
blanchet@48975
  1513
  obtain h where "bij_betw h A {0 ..< card A}"
blanchet@48975
  1514
  using assms ex_bij_betw_finite_nat by blast
blanchet@48975
  1515
  thus ?thesis using card_of_ordIso card_of_less ordIso_equivalence by blast
blanchet@48975
  1516
qed
blanchet@48975
  1517
blanchet@48975
  1518
blanchet@48975
  1519
lemma finite_iff_card_of_natLeq_on:
blanchet@48975
  1520
"finite A = (\<exists>n. |A| =o natLeq_on n)"
blanchet@48975
  1521
using finite_imp_card_of_natLeq_on[of A]
blanchet@48975
  1522
by(auto simp add: ordIso_natLeq_on_imp_finite)
blanchet@48975
  1523
blanchet@48975
  1524
blanchet@48975
  1525
blanchet@48975
  1526
subsection {* The successor of a cardinal *}
blanchet@48975
  1527
blanchet@48975
  1528
blanchet@48975
  1529
text{* First we define @{text "isCardSuc r r'"}, the notion of @{text "r'"}
blanchet@48975
  1530
being a successor cardinal of @{text "r"}. Although the definition does
blanchet@48975
  1531
not require @{text "r"} to be a cardinal, only this case will be meaningful.  *}
blanchet@48975
  1532
blanchet@48975
  1533
blanchet@48975
  1534
definition isCardSuc :: "'a rel \<Rightarrow> 'a set rel \<Rightarrow> bool"
blanchet@48975
  1535
where
blanchet@48975
  1536
"isCardSuc r r' \<equiv>
blanchet@48975
  1537
 Card_order r' \<and> r <o r' \<and>
blanchet@48975
  1538
 (\<forall>(r''::'a set rel). Card_order r'' \<and> r <o r'' \<longrightarrow> r' \<le>o r'')"
blanchet@48975
  1539
blanchet@48975
  1540
blanchet@48975
  1541
text{* Now we introduce the cardinal-successor operator @{text "cardSuc"},
blanchet@48975
  1542
by picking {\em some} cardinal-order relation fulfilling @{text "isCardSuc"}.
blanchet@48975
  1543
Again, the picked item shall be proved unique up to order-isomorphism. *}
blanchet@48975
  1544
blanchet@48975
  1545
blanchet@48975
  1546
definition cardSuc :: "'a rel \<Rightarrow> 'a set rel"
blanchet@48975
  1547
where
blanchet@48975
  1548
"cardSuc r \<equiv> SOME r'. isCardSuc r r'"
blanchet@48975
  1549
blanchet@48975
  1550
blanchet@48975
  1551
lemma exists_minim_Card_order:
blanchet@48975
  1552
"\<lbrakk>R \<noteq> {}; \<forall>r \<in> R. Card_order r\<rbrakk> \<Longrightarrow> \<exists>r \<in> R. \<forall>r' \<in> R. r \<le>o r'"
blanchet@48975
  1553
unfolding card_order_on_def using exists_minim_Well_order by blast
blanchet@48975
  1554
blanchet@48975
  1555
blanchet@48975
  1556
lemma exists_isCardSuc:
blanchet@48975
  1557
assumes "Card_order r"
blanchet@48975
  1558
shows "\<exists>r'. isCardSuc r r'"
blanchet@48975
  1559
proof-
blanchet@48975
  1560
  let ?R = "{(r'::'a set rel). Card_order r' \<and> r <o r'}"
blanchet@48975
  1561
  have "|Pow(Field r)| \<in> ?R \<and> (\<forall>r \<in> ?R. Card_order r)" using assms
blanchet@48975
  1562
  by (simp add: card_of_Card_order Card_order_Pow)
blanchet@48975
  1563
  then obtain r where "r \<in> ?R \<and> (\<forall>r' \<in> ?R. r \<le>o r')"
blanchet@48975
  1564
  using exists_minim_Card_order[of ?R] by blast
blanchet@48975
  1565
  thus ?thesis unfolding isCardSuc_def by auto
blanchet@48975
  1566
qed
blanchet@48975
  1567
blanchet@48975
  1568
blanchet@48975
  1569
lemma cardSuc_isCardSuc:
blanchet@48975
  1570
assumes "Card_order r"
blanchet@48975
  1571
shows "isCardSuc r (cardSuc r)"
blanchet@48975
  1572
unfolding cardSuc_def using assms
blanchet@48975
  1573
by (simp add: exists_isCardSuc someI_ex)
blanchet@48975
  1574
blanchet@48975
  1575
blanchet@48975
  1576
lemma cardSuc_Card_order:
blanchet@48975
  1577
"Card_order r \<Longrightarrow> Card_order(cardSuc r)"
blanchet@48975
  1578
using cardSuc_isCardSuc unfolding isCardSuc_def by blast
blanchet@48975
  1579
blanchet@48975
  1580
blanchet@48975
  1581
lemma cardSuc_greater:
blanchet@48975
  1582
"Card_order r \<Longrightarrow> r <o cardSuc r"
blanchet@48975
  1583
using cardSuc_isCardSuc unfolding isCardSuc_def by blast
blanchet@48975
  1584
blanchet@48975
  1585
blanchet@48975
  1586
lemma cardSuc_ordLeq:
blanchet@48975
  1587
"Card_order r \<Longrightarrow> r \<le>o cardSuc r"
blanchet@48975
  1588
using cardSuc_greater ordLeq_iff_ordLess_or_ordIso by blast
blanchet@48975
  1589
blanchet@48975
  1590
blanchet@48975
  1591
text{* The minimality property of @{text "cardSuc"} originally present in its definition
blanchet@48975
  1592
is local to the type @{text "'a set rel"}, i.e., that of @{text "cardSuc r"}:  *}
blanchet@48975
  1593
blanchet@48975
  1594
lemma cardSuc_least_aux:
blanchet@48975
  1595
"\<lbrakk>Card_order (r::'a rel); Card_order (r'::'a set rel); r <o r'\<rbrakk> \<Longrightarrow> cardSuc r \<le>o r'"
blanchet@48975
  1596
using cardSuc_isCardSuc unfolding isCardSuc_def by blast
blanchet@48975
  1597
blanchet@48975
  1598
blanchet@48975
  1599
text{* But from this we can infer general minimality: *}
blanchet@48975
  1600
blanchet@48975
  1601
lemma cardSuc_least:
blanchet@48975
  1602
assumes CARD: "Card_order r" and CARD': "Card_order r'" and LESS: "r <o r'"
blanchet@48975
  1603
shows "cardSuc r \<le>o r'"
blanchet@48975
  1604
proof-
blanchet@48975
  1605
  let ?p = "cardSuc r"
blanchet@48975
  1606
  have 0: "Well_order ?p \<and> Well_order r'"
blanchet@48975
  1607
  using assms cardSuc_Card_order unfolding card_order_on_def by blast
blanchet@48975
  1608
  {assume "r' <o ?p"
blanchet@48975
  1609
   then obtain r'' where 1: "Field r'' < Field ?p" and 2: "r' =o r'' \<and> r'' <o ?p"
blanchet@48975
  1610
   using internalize_ordLess[of r' ?p] by blast
blanchet@48975
  1611
   (*  *)
blanchet@48975
  1612
   have "Card_order r''" using CARD' Card_order_ordIso2 2 by blast
blanchet@48975
  1613
   moreover have "r <o r''" using LESS 2 ordLess_ordIso_trans by blast
blanchet@48975
  1614
   ultimately have "?p \<le>o r''" using cardSuc_least_aux CARD by blast
blanchet@48975
  1615
   hence False using 2 not_ordLess_ordLeq by blast
blanchet@48975
  1616
  }
blanchet@48975
  1617
  thus ?thesis using 0 ordLess_or_ordLeq by blast
blanchet@48975
  1618
qed
blanchet@48975
  1619
blanchet@48975
  1620
blanchet@48975
  1621
lemma cardSuc_ordLess_ordLeq:
blanchet@48975
  1622
assumes CARD: "Card_order r" and CARD': "Card_order r'"
blanchet@48975
  1623
shows "(r <o r') = (cardSuc r \<le>o r')"
blanchet@48975
  1624
proof(auto simp add: assms cardSuc_least)
blanchet@48975
  1625
  assume "cardSuc r \<le>o r'"
blanchet@48975
  1626
  thus "r <o r'" using assms cardSuc_greater ordLess_ordLeq_trans by blast
blanchet@48975
  1627
qed
blanchet@48975
  1628
blanchet@48975
  1629
blanchet@48975
  1630
lemma cardSuc_ordLeq_ordLess:
blanchet@48975
  1631
assumes CARD: "Card_order r" and CARD': "Card_order r'"
blanchet@48975
  1632
shows "(r' <o cardSuc r) = (r' \<le>o r)"
blanchet@48975
  1633
proof-
blanchet@48975
  1634
  have "Well_order r \<and> Well_order r'"
blanchet@48975
  1635
  using assms unfolding card_order_on_def by auto
blanchet@48975
  1636
  moreover have "Well_order(cardSuc r)"
blanchet@48975
  1637
  using assms cardSuc_Card_order card_order_on_def by blast
blanchet@48975
  1638
  ultimately show ?thesis
blanchet@48975
  1639
  using assms cardSuc_ordLess_ordLeq[of r r']
blanchet@48975
  1640
  not_ordLeq_iff_ordLess[of r r'] not_ordLeq_iff_ordLess[of r' "cardSuc r"] by blast
blanchet@48975
  1641
qed
blanchet@48975
  1642
blanchet@48975
  1643
blanchet@48975
  1644
lemma cardSuc_mono_ordLeq:
blanchet@48975
  1645
assumes CARD: "Card_order r" and CARD': "Card_order r'"
blanchet@48975
  1646
shows "(cardSuc r \<le>o cardSuc r') = (r \<le>o r')"
blanchet@48975
  1647
using assms cardSuc_ordLeq_ordLess cardSuc_ordLess_ordLeq cardSuc_Card_order by blast
blanchet@48975
  1648
blanchet@48975
  1649
blanchet@48975
  1650
lemma cardSuc_invar_ordIso:
blanchet@48975
  1651
assumes CARD: "Card_order r" and CARD': "Card_order r'"
blanchet@48975
  1652
shows "(cardSuc r =o cardSuc r') = (r =o r')"
blanchet@48975
  1653
proof-
blanchet@48975
  1654
  have 0: "Well_order r \<and> Well_order r' \<and> Well_order(cardSuc r) \<and> Well_order(cardSuc r')"
blanchet@48975
  1655
  using assms by (simp add: card_order_on_well_order_on cardSuc_Card_order)
blanchet@48975
  1656
  thus ?thesis
blanchet@48975
  1657
  using ordIso_iff_ordLeq[of r r'] ordIso_iff_ordLeq
blanchet@48975
  1658
  using cardSuc_mono_ordLeq[of r r'] cardSuc_mono_ordLeq[of r' r] assms by blast
blanchet@48975
  1659
qed
blanchet@48975
  1660
blanchet@48975
  1661
blanchet@48975
  1662
lemma cardSuc_natLeq_on_Suc:
blanchet@48975
  1663
"cardSuc(natLeq_on n) =o natLeq_on(Suc n)"
blanchet@48975
  1664
proof-
blanchet@48975
  1665
  obtain r r' p where r_def: "r = natLeq_on n" and
blanchet@48975
  1666
                      r'_def: "r' = cardSuc(natLeq_on n)"  and
blanchet@48975
  1667
                      p_def: "p = natLeq_on(Suc n)" by blast
blanchet@48975
  1668
  (* Preliminary facts:  *)
blanchet@48975
  1669
  have CARD: "Card_order r \<and> Card_order r' \<and> Card_order p" unfolding r_def r'_def p_def
blanchet@48975
  1670
  using cardSuc_ordLess_ordLeq natLeq_on_Card_order cardSuc_Card_order by blast
blanchet@48975
  1671
  hence WELL: "Well_order r \<and> Well_order r' \<and>  Well_order p"
blanchet@48975
  1672
  unfolding card_order_on_def by force
blanchet@48975
  1673
  have FIELD: "Field r = {0..<n} \<and> Field p = {0..<(Suc n)}"
blanchet@48975
  1674
  unfolding r_def p_def Field_natLeq_on by simp
blanchet@48975
  1675
  hence FIN: "finite (Field r)" by force
blanchet@48975
  1676
  have "r <o r'" using CARD unfolding r_def r'_def using cardSuc_greater by blast
blanchet@48975
  1677
  hence "|Field r| <o r'" using CARD card_of_Field_ordIso ordIso_ordLess_trans by blast
blanchet@48975
  1678
  hence LESS: "|Field r| <o |Field r'|"
blanchet@48975
  1679
  using CARD card_of_Field_ordIso ordLess_ordIso_trans ordIso_symmetric by blast
blanchet@48975
  1680
  (* Main proof: *)
blanchet@48975
  1681
  have "r' \<le>o p" using CARD unfolding r_def r'_def p_def
blanchet@48975
  1682
  using natLeq_on_ordLeq_less cardSuc_ordLess_ordLeq by blast
blanchet@48975
  1683
  moreover have "p \<le>o r'"
blanchet@48975
  1684
  proof-
blanchet@48975
  1685
    {assume "r' <o p"
blanchet@48975
  1686
     then obtain f where 0: "embedS r' p f" unfolding ordLess_def by force
blanchet@48975
  1687
     let ?q = "Restr p (f ` Field r')"
blanchet@48975
  1688
     have 1: "embed r' p f" using 0 unfolding embedS_def by force
blanchet@48975
  1689
     hence 2: "f ` Field r' < {0..<(Suc n)}"
blanchet@48975
  1690
     using WELL FIELD 0 by (auto simp add: embedS_iff)
blanchet@48975
  1691
     have "wo_rel.ofilter p (f ` Field r')" using embed_Field_ofilter 1 WELL by blast
blanchet@48975
  1692
     then obtain m where "m \<le> Suc n" and 3: "f ` (Field r') = {0..<m}"
blanchet@48975
  1693
     unfolding p_def by (auto simp add: natLeq_on_ofilter_iff)
blanchet@48975
  1694
     hence 4: "m \<le> n" using 2 by force
blanchet@48975
  1695
     (*  *)
blanchet@48975
  1696
     have "bij_betw f (Field r') (f ` (Field r'))"
blanchet@48975
  1697
     using 1 WELL embed_inj_on unfolding bij_betw_def by force
blanchet@48975
  1698
     moreover have "finite(f ` (Field r'))" using 3 finite_atLeastLessThan[of 0 m] by force
blanchet@48975
  1699
     ultimately have 5: "finite (Field r') \<and> card(Field r') = card (f ` (Field r'))"
blanchet@48975
  1700
     using bij_betw_same_card bij_betw_finite by metis
blanchet@48975
  1701
     hence "card(Field r') \<le> card(Field r)" using 3 4 FIELD by force
blanchet@48975
  1702
     hence "|Field r'| \<le>o |Field r|" using FIN 5 finite_card_of_iff_card2 by blast
blanchet@48975
  1703
     hence False using LESS not_ordLess_ordLeq by auto
blanchet@48975
  1704
    }
blanchet@48975
  1705
    thus ?thesis using WELL CARD by (fastforce simp: not_ordLess_iff_ordLeq)
blanchet@48975
  1706
  qed
blanchet@48975
  1707
  ultimately show ?thesis using ordIso_iff_ordLeq unfolding r'_def p_def by blast
blanchet@48975
  1708
qed
blanchet@48975
  1709
blanchet@48975
  1710
blanchet@48975
  1711
lemma card_of_cardSuc_finite:
blanchet@48975
  1712
"finite(Field(cardSuc |A| )) = finite A"
blanchet@48975
  1713
proof
blanchet@48975
  1714
  assume *: "finite (Field (cardSuc |A| ))"
blanchet@48975
  1715
  have 0: "|Field(cardSuc |A| )| =o cardSuc |A|"
blanchet@48975
  1716
  using card_of_Card_order cardSuc_Card_order card_of_Field_ordIso by blast
blanchet@48975
  1717
  hence "|A| \<le>o |Field(cardSuc |A| )|"
blanchet@48975
  1718
  using card_of_Card_order[of A] cardSuc_ordLeq[of "|A|"] ordIso_symmetric
blanchet@48975
  1719
  ordLeq_ordIso_trans by blast
blanchet@48975
  1720
  thus "finite A" using * card_of_ordLeq_finite by blast
blanchet@48975
  1721
next
blanchet@48975
  1722
  assume "finite A"
blanchet@48975
  1723
  then obtain n where "|A| =o natLeq_on n" using finite_iff_card_of_natLeq_on by blast
blanchet@48975
  1724
  hence "cardSuc |A| =o cardSuc(natLeq_on n)"
blanchet@48975
  1725
  using card_of_Card_order cardSuc_invar_ordIso natLeq_on_Card_order by blast
blanchet@48975
  1726
  hence "cardSuc |A| =o natLeq_on(Suc n)"
blanchet@48975
  1727
  using cardSuc_natLeq_on_Suc ordIso_transitive by blast
blanchet@48975
  1728
  hence "cardSuc |A| =o |{0..<(Suc n)}|" using card_of_less ordIso_equivalence by blast
blanchet@48975
  1729
  moreover have "|Field (cardSuc |A| ) | =o cardSuc |A|"
blanchet@48975
  1730
  using card_of_Field_ordIso cardSuc_Card_order card_of_Card_order by blast
blanchet@48975
  1731
  ultimately have "|Field (cardSuc |A| ) | =o |{0..<(Suc n)}|"
blanchet@48975
  1732
  using ordIso_equivalence by blast
blanchet@48975
  1733
  thus "finite (Field (cardSuc |A| ))"
blanchet@48975
  1734
  using card_of_ordIso_finite finite_atLeastLessThan by blast
blanchet@48975
  1735
qed
blanchet@48975
  1736
blanchet@48975
  1737
blanchet@48975
  1738
lemma cardSuc_finite:
blanchet@48975
  1739
assumes "Card_order r"
blanchet@48975
  1740
shows "finite (Field (cardSuc r)) = finite (Field r)"
blanchet@48975
  1741
proof-
blanchet@48975
  1742
  let ?A = "Field r"
blanchet@48975
  1743
  have "|?A| =o r" using assms by (simp add: card_of_Field_ordIso)
blanchet@48975
  1744
  hence "cardSuc |?A| =o cardSuc r" using assms
blanchet@48975
  1745
  by (simp add: card_of_Card_order cardSuc_invar_ordIso)
blanchet@48975
  1746
  moreover have "|Field (cardSuc |?A| ) | =o cardSuc |?A|"
blanchet@48975
  1747
  by (simp add: card_of_card_order_on Field_card_of card_of_Field_ordIso cardSuc_Card_order)
blanchet@48975
  1748
  moreover
blanchet@48975
  1749
  {have "|Field (cardSuc r) | =o cardSuc r"
blanchet@48975
  1750
   using assms by (simp add: card_of_Field_ordIso cardSuc_Card_order)
blanchet@48975
  1751
   hence "cardSuc r =o |Field (cardSuc r) |"
blanchet@48975
  1752
   using ordIso_symmetric by blast
blanchet@48975
  1753
  }
blanchet@48975
  1754
  ultimately have "|Field (cardSuc |?A| ) | =o |Field (cardSuc r) |"
blanchet@48975
  1755
  using ordIso_transitive by blast
blanchet@48975
  1756
  hence "finite (Field (cardSuc |?A| )) = finite (Field (cardSuc r))"
blanchet@48975
  1757
  using card_of_ordIso_finite by blast
blanchet@48975
  1758
  thus ?thesis by (simp only: card_of_cardSuc_finite)
blanchet@48975
  1759
qed
blanchet@48975
  1760
blanchet@48975
  1761
blanchet@54475
  1762
lemma card_of_Plus_ordLess_infinite:
blanchet@54475
  1763
assumes INF: "infinite C" and
blanchet@54475
  1764
        LESS1: "|A| <o |C|" and LESS2: "|B| <o |C|"
blanchet@54475
  1765
shows "|A <+> B| <o |C|"
blanchet@54475
  1766
proof(cases "A = {} \<or> B = {}")
blanchet@54475
  1767
  assume Case1: "A = {} \<or> B = {}"
blanchet@54475
  1768
  hence "|A| =o |A <+> B| \<or> |B| =o |A <+> B|"
blanchet@54475
  1769
  using card_of_Plus_empty1 card_of_Plus_empty2 by blast
blanchet@54475
  1770
  hence "|A <+> B| =o |A| \<or> |A <+> B| =o |B|"
blanchet@54475
  1771
  using ordIso_symmetric[of "|A|"] ordIso_symmetric[of "|B|"] by blast
blanchet@54475
  1772
  thus ?thesis using LESS1 LESS2
blanchet@54475
  1773
       ordIso_ordLess_trans[of "|A <+> B|" "|A|"]
blanchet@54475
  1774
       ordIso_ordLess_trans[of "|A <+> B|" "|B|"] by blast
blanchet@54475
  1775
next
blanchet@54475
  1776
  assume Case2: "\<not>(A = {} \<or> B = {})"
blanchet@54475
  1777
  {assume *: "|C| \<le>o |A <+> B|"
blanchet@54475
  1778
   hence "infinite (A <+> B)" using INF card_of_ordLeq_finite by blast
blanchet@54475
  1779
   hence 1: "infinite A \<or> infinite B" using finite_Plus by blast
blanchet@54475
  1780
   {assume Case21: "|A| \<le>o |B|"
blanchet@54475
  1781
    hence "infinite B" using 1 card_of_ordLeq_finite by blast
blanchet@54475
  1782
    hence "|A <+> B| =o |B|" using Case2 Case21
blanchet@54475
  1783
    by (auto simp add: card_of_Plus_infinite)
blanchet@54475
  1784
    hence False using LESS2 not_ordLess_ordLeq * ordLeq_ordIso_trans by blast
blanchet@54475
  1785
   }
blanchet@54475
  1786
   moreover
blanchet@54475
  1787
   {assume Case22: "|B| \<le>o |A|"
blanchet@54475
  1788
    hence "infinite A" using 1 card_of_ordLeq_finite by blast
blanchet@54475
  1789
    hence "|A <+> B| =o |A|" using Case2 Case22
blanchet@54475
  1790
    by (auto simp add: card_of_Plus_infinite)
blanchet@54475
  1791
    hence False using LESS1 not_ordLess_ordLeq * ordLeq_ordIso_trans by blast
blanchet@54475
  1792
   }
blanchet@54475
  1793
   ultimately have False using ordLeq_total card_of_Well_order[of A]
blanchet@54475
  1794
   card_of_Well_order[of B] by blast
blanchet@54475
  1795
  }
blanchet@54475
  1796
  thus ?thesis using ordLess_or_ordLeq[of "|A <+> B|" "|C|"]
blanchet@54475
  1797
  card_of_Well_order[of "A <+> B"] card_of_Well_order[of "C"] by auto
blanchet@54475
  1798
qed
blanchet@54475
  1799
blanchet@54475
  1800
blanchet@54475
  1801
lemma card_of_Plus_ordLess_infinite_Field:
blanchet@54475
  1802
assumes INF: "infinite (Field r)" and r: "Card_order r" and
blanchet@54475
  1803
        LESS1: "|A| <o r" and LESS2: "|B| <o r"
blanchet@54475
  1804
shows "|A <+> B| <o r"
blanchet@54475
  1805
proof-
blanchet@54475
  1806
  let ?C  = "Field r"
blanchet@54475
  1807
  have 1: "r =o |?C| \<and> |?C| =o r" using r card_of_Field_ordIso
blanchet@54475
  1808
  ordIso_symmetric by blast
blanchet@54475
  1809
  hence "|A| <o |?C|"  "|B| <o |?C|"
blanchet@54475
  1810
  using LESS1 LESS2 ordLess_ordIso_trans by blast+
blanchet@54475
  1811
  hence  "|A <+> B| <o |?C|" using INF
blanchet@54475
  1812
  card_of_Plus_ordLess_infinite by blast
blanchet@54475
  1813
  thus ?thesis using 1 ordLess_ordIso_trans by blast
blanchet@54475
  1814
qed
blanchet@54475
  1815
blanchet@54475
  1816
blanchet@48975
  1817
lemma card_of_Plus_ordLeq_infinite_Field:
blanchet@48975
  1818
assumes r: "infinite (Field r)" and A: "|A| \<le>o r" and B: "|B| \<le>o r"
blanchet@48975
  1819
and c: "Card_order r"
blanchet@48975
  1820
shows "|A <+> B| \<le>o r"
blanchet@48975
  1821
proof-
blanchet@48975
  1822
  let ?r' = "cardSuc r"
blanchet@48975
  1823
  have "Card_order ?r' \<and> infinite (Field ?r')" using assms
blanchet@48975
  1824
  by (simp add: cardSuc_Card_order cardSuc_finite)
blanchet@48975
  1825
  moreover have "|A| <o ?r'" and "|B| <o ?r'" using A B c
blanchet@48975
  1826
  by (auto simp: card_of_card_order_on Field_card_of cardSuc_ordLeq_ordLess)
blanchet@48975
  1827
  ultimately have "|A <+> B| <o ?r'"
blanchet@48975
  1828
  using card_of_Plus_ordLess_infinite_Field by blast
blanchet@48975
  1829
  thus ?thesis using c r
blanchet@48975
  1830
  by (simp add: card_of_card_order_on Field_card_of cardSuc_ordLeq_ordLess)
blanchet@48975
  1831
qed
blanchet@48975
  1832
blanchet@48975
  1833
blanchet@48975
  1834
lemma card_of_Un_ordLeq_infinite_Field:
blanchet@48975
  1835
assumes C: "infinite (Field r)" and A: "|A| \<le>o r" and B: "|B| \<le>o r"
blanchet@48975
  1836
and "Card_order r"
blanchet@48975
  1837
shows "|A Un B| \<le>o r"
blanchet@48975
  1838
using assms card_of_Plus_ordLeq_infinite_Field card_of_Un_Plus_ordLeq
blanchet@48975
  1839
ordLeq_transitive by blast
blanchet@48975
  1840
blanchet@48975
  1841
blanchet@48975
  1842
blanchet@48975
  1843
subsection {* Regular cardinals *}
blanchet@48975
  1844
blanchet@48975
  1845
blanchet@48975
  1846
definition cofinal where
blanchet@48975
  1847
"cofinal A r \<equiv>
blanchet@48975
  1848
 ALL a : Field r. EX b : A. a \<noteq> b \<and> (a,b) : r"
blanchet@48975
  1849
blanchet@48975
  1850
blanchet@48975
  1851
definition regular where
blanchet@48975
  1852
"regular r \<equiv>
blanchet@48975
  1853
 ALL K. K \<le> Field r \<and> cofinal K r \<longrightarrow> |K| =o r"
blanchet@48975
  1854
blanchet@48975
  1855
blanchet@48975
  1856
definition relChain where
blanchet@48975
  1857
"relChain r As \<equiv>
blanchet@48975
  1858
 ALL i j. (i,j) \<in> r \<longrightarrow> As i \<le> As j"
blanchet@48975
  1859
blanchet@48975
  1860
lemma regular_UNION:
blanchet@48975
  1861
assumes r: "Card_order r"   "regular r"
blanchet@48975
  1862
and As: "relChain r As"
blanchet@48975
  1863
and Bsub: "B \<le> (UN i : Field r. As i)"
blanchet@48975
  1864
and cardB: "|B| <o r"
blanchet@48975
  1865
shows "EX i : Field r. B \<le> As i"
blanchet@48975
  1866
proof-
blanchet@48975
  1867
  let ?phi = "%b j. j : Field r \<and> b : As j"
blanchet@48975
  1868
  have "ALL b : B. EX j. ?phi b j" using Bsub by blast
blanchet@48975
  1869
  then obtain f where f: "!! b. b : B \<Longrightarrow> ?phi b (f b)"
blanchet@48975
  1870
  using bchoice[of B ?phi] by blast
blanchet@48975
  1871
  let ?K = "f ` B"
blanchet@48975
  1872
  {assume 1: "!! i. i : Field r \<Longrightarrow> ~ B \<le> As i"
blanchet@48975
  1873
   have 2: "cofinal ?K r"
blanchet@48975
  1874
   unfolding cofinal_def proof auto
blanchet@48975
  1875
     fix i assume i: "i : Field r"
blanchet@48975
  1876
     with 1 obtain b where b: "b : B \<and> b \<notin> As i" by blast
blanchet@48975
  1877
     hence "i \<noteq> f b \<and> ~ (f b,i) : r"
blanchet@48975
  1878
     using As f unfolding relChain_def by auto
blanchet@48975
  1879
     hence "i \<noteq> f b \<and> (i, f b) : r" using r
blanchet@48975
  1880
     unfolding card_order_on_def well_order_on_def linear_order_on_def
blanchet@48975
  1881
     total_on_def using i f b by auto
blanchet@48975
  1882
     with b show "\<exists>b\<in>B. i \<noteq> f b \<and> (i, f b) \<in> r" by blast
blanchet@48975
  1883
   qed
blanchet@48975
  1884
   moreover have "?K \<le> Field r" using f by blast
blanchet@48975
  1885
   ultimately have "|?K| =o r" using 2 r unfolding regular_def by blast
blanchet@48975
  1886
   moreover
blanchet@48975
  1887
   {
blanchet@48975
  1888
    have "|?K| <=o |B|" using card_of_image .
blanchet@48975
  1889
    hence "|?K| <o r" using cardB ordLeq_ordLess_trans by blast
blanchet@48975
  1890
   }
blanchet@48975
  1891
   ultimately have False using not_ordLess_ordIso by blast
blanchet@48975
  1892
  }
blanchet@48975
  1893
  thus ?thesis by blast
blanchet@48975
  1894
qed
blanchet@48975
  1895
blanchet@48975
  1896
blanchet@48975
  1897
lemma infinite_cardSuc_regular:
blanchet@48975
  1898
assumes r_inf: "infinite (Field r)" and r_card: "Card_order r"
blanchet@48975
  1899
shows "regular (cardSuc r)"
blanchet@48975
  1900
proof-
blanchet@48975
  1901
  let ?r' = "cardSuc r"
blanchet@48975
  1902
  have r': "Card_order ?r'"
blanchet@48975
  1903
  "!! p. Card_order p \<longrightarrow> (p \<le>o r) = (p <o ?r')"
blanchet@48975
  1904
  using r_card by (auto simp: cardSuc_Card_order cardSuc_ordLeq_ordLess)
blanchet@48975
  1905
  show ?thesis
blanchet@48975
  1906
  unfolding regular_def proof auto
blanchet@48975
  1907
    fix K assume 1: "K \<le> Field ?r'" and 2: "cofinal K ?r'"
blanchet@48975
  1908
    hence "|K| \<le>o |Field ?r'|" by (simp only: card_of_mono1)
blanchet@48975
  1909
    also have 22: "|Field ?r'| =o ?r'"
blanchet@48975
  1910
    using r' by (simp add: card_of_Field_ordIso[of ?r'])
blanchet@48975
  1911
    finally have "|K| \<le>o ?r'" .
blanchet@48975
  1912
    moreover
blanchet@48975
  1913
    {let ?L = "UN j : K. rel.underS ?r' j"
blanchet@48975
  1914
     let ?J = "Field r"
blanchet@48975
  1915
     have rJ: "r =o |?J|"
blanchet@48975
  1916
     using r_card card_of_Field_ordIso ordIso_symmetric by blast
blanchet@48975
  1917
     assume "|K| <o ?r'"
blanchet@48975
  1918
     hence "|K| <=o r" using r' card_of_Card_order[of K] by blast
blanchet@48975
  1919
     hence "|K| \<le>o |?J|" using rJ ordLeq_ordIso_trans by blast
blanchet@48975
  1920
     moreover
blanchet@48975
  1921
     {have "ALL j : K. |rel.underS ?r' j| <o ?r'"
blanchet@48975
  1922
      using r' 1 by (auto simp: card_of_underS)
blanchet@48975
  1923
      hence "ALL j : K. |rel.underS ?r' j| \<le>o r"
blanchet@48975
  1924
      using r' card_of_Card_order by blast
blanchet@48975
  1925
      hence "ALL j : K. |rel.underS ?r' j| \<le>o |?J|"
blanchet@48975
  1926
      using rJ ordLeq_ordIso_trans by blast
blanchet@48975
  1927
     }
blanchet@48975
  1928
     ultimately have "|?L| \<le>o |?J|"
blanchet@48975
  1929
     using r_inf card_of_UNION_ordLeq_infinite by blast
blanchet@48975
  1930
     hence "|?L| \<le>o r" using rJ ordIso_symmetric ordLeq_ordIso_trans by blast
blanchet@48975
  1931
     hence "|?L| <o ?r'" using r' card_of_Card_order by blast
blanchet@48975
  1932
     moreover
blanchet@48975
  1933
     {
blanchet@48975
  1934
      have "Field ?r' \<le> ?L"
blanchet@48975
  1935
      using 2 unfolding rel.underS_def cofinal_def by auto
blanchet@48975
  1936
      hence "|Field ?r'| \<le>o |?L|" by (simp add: card_of_mono1)
blanchet@48975
  1937
      hence "?r' \<le>o |?L|"
blanchet@48975
  1938
      using 22 ordIso_ordLeq_trans ordIso_symmetric by blast
blanchet@48975
  1939
     }
blanchet@48975
  1940
     ultimately have "|?L| <o |?L|" using ordLess_ordLeq_trans by blast
blanchet@48975
  1941
     hence False using ordLess_irreflexive by blast
blanchet@48975
  1942
    }
blanchet@48975
  1943
    ultimately show "|K| =o ?r'"
blanchet@48975
  1944
    unfolding ordLeq_iff_ordLess_or_ordIso by blast
blanchet@48975
  1945
  qed
blanchet@48975
  1946
qed
blanchet@48975
  1947
blanchet@48975
  1948
lemma cardSuc_UNION:
blanchet@48975
  1949
assumes r: "Card_order r" and "infinite (Field r)"
blanchet@48975
  1950
and As: "relChain (cardSuc r) As"
blanchet@48975
  1951
and Bsub: "B \<le> (UN i : Field (cardSuc r). As i)"
blanchet@48975
  1952
and cardB: "|B| <=o r"
blanchet@48975
  1953
shows "EX i : Field (cardSuc r). B \<le> As i"
blanchet@48975
  1954
proof-
blanchet@48975
  1955
  let ?r' = "cardSuc r"
blanchet@48975
  1956
  have "Card_order ?r' \<and> |B| <o ?r'"
blanchet@48975
  1957
  using r cardB cardSuc_ordLeq_ordLess cardSuc_Card_order
blanchet@48975
  1958
  card_of_Card_order by blast
blanchet@48975
  1959
  moreover have "regular ?r'"
blanchet@48975
  1960
  using assms by(simp add: infinite_cardSuc_regular)
blanchet@48975
  1961
  ultimately show ?thesis
blanchet@48975
  1962
  using As Bsub cardB regular_UNION by blast
blanchet@48975
  1963
qed
blanchet@48975
  1964
blanchet@48975
  1965
blanchet@48975
  1966
subsection {* Others *}
blanchet@48975
  1967
blanchet@48975
  1968
(* function space *)
blanchet@48975
  1969
definition Func where
traytel@52545
  1970
"Func A B = {f . (\<forall> a \<in> A. f a \<in> B) \<and> (\<forall> a. a \<notin> A \<longrightarrow> f a = undefined)}"
blanchet@48975
  1971
blanchet@48975
  1972
lemma Func_empty:
traytel@52545
  1973
"Func {} B = {\<lambda>x. undefined}"
blanchet@48975
  1974
unfolding Func_def by auto
blanchet@48975
  1975
blanchet@48975
  1976
lemma Func_elim:
blanchet@48975
  1977
assumes "g \<in> Func A B" and "a \<in> A"
traytel@52545
  1978
shows "\<exists> b. b \<in> B \<and> g a = b"
traytel@52545
  1979
using assms unfolding Func_def by (cases "g a = undefined") auto
blanchet@48975
  1980
blanchet@48975
  1981
definition curr where
traytel@52545
  1982
"curr A f \<equiv> \<lambda> a. if a \<in> A then \<lambda>b. f (a,b) else undefined"
blanchet@48975
  1983
blanchet@48975
  1984
lemma curr_in:
blanchet@48975
  1985
assumes f: "f \<in> Func (A <*> B) C"
blanchet@48975
  1986
shows "curr A f \<in> Func A (Func B C)"
blanchet@48975
  1987
using assms unfolding curr_def Func_def by auto
blanchet@48975
  1988
blanchet@48975
  1989
lemma curr_inj:
blanchet@48975
  1990
assumes "f1 \<in> Func (A <*> B) C" and "f2 \<in> Func (A <*> B) C"
blanchet@48975
  1991
shows "curr A f1 = curr A f2 \<longleftrightarrow> f1 = f2"
blanchet@48975
  1992
proof safe
blanchet@48975
  1993
  assume c: "curr A f1 = curr A f2"
blanchet@48975
  1994
  show "f1 = f2"
blanchet@48975
  1995
  proof (rule ext, clarify)
blanchet@48975
  1996
    fix a b show "f1 (a, b) = f2 (a, b)"
blanchet@48975
  1997
    proof (cases "(a,b) \<in> A <*> B")
blanchet@48975
  1998
      case False
traytel@52545
  1999
      thus ?thesis using assms unfolding Func_def by auto
blanchet@48975
  2000
    next
blanchet@48975
  2001
      case True hence a: "a \<in> A" and b: "b \<in> B" by auto
blanchet@48975
  2002
      thus ?thesis
traytel@52545
  2003
      using c unfolding curr_def fun_eq_iff by(elim allE[of _ a]) simp
blanchet@48975
  2004
    qed
blanchet@48975
  2005
  qed
blanchet@48975
  2006
qed
blanchet@48975
  2007
blanchet@48975
  2008
lemma curr_surj:
blanchet@48975
  2009
assumes "g \<in> Func A (Func B C)"
blanchet@48975
  2010
shows "\<exists> f \<in> Func (A <*> B) C. curr A f = g"
blanchet@48975
  2011
proof
traytel@52545
  2012
  let ?f = "\<lambda> ab. if fst ab \<in> A \<and> snd ab \<in> B then g (fst ab) (snd ab) else undefined"
blanchet@48975
  2013
  show "curr A ?f = g"
blanchet@48975
  2014
  proof (rule ext)
blanchet@48975
  2015
    fix a show "curr A ?f a = g a"
blanchet@48975
  2016
    proof (cases "a \<in> A")
blanchet@48975
  2017
      case False
traytel@52545
  2018
      hence "g a = undefined" using assms unfolding Func_def by auto
blanchet@48975
  2019
      thus ?thesis unfolding curr_def using False by simp
blanchet@48975
  2020
    next
blanchet@48975
  2021
      case True
traytel@52545
  2022
      obtain g1 where "g1 \<in> Func B C" and "g a = g1"
blanchet@48975
  2023
      using assms using Func_elim[OF assms True] by blast
traytel@52545
  2024
      thus ?thesis using True unfolding Func_def curr_def by auto
blanchet@48975
  2025
    qed
blanchet@48975
  2026
  qed
traytel@52545
  2027
  show "?f \<in> Func (A <*> B) C" using assms unfolding Func_def mem_Collect_eq by auto
blanchet@48975
  2028
qed
blanchet@48975
  2029
traytel@52544
  2030
lemma bij_betw_curr:
blanchet@48975
  2031
"bij_betw (curr A) (Func (A <*> B) C) (Func A (Func B C))"
blanchet@48975
  2032
unfolding bij_betw_def inj_on_def image_def
blanchet@48975
  2033
using curr_in curr_inj curr_surj by blast
blanchet@48975
  2034
blanchet@48975
  2035
lemma card_of_Func_Times:
blanchet@48975
  2036
"|Func (A <*> B) C| =o |Func A (Func B C)|"
blanchet@48975
  2037
unfolding card_of_ordIso[symmetric]
traytel@52544
  2038
using bij_betw_curr by blast
blanchet@48975
  2039
blanchet@48975
  2040
definition Func_map where
traytel@52545
  2041
"Func_map B2 f1 f2 g b2 \<equiv> if b2 \<in> B2 then f1 (g (f2 b2)) else undefined"
blanchet@48975
  2042
blanchet@48975
  2043
lemma Func_map:
blanchet@48975
  2044
assumes g: "g \<in> Func A2 A1" and f1: "f1 ` A1 \<subseteq> B1" and f2: "f2 ` B2 \<subseteq> A2"
blanchet@48975
  2045
shows "Func_map B2 f1 f2 g \<in> Func B2 B1"
traytel@52545
  2046
using assms unfolding Func_def Func_map_def mem_Collect_eq by auto
blanchet@48975
  2047
blanchet@48975
  2048
lemma Func_non_emp:
blanchet@48975
  2049
assumes "B \<noteq> {}"
blanchet@48975
  2050
shows "Func A B \<noteq> {}"
blanchet@48975
  2051
proof-
blanchet@48975
  2052
  obtain b where b: "b \<in> B" using assms by auto
traytel@52545
  2053
  hence "(\<lambda> a. if a \<in> A then b else undefined) \<in> Func A B" unfolding Func_def by auto
blanchet@48975
  2054
  thus ?thesis by blast
blanchet@48975
  2055
qed
blanchet@48975
  2056
blanchet@48975
  2057
lemma Func_is_emp:
blanchet@48975
  2058
"Func A B = {} \<longleftrightarrow> A \<noteq> {} \<and> B = {}" (is "?L \<longleftrightarrow> ?R")
blanchet@48975
  2059
proof
blanchet@48975
  2060
  assume L: ?L
blanchet@48975
  2061
  moreover {assume "A = {}" hence False using L Func_empty by auto}
blanchet@48975
  2062
  moreover {assume "B \<noteq> {}" hence False using L Func_non_emp by metis}
blanchet@48975
  2063
  ultimately show ?R by blast
blanchet@48975
  2064
next
blanchet@48975
  2065
  assume R: ?R
blanchet@48975
  2066
  moreover
blanchet@48975
  2067
  {fix f assume "f \<in> Func A B"
blanchet@48975
  2068
   moreover obtain a where "a \<in> A" using R by blast
traytel@52545
  2069
   ultimately obtain b where "b \<in> B" unfolding Func_def by(cases "f a = undefined", force+)
blanchet@48975
  2070
   with R have False by auto
blanchet@48975
  2071
  }
blanchet@48975
  2072
  thus ?L by blast
blanchet@48975
  2073
qed
blanchet@48975
  2074
blanchet@48975
  2075
lemma Func_map_surj:
blanchet@48975
  2076
assumes B1: "f1 ` A1 = B1" and A2: "inj_on f2 B2" "f2 ` B2 \<subseteq> A2"
blanchet@48975
  2077
and B2A2: "B2 = {} \<Longrightarrow> A2 = {}"
blanchet@48975
  2078
shows "Func B2 B1 = Func_map B2 f1 f2 ` Func A2 A1"
blanchet@48975
  2079
proof(cases "B2 = {}")
blanchet@48975
  2080
  case True
traytel@52545
  2081
  thus ?thesis using B2A2 by (auto simp: Func_empty Func_map_def)
blanchet@48975
  2082
next
blanchet@48975
  2083
  case False note B2 = False
blanchet@48975
  2084
  show ?thesis
traytel@52545
  2085
  proof safe
traytel@52545
  2086
    fix h assume h: "h \<in> Func B2 B1"
traytel@52545
  2087
    def j1 \<equiv> "inv_into A1 f1"
traytel@52545
  2088
    have "\<forall> a2 \<in> f2 ` B2. \<exists> b2. b2 \<in> B2 \<and> f2 b2 = a2" by blast
traytel@52545
  2089
    then obtain k where k: "\<forall> a2 \<in> f2 ` B2. k a2 \<in> B2 \<and> f2 (k a2) = a2" by metis
traytel@52545
  2090
    {fix b2 assume b2: "b2 \<in> B2"
traytel@52545
  2091
     hence "f2 (k (f2 b2)) = f2 b2" using k A2(2) by auto
traytel@52545
  2092
     moreover have "k (f2 b2) \<in> B2" using b2 A2(2) k by auto
traytel@52545
  2093
     ultimately have "k (f2 b2) = b2" using b2 A2(1) unfolding inj_on_def by blast
traytel@52545
  2094
    } note kk = this
traytel@52545
  2095
    obtain b22 where b22: "b22 \<in> B2" using B2 by auto
traytel@52545
  2096
    def j2 \<equiv> "\<lambda> a2. if a2 \<in> f2 ` B2 then k a2 else b22"
traytel@52545
  2097
    have j2A2: "j2 ` A2 \<subseteq> B2" unfolding j2_def using k b22 by auto
traytel@52545
  2098
    have j2: "\<And> b2. b2 \<in> B2 \<Longrightarrow> j2 (f2 b2) = b2"
traytel@52545
  2099
    using kk unfolding j2_def by auto
traytel@52545
  2100
    def g \<equiv> "Func_map A2 j1 j2 h"
traytel@52545
  2101
    have "Func_map B2 f1 f2 g = h"
traytel@52545
  2102
    proof (rule ext)
traytel@52545
  2103
      fix b2 show "Func_map B2 f1 f2 g b2 = h b2"
traytel@52545
  2104
      proof(cases "b2 \<in> B2")
traytel@52545
  2105
        case True
blanchet@48975
  2106
        show ?thesis
traytel@52545
  2107
        proof (cases "h b2 = undefined")
traytel@52545
  2108
          case True
traytel@52545
  2109
          hence b1: "h b2 \<in> f1 ` A1" using h `b2 \<in> B2` unfolding B1 Func_def by auto