src/ZF/Cardinal.thy
author wenzelm
Sun Nov 09 17:04:14 2014 +0100 (2014-11-09)
changeset 58957 c9e744ea8a38
parent 58871 c399ae4b836f
child 59788 6f7b6adac439
permissions -rw-r--r--
proper context for match_tac etc.;
clasohm@1478
     1
(*  Title:      ZF/Cardinal.thy
clasohm@1478
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
lcp@435
     3
    Copyright   1994  University of Cambridge
paulson@13328
     4
*)
paulson@13221
     5
wenzelm@58871
     6
section{*Cardinal Numbers Without the Axiom of Choice*}
lcp@435
     7
krauss@26056
     8
theory Cardinal imports OrderType Finite Nat_ZF Sum begin
paulson@13221
     9
wenzelm@24893
    10
definition
lcp@435
    11
  (*least ordinal operator*)
wenzelm@24893
    12
   Least    :: "(i=>o) => i"    (binder "LEAST " 10)  where
paulson@46820
    13
     "Least(P) == THE i. Ord(i) & P(i) & (\<forall>j. j<i \<longrightarrow> ~P(j))"
lcp@435
    14
wenzelm@24893
    15
definition
wenzelm@24893
    16
  eqpoll   :: "[i,i] => o"     (infixl "eqpoll" 50)  where
paulson@46953
    17
    "A eqpoll B == \<exists>f. f \<in> bij(A,B)"
lcp@435
    18
wenzelm@24893
    19
definition
wenzelm@24893
    20
  lepoll   :: "[i,i] => o"     (infixl "lepoll" 50)  where
paulson@46953
    21
    "A lepoll B == \<exists>f. f \<in> inj(A,B)"
lcp@435
    22
wenzelm@24893
    23
definition
wenzelm@24893
    24
  lesspoll :: "[i,i] => o"     (infixl "lesspoll" 50)  where
paulson@13221
    25
    "A lesspoll B == A lepoll B & ~(A eqpoll B)"
lcp@832
    26
wenzelm@24893
    27
definition
wenzelm@24893
    28
  cardinal :: "i=>i"           ("|_|")  where
paulson@46847
    29
    "|A| == (LEAST i. i eqpoll A)"
lcp@435
    30
wenzelm@24893
    31
definition
wenzelm@24893
    32
  Finite   :: "i=>o"  where
paulson@46820
    33
    "Finite(A) == \<exists>n\<in>nat. A eqpoll n"
lcp@435
    34
wenzelm@24893
    35
definition
wenzelm@24893
    36
  Card     :: "i=>o"  where
paulson@13221
    37
    "Card(i) == (i = |i|)"
lcp@435
    38
wenzelm@21524
    39
notation (xsymbols)
wenzelm@21524
    40
  eqpoll    (infixl "\<approx>" 50) and
wenzelm@21524
    41
  lepoll    (infixl "\<lesssim>" 50) and
wenzelm@21524
    42
  lesspoll  (infixl "\<prec>" 50) and
wenzelm@21524
    43
  Least     (binder "\<mu>" 10)
paulson@13221
    44
paulson@46847
    45
notation (HTML)
wenzelm@21524
    46
  eqpoll    (infixl "\<approx>" 50) and
wenzelm@21524
    47
  Least     (binder "\<mu>" 10)
wenzelm@21524
    48
kleing@14565
    49
paulson@13357
    50
subsection{*The Schroeder-Bernstein Theorem*}
paulson@13357
    51
text{*See Davey and Priestly, page 106*}
paulson@13221
    52
paulson@13221
    53
(** Lemma: Banach's Decomposition Theorem **)
paulson@13221
    54
paulson@13221
    55
lemma decomp_bnd_mono: "bnd_mono(X, %W. X - g``(Y - f``W))"
paulson@13221
    56
by (rule bnd_monoI, blast+)
paulson@13221
    57
paulson@13221
    58
lemma Banach_last_equation:
paulson@46953
    59
    "g \<in> Y->X
paulson@46820
    60
     ==> g``(Y - f`` lfp(X, %W. X - g``(Y - f``W))) =
paulson@46820
    61
         X - lfp(X, %W. X - g``(Y - f``W))"
paulson@46820
    62
apply (rule_tac P = "%u. ?v = X-u"
paulson@13221
    63
       in decomp_bnd_mono [THEN lfp_unfold, THEN ssubst])
paulson@13221
    64
apply (simp add: double_complement  fun_is_rel [THEN image_subset])
paulson@13221
    65
done
paulson@13221
    66
paulson@13221
    67
lemma decomposition:
paulson@46953
    68
     "[| f \<in> X->Y;  g \<in> Y->X |] ==>
paulson@46820
    69
      \<exists>XA XB YA YB. (XA \<inter> XB = 0) & (XA \<union> XB = X) &
paulson@46820
    70
                      (YA \<inter> YB = 0) & (YA \<union> YB = Y) &
paulson@13221
    71
                      f``XA=YA & g``YB=XB"
paulson@13221
    72
apply (intro exI conjI)
paulson@13221
    73
apply (rule_tac [6] Banach_last_equation)
paulson@13221
    74
apply (rule_tac [5] refl)
paulson@46820
    75
apply (assumption |
paulson@13221
    76
       rule  Diff_disjoint Diff_partition fun_is_rel image_subset lfp_subset)+
paulson@13221
    77
done
paulson@13221
    78
paulson@13221
    79
lemma schroeder_bernstein:
paulson@46953
    80
    "[| f \<in> inj(X,Y);  g \<in> inj(Y,X) |] ==> \<exists>h. h \<in> bij(X,Y)"
paulson@46820
    81
apply (insert decomposition [of f X Y g])
paulson@13221
    82
apply (simp add: inj_is_fun)
paulson@13221
    83
apply (blast intro!: restrict_bij bij_disjoint_Un intro: bij_converse_bij)
paulson@46820
    84
(* The instantiation of exI to @{term"restrict(f,XA) \<union> converse(restrict(g,YB))"}
paulson@13221
    85
   is forced by the context!! *)
paulson@13221
    86
done
paulson@13221
    87
paulson@13221
    88
paulson@13221
    89
(** Equipollence is an equivalence relation **)
paulson@13221
    90
paulson@46953
    91
lemma bij_imp_eqpoll: "f \<in> bij(A,B) ==> A \<approx> B"
paulson@13221
    92
apply (unfold eqpoll_def)
paulson@13221
    93
apply (erule exI)
paulson@13221
    94
done
paulson@13221
    95
paulson@13221
    96
(*A eqpoll A*)
wenzelm@45602
    97
lemmas eqpoll_refl = id_bij [THEN bij_imp_eqpoll, simp]
paulson@13221
    98
paulson@13221
    99
lemma eqpoll_sym: "X \<approx> Y ==> Y \<approx> X"
paulson@13221
   100
apply (unfold eqpoll_def)
paulson@13221
   101
apply (blast intro: bij_converse_bij)
paulson@13221
   102
done
paulson@13221
   103
paulson@46841
   104
lemma eqpoll_trans [trans]:
paulson@13221
   105
    "[| X \<approx> Y;  Y \<approx> Z |] ==> X \<approx> Z"
paulson@13221
   106
apply (unfold eqpoll_def)
paulson@13221
   107
apply (blast intro: comp_bij)
paulson@13221
   108
done
paulson@13221
   109
paulson@13221
   110
(** Le-pollence is a partial ordering **)
paulson@13221
   111
paulson@13221
   112
lemma subset_imp_lepoll: "X<=Y ==> X \<lesssim> Y"
paulson@13221
   113
apply (unfold lepoll_def)
paulson@13221
   114
apply (rule exI)
paulson@13221
   115
apply (erule id_subset_inj)
paulson@13221
   116
done
paulson@13221
   117
wenzelm@45602
   118
lemmas lepoll_refl = subset_refl [THEN subset_imp_lepoll, simp]
paulson@13221
   119
wenzelm@45602
   120
lemmas le_imp_lepoll = le_imp_subset [THEN subset_imp_lepoll]
paulson@13221
   121
paulson@13221
   122
lemma eqpoll_imp_lepoll: "X \<approx> Y ==> X \<lesssim> Y"
paulson@13221
   123
by (unfold eqpoll_def bij_def lepoll_def, blast)
paulson@13221
   124
paulson@46841
   125
lemma lepoll_trans [trans]: "[| X \<lesssim> Y;  Y \<lesssim> Z |] ==> X \<lesssim> Z"
paulson@13221
   126
apply (unfold lepoll_def)
paulson@13221
   127
apply (blast intro: comp_inj)
paulson@13221
   128
done
paulson@13221
   129
paulson@46841
   130
lemma eq_lepoll_trans [trans]: "[| X \<approx> Y;  Y \<lesssim> Z |] ==> X \<lesssim> Z"
paulson@46953
   131
 by (blast intro: eqpoll_imp_lepoll lepoll_trans)
paulson@46841
   132
paulson@46841
   133
lemma lepoll_eq_trans [trans]: "[| X \<lesssim> Y;  Y \<approx> Z |] ==> X \<lesssim> Z"
paulson@46953
   134
 by (blast intro: eqpoll_imp_lepoll lepoll_trans)
paulson@46841
   135
paulson@13221
   136
(*Asymmetry law*)
paulson@13221
   137
lemma eqpollI: "[| X \<lesssim> Y;  Y \<lesssim> X |] ==> X \<approx> Y"
paulson@13221
   138
apply (unfold lepoll_def eqpoll_def)
paulson@13221
   139
apply (elim exE)
paulson@13221
   140
apply (rule schroeder_bernstein, assumption+)
paulson@13221
   141
done
paulson@13221
   142
paulson@13221
   143
lemma eqpollE:
paulson@13221
   144
    "[| X \<approx> Y; [| X \<lesssim> Y; Y \<lesssim> X |] ==> P |] ==> P"
paulson@46820
   145
by (blast intro: eqpoll_imp_lepoll eqpoll_sym)
paulson@13221
   146
paulson@46821
   147
lemma eqpoll_iff: "X \<approx> Y \<longleftrightarrow> X \<lesssim> Y & Y \<lesssim> X"
paulson@13221
   148
by (blast intro: eqpollI elim!: eqpollE)
paulson@13221
   149
paulson@13221
   150
lemma lepoll_0_is_0: "A \<lesssim> 0 ==> A = 0"
paulson@13221
   151
apply (unfold lepoll_def inj_def)
paulson@13221
   152
apply (blast dest: apply_type)
paulson@13221
   153
done
paulson@13221
   154
paulson@46820
   155
(*@{term"0 \<lesssim> Y"}*)
wenzelm@45602
   156
lemmas empty_lepollI = empty_subsetI [THEN subset_imp_lepoll]
paulson@13221
   157
paulson@46821
   158
lemma lepoll_0_iff: "A \<lesssim> 0 \<longleftrightarrow> A=0"
paulson@13221
   159
by (blast intro: lepoll_0_is_0 lepoll_refl)
paulson@13221
   160
paulson@46820
   161
lemma Un_lepoll_Un:
paulson@46820
   162
    "[| A \<lesssim> B; C \<lesssim> D; B \<inter> D = 0 |] ==> A \<union> C \<lesssim> B \<union> D"
paulson@13221
   163
apply (unfold lepoll_def)
paulson@13221
   164
apply (blast intro: inj_disjoint_Un)
paulson@13221
   165
done
paulson@13221
   166
paulson@13221
   167
(*A eqpoll 0 ==> A=0*)
wenzelm@45602
   168
lemmas eqpoll_0_is_0 = eqpoll_imp_lepoll [THEN lepoll_0_is_0]
paulson@13221
   169
paulson@46821
   170
lemma eqpoll_0_iff: "A \<approx> 0 \<longleftrightarrow> A=0"
paulson@13221
   171
by (blast intro: eqpoll_0_is_0 eqpoll_refl)
paulson@13221
   172
paulson@46820
   173
lemma eqpoll_disjoint_Un:
paulson@46820
   174
    "[| A \<approx> B;  C \<approx> D;  A \<inter> C = 0;  B \<inter> D = 0 |]
paulson@46820
   175
     ==> A \<union> C \<approx> B \<union> D"
paulson@13221
   176
apply (unfold eqpoll_def)
paulson@13221
   177
apply (blast intro: bij_disjoint_Un)
paulson@13221
   178
done
paulson@13221
   179
paulson@13221
   180
paulson@13356
   181
subsection{*lesspoll: contributions by Krzysztof Grabczewski *}
paulson@13221
   182
paulson@13221
   183
lemma lesspoll_not_refl: "~ (i \<prec> i)"
paulson@46820
   184
by (simp add: lesspoll_def)
paulson@13221
   185
paulson@13221
   186
lemma lesspoll_irrefl [elim!]: "i \<prec> i ==> P"
paulson@46820
   187
by (simp add: lesspoll_def)
paulson@13221
   188
paulson@13221
   189
lemma lesspoll_imp_lepoll: "A \<prec> B ==> A \<lesssim> B"
paulson@13221
   190
by (unfold lesspoll_def, blast)
paulson@13221
   191
paulson@46820
   192
lemma lepoll_well_ord: "[| A \<lesssim> B; well_ord(B,r) |] ==> \<exists>s. well_ord(A,s)"
paulson@13221
   193
apply (unfold lepoll_def)
paulson@13221
   194
apply (blast intro: well_ord_rvimage)
paulson@13221
   195
done
paulson@13221
   196
paulson@46821
   197
lemma lepoll_iff_leqpoll: "A \<lesssim> B \<longleftrightarrow> A \<prec> B | A \<approx> B"
paulson@13221
   198
apply (unfold lesspoll_def)
paulson@13221
   199
apply (blast intro!: eqpollI elim!: eqpollE)
paulson@13221
   200
done
paulson@13221
   201
paulson@46820
   202
lemma inj_not_surj_succ:
paulson@47042
   203
  assumes fi: "f \<in> inj(A, succ(m))" and fns: "f \<notin> surj(A, succ(m))" 
paulson@47042
   204
  shows "\<exists>f. f \<in> inj(A,m)"
paulson@47042
   205
proof -
paulson@47042
   206
  from fi [THEN inj_is_fun] fns 
paulson@47042
   207
  obtain y where y: "y \<in> succ(m)" "\<And>x. x\<in>A \<Longrightarrow> f ` x \<noteq> y"
paulson@47042
   208
    by (auto simp add: surj_def)
paulson@47042
   209
  show ?thesis
paulson@47042
   210
    proof 
paulson@47042
   211
      show "(\<lambda>z\<in>A. if f`z = m then y else f`z) \<in> inj(A, m)" using y fi
paulson@47042
   212
        by (simp add: inj_def) 
paulson@47042
   213
           (auto intro!: if_type [THEN lam_type] intro: Pi_type dest: apply_funtype)
paulson@47042
   214
      qed
paulson@47042
   215
qed
paulson@13221
   216
paulson@13221
   217
(** Variations on transitivity **)
paulson@13221
   218
paulson@46841
   219
lemma lesspoll_trans [trans]:
paulson@13221
   220
      "[| X \<prec> Y; Y \<prec> Z |] ==> X \<prec> Z"
paulson@13221
   221
apply (unfold lesspoll_def)
paulson@13221
   222
apply (blast elim!: eqpollE intro: eqpollI lepoll_trans)
paulson@13221
   223
done
paulson@13221
   224
paulson@46841
   225
lemma lesspoll_trans1 [trans]:
paulson@13221
   226
      "[| X \<lesssim> Y; Y \<prec> Z |] ==> X \<prec> Z"
paulson@13221
   227
apply (unfold lesspoll_def)
paulson@13221
   228
apply (blast elim!: eqpollE intro: eqpollI lepoll_trans)
paulson@13221
   229
done
paulson@13221
   230
paulson@46841
   231
lemma lesspoll_trans2 [trans]:
paulson@13221
   232
      "[| X \<prec> Y; Y \<lesssim> Z |] ==> X \<prec> Z"
paulson@13221
   233
apply (unfold lesspoll_def)
paulson@13221
   234
apply (blast elim!: eqpollE intro: eqpollI lepoll_trans)
paulson@13221
   235
done
paulson@13221
   236
paulson@46841
   237
lemma eq_lesspoll_trans [trans]:
paulson@46841
   238
      "[| X \<approx> Y; Y \<prec> Z |] ==> X \<prec> Z"
paulson@46953
   239
  by (blast intro: eqpoll_imp_lepoll lesspoll_trans1)
paulson@46841
   240
paulson@46841
   241
lemma lesspoll_eq_trans [trans]:
paulson@46841
   242
      "[| X \<prec> Y; Y \<approx> Z |] ==> X \<prec> Z"
paulson@46953
   243
  by (blast intro: eqpoll_imp_lepoll lesspoll_trans2)
paulson@46841
   244
paulson@13221
   245
paulson@13221
   246
(** LEAST -- the least number operator [from HOL/Univ.ML] **)
paulson@13221
   247
paulson@46820
   248
lemma Least_equality:
paulson@46847
   249
    "[| P(i);  Ord(i);  !!x. x<i ==> ~P(x) |] ==> (\<mu> x. P(x)) = i"
paulson@46820
   250
apply (unfold Least_def)
paulson@13221
   251
apply (rule the_equality, blast)
paulson@13221
   252
apply (elim conjE)
paulson@13221
   253
apply (erule Ord_linear_lt, assumption, blast+)
paulson@13221
   254
done
paulson@13221
   255
paulson@47016
   256
lemma LeastI: 
paulson@47016
   257
  assumes P: "P(i)" and i: "Ord(i)" shows "P(\<mu> x. P(x))"
paulson@47016
   258
proof -
paulson@47016
   259
  { from i have "P(i) \<Longrightarrow> P(\<mu> x. P(x))"
paulson@47016
   260
      proof (induct i rule: trans_induct)
paulson@47016
   261
        case (step i) 
paulson@47016
   262
        show ?case
paulson@47016
   263
          proof (cases "P(\<mu> a. P(a))")
paulson@47016
   264
            case True thus ?thesis .
paulson@47016
   265
          next
paulson@47016
   266
            case False
paulson@47016
   267
            hence "\<And>x. x \<in> i \<Longrightarrow> ~P(x)" using step
paulson@47016
   268
              by blast
paulson@47018
   269
            hence "(\<mu> a. P(a)) = i" using step
paulson@47018
   270
              by (blast intro: Least_equality ltD) 
paulson@47018
   271
            thus ?thesis using step.prems
paulson@47016
   272
              by simp 
paulson@47016
   273
          qed
paulson@47016
   274
      qed
paulson@47016
   275
  }
paulson@47016
   276
  thus ?thesis using P .
paulson@47016
   277
qed
paulson@13221
   278
paulson@47018
   279
text{*The proof is almost identical to the one above!*}
paulson@47018
   280
lemma Least_le: 
paulson@47018
   281
  assumes P: "P(i)" and i: "Ord(i)" shows "(\<mu> x. P(x)) \<le> i"
paulson@47018
   282
proof -
paulson@47018
   283
  { from i have "P(i) \<Longrightarrow> (\<mu> x. P(x)) \<le> i"
paulson@47018
   284
      proof (induct i rule: trans_induct)
paulson@47018
   285
        case (step i) 
paulson@47018
   286
        show ?case
paulson@47018
   287
          proof (cases "(\<mu> a. P(a)) \<le> i")
paulson@47018
   288
            case True thus ?thesis .
paulson@47018
   289
          next
paulson@47018
   290
            case False
paulson@47018
   291
            hence "\<And>x. x \<in> i \<Longrightarrow> ~ (\<mu> a. P(a)) \<le> i" using step
paulson@47018
   292
              by blast
paulson@47018
   293
            hence "(\<mu> a. P(a)) = i" using step
paulson@47018
   294
              by (blast elim: ltE intro: ltI Least_equality lt_trans1)
paulson@47018
   295
            thus ?thesis using step
paulson@47018
   296
              by simp 
paulson@47018
   297
          qed
paulson@47018
   298
      qed
paulson@47018
   299
  }
paulson@47018
   300
  thus ?thesis using P .
paulson@47018
   301
qed
paulson@13221
   302
paulson@13221
   303
(*LEAST really is the smallest*)
paulson@46847
   304
lemma less_LeastE: "[| P(i);  i < (\<mu> x. P(x)) |] ==> Q"
paulson@13221
   305
apply (rule Least_le [THEN [2] lt_trans2, THEN lt_irrefl], assumption+)
paulson@46820
   306
apply (simp add: lt_Ord)
paulson@13221
   307
done
paulson@13221
   308
paulson@13221
   309
(*Easier to apply than LeastI: conclusion has only one occurrence of P*)
paulson@13221
   310
lemma LeastI2:
paulson@46847
   311
    "[| P(i);  Ord(i);  !!j. P(j) ==> Q(j) |] ==> Q(\<mu> j. P(j))"
paulson@46820
   312
by (blast intro: LeastI )
paulson@13221
   313
paulson@13221
   314
(*If there is no such P then LEAST is vacuously 0*)
paulson@46820
   315
lemma Least_0:
paulson@46847
   316
    "[| ~ (\<exists>i. Ord(i) & P(i)) |] ==> (\<mu> x. P(x)) = 0"
paulson@13221
   317
apply (unfold Least_def)
paulson@13221
   318
apply (rule the_0, blast)
paulson@13221
   319
done
paulson@13221
   320
paulson@46847
   321
lemma Ord_Least [intro,simp,TC]: "Ord(\<mu> x. P(x))"
paulson@47042
   322
proof (cases "\<exists>i. Ord(i) & P(i)")
paulson@47042
   323
  case True 
paulson@47042
   324
  then obtain i where "P(i)" "Ord(i)"  by auto
paulson@47042
   325
  hence " (\<mu> x. P(x)) \<le> i"  by (rule Least_le) 
paulson@47042
   326
  thus ?thesis
paulson@47042
   327
    by (elim ltE)
paulson@47042
   328
next
paulson@47042
   329
  case False
paulson@47042
   330
  hence "(\<mu> x. P(x)) = 0"  by (rule Least_0)
paulson@47042
   331
  thus ?thesis
paulson@47042
   332
    by auto
paulson@47042
   333
qed
paulson@13221
   334
paulson@13221
   335
paulson@47042
   336
subsection{*Basic Properties of Cardinals*}
paulson@13221
   337
paulson@13221
   338
(*Not needed for simplification, but helpful below*)
paulson@46847
   339
lemma Least_cong: "(!!y. P(y) \<longleftrightarrow> Q(y)) ==> (\<mu> x. P(x)) = (\<mu> x. Q(x))"
paulson@13221
   340
by simp
paulson@13221
   341
paulson@46820
   342
(*Need AC to get @{term"X \<lesssim> Y ==> |X| \<le> |Y|"};  see well_ord_lepoll_imp_Card_le
paulson@13221
   343
  Converse also requires AC, but see well_ord_cardinal_eqE*)
paulson@13221
   344
lemma cardinal_cong: "X \<approx> Y ==> |X| = |Y|"
paulson@13221
   345
apply (unfold eqpoll_def cardinal_def)
paulson@13221
   346
apply (rule Least_cong)
paulson@13221
   347
apply (blast intro: comp_bij bij_converse_bij)
paulson@13221
   348
done
paulson@13221
   349
paulson@13221
   350
(*Under AC, the premise becomes trivial; one consequence is ||A|| = |A|*)
paulson@46820
   351
lemma well_ord_cardinal_eqpoll:
paulson@47018
   352
  assumes r: "well_ord(A,r)" shows "|A| \<approx> A"
paulson@47018
   353
proof (unfold cardinal_def)
paulson@47018
   354
  show "(\<mu> i. i \<approx> A) \<approx> A"
paulson@47018
   355
    by (best intro: LeastI Ord_ordertype ordermap_bij bij_converse_bij bij_imp_eqpoll r) 
paulson@47018
   356
qed
paulson@13221
   357
paulson@46820
   358
(* @{term"Ord(A) ==> |A| \<approx> A"} *)
paulson@13221
   359
lemmas Ord_cardinal_eqpoll = well_ord_Memrel [THEN well_ord_cardinal_eqpoll]
paulson@13221
   360
paulson@46841
   361
lemma Ord_cardinal_idem: "Ord(A) \<Longrightarrow> ||A|| = |A|"
paulson@46841
   362
 by (rule Ord_cardinal_eqpoll [THEN cardinal_cong])
paulson@46841
   363
paulson@13221
   364
lemma well_ord_cardinal_eqE:
paulson@46953
   365
  assumes woX: "well_ord(X,r)" and woY: "well_ord(Y,s)" and eq: "|X| = |Y|"
paulson@46847
   366
shows "X \<approx> Y"
paulson@46847
   367
proof -
paulson@46953
   368
  have "X \<approx> |X|" by (blast intro: well_ord_cardinal_eqpoll [OF woX] eqpoll_sym)
paulson@46847
   369
  also have "... = |Y|" by (rule eq)
paulson@46953
   370
  also have "... \<approx> Y" by (rule well_ord_cardinal_eqpoll [OF woY])
paulson@46847
   371
  finally show ?thesis .
paulson@46847
   372
qed
paulson@13221
   373
paulson@13221
   374
lemma well_ord_cardinal_eqpoll_iff:
paulson@46821
   375
     "[| well_ord(X,r);  well_ord(Y,s) |] ==> |X| = |Y| \<longleftrightarrow> X \<approx> Y"
paulson@13221
   376
by (blast intro: cardinal_cong well_ord_cardinal_eqE)
paulson@13221
   377
paulson@13221
   378
paulson@13221
   379
(** Observations from Kunen, page 28 **)
paulson@13221
   380
paulson@46820
   381
lemma Ord_cardinal_le: "Ord(i) ==> |i| \<le> i"
paulson@13221
   382
apply (unfold cardinal_def)
paulson@13221
   383
apply (erule eqpoll_refl [THEN Least_le])
paulson@13221
   384
done
paulson@13221
   385
paulson@13221
   386
lemma Card_cardinal_eq: "Card(K) ==> |K| = K"
paulson@13221
   387
apply (unfold Card_def)
paulson@13221
   388
apply (erule sym)
paulson@13221
   389
done
paulson@13221
   390
paulson@46841
   391
(* Could replace the  @{term"~(j \<approx> i)"}  by  @{term"~(i \<preceq> j)"}. *)
paulson@13221
   392
lemma CardI: "[| Ord(i);  !!j. j<i ==> ~(j \<approx> i) |] ==> Card(i)"
paulson@46820
   393
apply (unfold Card_def cardinal_def)
paulson@13221
   394
apply (subst Least_equality)
paulson@47018
   395
apply (blast intro: eqpoll_refl)+
paulson@13221
   396
done
paulson@13221
   397
paulson@13221
   398
lemma Card_is_Ord: "Card(i) ==> Ord(i)"
paulson@13221
   399
apply (unfold Card_def cardinal_def)
paulson@13221
   400
apply (erule ssubst)
paulson@13221
   401
apply (rule Ord_Least)
paulson@13221
   402
done
paulson@13221
   403
paulson@46820
   404
lemma Card_cardinal_le: "Card(K) ==> K \<le> |K|"
paulson@13221
   405
apply (simp (no_asm_simp) add: Card_is_Ord Card_cardinal_eq)
paulson@13221
   406
done
paulson@13221
   407
paulson@13221
   408
lemma Ord_cardinal [simp,intro!]: "Ord(|A|)"
paulson@13221
   409
apply (unfold cardinal_def)
paulson@13221
   410
apply (rule Ord_Least)
paulson@13221
   411
done
paulson@13221
   412
paulson@47018
   413
text{*The cardinals are the initial ordinals.*}
paulson@46821
   414
lemma Card_iff_initial: "Card(K) \<longleftrightarrow> Ord(K) & (\<forall>j. j<K \<longrightarrow> ~ j \<approx> K)"
paulson@47018
   415
proof -
paulson@47018
   416
  { fix j
paulson@47018
   417
    assume K: "Card(K)" "j \<approx> K"
paulson@47018
   418
    assume "j < K"
paulson@47018
   419
    also have "... = (\<mu> i. i \<approx> K)" using K
paulson@47018
   420
      by (simp add: Card_def cardinal_def)
paulson@47018
   421
    finally have "j < (\<mu> i. i \<approx> K)" .
paulson@47018
   422
    hence "False" using K
paulson@47018
   423
      by (best dest: less_LeastE) 
paulson@47018
   424
  }
paulson@47018
   425
  then show ?thesis
paulson@47042
   426
    by (blast intro: CardI Card_is_Ord) 
paulson@47018
   427
qed
paulson@13221
   428
paulson@13221
   429
lemma lt_Card_imp_lesspoll: "[| Card(a); i<a |] ==> i \<prec> a"
paulson@13221
   430
apply (unfold lesspoll_def)
paulson@13221
   431
apply (drule Card_iff_initial [THEN iffD1])
paulson@13221
   432
apply (blast intro!: leI [THEN le_imp_lepoll])
paulson@13221
   433
done
paulson@13221
   434
paulson@13221
   435
lemma Card_0: "Card(0)"
paulson@13221
   436
apply (rule Ord_0 [THEN CardI])
paulson@13221
   437
apply (blast elim!: ltE)
paulson@13221
   438
done
paulson@13221
   439
paulson@46820
   440
lemma Card_Un: "[| Card(K);  Card(L) |] ==> Card(K \<union> L)"
paulson@13221
   441
apply (rule Ord_linear_le [of K L])
paulson@13221
   442
apply (simp_all add: subset_Un_iff [THEN iffD1]  Card_is_Ord le_imp_subset
paulson@13221
   443
                     subset_Un_iff2 [THEN iffD1])
paulson@13221
   444
done
paulson@13221
   445
paulson@13221
   446
(*Infinite unions of cardinals?  See Devlin, Lemma 6.7, page 98*)
paulson@13221
   447
paulson@47101
   448
lemma Card_cardinal [iff]: "Card(|A|)"
paulson@46847
   449
proof (unfold cardinal_def)
paulson@46847
   450
  show "Card(\<mu> i. i \<approx> A)"
paulson@46847
   451
    proof (cases "\<exists>i. Ord (i) & i \<approx> A")
paulson@46847
   452
      case False thus ?thesis           --{*degenerate case*}
paulson@46847
   453
        by (simp add: Least_0 Card_0)
paulson@46847
   454
    next
paulson@46847
   455
      case True                         --{*real case: @{term A} is isomorphic to some ordinal*}
paulson@46847
   456
      then obtain i where i: "Ord(i)" "i \<approx> A" by blast
paulson@46953
   457
      show ?thesis
paulson@46847
   458
        proof (rule CardI [OF Ord_Least], rule notI)
paulson@46847
   459
          fix j
paulson@46953
   460
          assume j: "j < (\<mu> i. i \<approx> A)"
paulson@46847
   461
          assume "j \<approx> (\<mu> i. i \<approx> A)"
paulson@46847
   462
          also have "... \<approx> A" using i by (auto intro: LeastI)
paulson@46847
   463
          finally have "j \<approx> A" .
paulson@46953
   464
          thus False
paulson@46847
   465
            by (rule less_LeastE [OF _ j])
paulson@46847
   466
        qed
paulson@46847
   467
    qed
paulson@46847
   468
qed
paulson@13221
   469
paulson@13221
   470
(*Kunen's Lemma 10.5*)
paulson@46953
   471
lemma cardinal_eq_lemma:
paulson@46841
   472
  assumes i:"|i| \<le> j" and j: "j \<le> i" shows "|j| = |i|"
paulson@46841
   473
proof (rule eqpollI [THEN cardinal_cong])
paulson@46841
   474
  show "j \<lesssim> i" by (rule le_imp_lepoll [OF j])
paulson@46841
   475
next
paulson@46841
   476
  have Oi: "Ord(i)" using j by (rule le_Ord2)
paulson@46953
   477
  hence "i \<approx> |i|"
paulson@46953
   478
    by (blast intro: Ord_cardinal_eqpoll eqpoll_sym)
paulson@46953
   479
  also have "... \<lesssim> j"
paulson@46953
   480
    by (blast intro: le_imp_lepoll i)
paulson@46841
   481
  finally show "i \<lesssim> j" .
paulson@46841
   482
qed
paulson@13221
   483
paulson@46953
   484
lemma cardinal_mono:
paulson@46877
   485
  assumes ij: "i \<le> j" shows "|i| \<le> |j|"
paulson@47016
   486
using Ord_cardinal [of i] Ord_cardinal [of j]
paulson@47016
   487
proof (cases rule: Ord_linear_le)
paulson@47016
   488
  case le thus ?thesis .
paulson@46877
   489
next
paulson@47016
   490
  case ge
paulson@46877
   491
  have i: "Ord(i)" using ij
paulson@46953
   492
    by (simp add: lt_Ord)
paulson@46953
   493
  have ci: "|i| \<le> j"
paulson@46953
   494
    by (blast intro: Ord_cardinal_le ij le_trans i)
paulson@46953
   495
  have "|i| = ||i||"
paulson@46953
   496
    by (auto simp add: Ord_cardinal_idem i)
paulson@46877
   497
  also have "... = |j|"
paulson@47016
   498
    by (rule cardinal_eq_lemma [OF ge ci])
paulson@46877
   499
  finally have "|i| = |j|" .
paulson@46877
   500
  thus ?thesis by simp
paulson@46877
   501
qed
paulson@13221
   502
paulson@47016
   503
text{*Since we have @{term"|succ(nat)| \<le> |nat|"}, the converse of @{text cardinal_mono} fails!*}
paulson@13221
   504
lemma cardinal_lt_imp_lt: "[| |i| < |j|;  Ord(i);  Ord(j) |] ==> i < j"
paulson@13221
   505
apply (rule Ord_linear2 [of i j], assumption+)
paulson@13221
   506
apply (erule lt_trans2 [THEN lt_irrefl])
paulson@13221
   507
apply (erule cardinal_mono)
paulson@13221
   508
done
paulson@13221
   509
paulson@13221
   510
lemma Card_lt_imp_lt: "[| |i| < K;  Ord(i);  Card(K) |] ==> i < K"
paulson@46877
   511
  by (simp (no_asm_simp) add: cardinal_lt_imp_lt Card_is_Ord Card_cardinal_eq)
paulson@13221
   512
paulson@46821
   513
lemma Card_lt_iff: "[| Ord(i);  Card(K) |] ==> (|i| < K) \<longleftrightarrow> (i < K)"
paulson@13221
   514
by (blast intro: Card_lt_imp_lt Ord_cardinal_le [THEN lt_trans1])
paulson@13221
   515
paulson@46821
   516
lemma Card_le_iff: "[| Ord(i);  Card(K) |] ==> (K \<le> |i|) \<longleftrightarrow> (K \<le> i)"
paulson@13269
   517
by (simp add: Card_lt_iff Card_is_Ord Ord_cardinal not_lt_iff_le [THEN iff_sym])
paulson@13221
   518
paulson@13221
   519
(*Can use AC or finiteness to discharge first premise*)
paulson@13221
   520
lemma well_ord_lepoll_imp_Card_le:
paulson@46841
   521
  assumes wB: "well_ord(B,r)" and AB: "A \<lesssim> B"
paulson@46841
   522
  shows "|A| \<le> |B|"
paulson@47016
   523
using Ord_cardinal [of A] Ord_cardinal [of B]
paulson@47016
   524
proof (cases rule: Ord_linear_le)
paulson@47016
   525
  case le thus ?thesis .
paulson@47016
   526
next
paulson@47016
   527
  case ge
paulson@46841
   528
  from lepoll_well_ord [OF AB wB]
paulson@46841
   529
  obtain s where s: "well_ord(A, s)" by blast
paulson@46953
   530
  have "B  \<approx> |B|" by (blast intro: wB eqpoll_sym well_ord_cardinal_eqpoll)
paulson@47016
   531
  also have "... \<lesssim> |A|" by (rule le_imp_lepoll [OF ge])
paulson@46841
   532
  also have "... \<approx> A" by (rule well_ord_cardinal_eqpoll [OF s])
paulson@46841
   533
  finally have "B \<lesssim> A" .
paulson@46953
   534
  hence "A \<approx> B" by (blast intro: eqpollI AB)
paulson@46841
   535
  hence "|A| = |B|" by (rule cardinal_cong)
paulson@46841
   536
  thus ?thesis by simp
paulson@46841
   537
qed
paulson@13221
   538
paulson@46820
   539
lemma lepoll_cardinal_le: "[| A \<lesssim> i; Ord(i) |] ==> |A| \<le> i"
paulson@13221
   540
apply (rule le_trans)
paulson@13221
   541
apply (erule well_ord_Memrel [THEN well_ord_lepoll_imp_Card_le], assumption)
paulson@13221
   542
apply (erule Ord_cardinal_le)
paulson@13221
   543
done
paulson@13221
   544
paulson@13221
   545
lemma lepoll_Ord_imp_eqpoll: "[| A \<lesssim> i; Ord(i) |] ==> |A| \<approx> A"
paulson@13221
   546
by (blast intro: lepoll_cardinal_le well_ord_Memrel well_ord_cardinal_eqpoll dest!: lepoll_well_ord)
paulson@13221
   547
paulson@14046
   548
lemma lesspoll_imp_eqpoll: "[| A \<prec> i; Ord(i) |] ==> |A| \<approx> A"
paulson@13221
   549
apply (unfold lesspoll_def)
paulson@13221
   550
apply (blast intro: lepoll_Ord_imp_eqpoll)
paulson@13221
   551
done
paulson@13221
   552
paulson@46820
   553
lemma cardinal_subset_Ord: "[|A<=i; Ord(i)|] ==> |A| \<subseteq> i"
paulson@14046
   554
apply (drule subset_imp_lepoll [THEN lepoll_cardinal_le])
paulson@14046
   555
apply (auto simp add: lt_def)
paulson@14046
   556
apply (blast intro: Ord_trans)
paulson@14046
   557
done
paulson@13221
   558
paulson@13356
   559
subsection{*The finite cardinals *}
paulson@13221
   560
paulson@46820
   561
lemma cons_lepoll_consD:
paulson@46820
   562
 "[| cons(u,A) \<lesssim> cons(v,B);  u\<notin>A;  v\<notin>B |] ==> A \<lesssim> B"
paulson@13221
   563
apply (unfold lepoll_def inj_def, safe)
paulson@46820
   564
apply (rule_tac x = "\<lambda>x\<in>A. if f`x=v then f`u else f`x" in exI)
paulson@13221
   565
apply (rule CollectI)
paulson@13221
   566
(*Proving it's in the function space A->B*)
paulson@13221
   567
apply (rule if_type [THEN lam_type])
paulson@13221
   568
apply (blast dest: apply_funtype)
paulson@13221
   569
apply (blast elim!: mem_irrefl dest: apply_funtype)
paulson@13221
   570
(*Proving it's injective*)
paulson@13221
   571
apply (simp (no_asm_simp))
paulson@13221
   572
apply blast
paulson@13221
   573
done
paulson@13221
   574
paulson@46820
   575
lemma cons_eqpoll_consD: "[| cons(u,A) \<approx> cons(v,B);  u\<notin>A;  v\<notin>B |] ==> A \<approx> B"
paulson@13221
   576
apply (simp add: eqpoll_iff)
paulson@13221
   577
apply (blast intro: cons_lepoll_consD)
paulson@13221
   578
done
paulson@13221
   579
paulson@13221
   580
(*Lemma suggested by Mike Fourman*)
paulson@13221
   581
lemma succ_lepoll_succD: "succ(m) \<lesssim> succ(n) ==> m \<lesssim> n"
paulson@13221
   582
apply (unfold succ_def)
paulson@13221
   583
apply (erule cons_lepoll_consD)
paulson@13221
   584
apply (rule mem_not_refl)+
paulson@13221
   585
done
paulson@13221
   586
paulson@46877
   587
paulson@46935
   588
lemma nat_lepoll_imp_le:
paulson@46935
   589
     "m \<in> nat ==> n \<in> nat \<Longrightarrow> m \<lesssim> n \<Longrightarrow> m \<le> n"
paulson@46935
   590
proof (induct m arbitrary: n rule: nat_induct)
paulson@46935
   591
  case 0 thus ?case by (blast intro!: nat_0_le)
paulson@46935
   592
next
paulson@46935
   593
  case (succ m)
paulson@46935
   594
  show ?case  using `n \<in> nat`
paulson@46935
   595
    proof (cases rule: natE)
paulson@46935
   596
      case 0 thus ?thesis using succ
paulson@46935
   597
        by (simp add: lepoll_def inj_def)
paulson@46935
   598
    next
paulson@46935
   599
      case (succ n') thus ?thesis using succ.hyps ` succ(m) \<lesssim> n`
paulson@46935
   600
        by (blast intro!: succ_leI dest!: succ_lepoll_succD)
paulson@46935
   601
    qed
paulson@46935
   602
qed
paulson@13221
   603
paulson@46953
   604
lemma nat_eqpoll_iff: "[| m \<in> nat; n \<in> nat |] ==> m \<approx> n \<longleftrightarrow> m = n"
paulson@13221
   605
apply (rule iffI)
paulson@13221
   606
apply (blast intro: nat_lepoll_imp_le le_anti_sym elim!: eqpollE)
paulson@13221
   607
apply (simp add: eqpoll_refl)
paulson@13221
   608
done
paulson@13221
   609
paulson@13221
   610
(*The object of all this work: every natural number is a (finite) cardinal*)
paulson@46820
   611
lemma nat_into_Card:
paulson@47042
   612
  assumes n: "n \<in> nat" shows "Card(n)"
paulson@47042
   613
proof (unfold Card_def cardinal_def, rule sym)
paulson@47042
   614
  have "Ord(n)" using n  by auto
paulson@47042
   615
  moreover
paulson@47042
   616
  { fix i
paulson@47042
   617
    assume "i < n" "i \<approx> n"
paulson@47042
   618
    hence False using n
paulson@47042
   619
      by (auto simp add: lt_nat_in_nat [THEN nat_eqpoll_iff])
paulson@47042
   620
  }
paulson@47042
   621
  ultimately show "(\<mu> i. i \<approx> n) = n" by (auto intro!: Least_equality) 
paulson@47042
   622
qed
paulson@13221
   623
paulson@13221
   624
lemmas cardinal_0 = nat_0I [THEN nat_into_Card, THEN Card_cardinal_eq, iff]
paulson@13221
   625
lemmas cardinal_1 = nat_1I [THEN nat_into_Card, THEN Card_cardinal_eq, iff]
paulson@13221
   626
paulson@13221
   627
paulson@13221
   628
(*Part of Kunen's Lemma 10.6*)
paulson@46877
   629
lemma succ_lepoll_natE: "[| succ(n) \<lesssim> n;  n \<in> nat |] ==> P"
paulson@13221
   630
by (rule nat_lepoll_imp_le [THEN lt_irrefl], auto)
paulson@13221
   631
paulson@46820
   632
lemma nat_lepoll_imp_ex_eqpoll_n:
paulson@13221
   633
     "[| n \<in> nat;  nat \<lesssim> X |] ==> \<exists>Y. Y \<subseteq> X & n \<approx> Y"
paulson@13221
   634
apply (unfold lepoll_def eqpoll_def)
paulson@13221
   635
apply (fast del: subsetI subsetCE
paulson@13221
   636
            intro!: subset_SIs
paulson@13221
   637
            dest!: Ord_nat [THEN [2] OrdmemD, THEN [2] restrict_inj]
paulson@46820
   638
            elim!: restrict_bij
paulson@13221
   639
                   inj_is_fun [THEN fun_is_rel, THEN image_subset])
paulson@13221
   640
done
paulson@13221
   641
paulson@13221
   642
paulson@13221
   643
(** lepoll, \<prec> and natural numbers **)
paulson@13221
   644
paulson@46877
   645
lemma lepoll_succ: "i \<lesssim> succ(i)"
paulson@46877
   646
  by (blast intro: subset_imp_lepoll)
paulson@46877
   647
paulson@46820
   648
lemma lepoll_imp_lesspoll_succ:
paulson@46877
   649
  assumes A: "A \<lesssim> m" and m: "m \<in> nat"
paulson@46877
   650
  shows "A \<prec> succ(m)"
paulson@46877
   651
proof -
paulson@46953
   652
  { assume "A \<approx> succ(m)"
paulson@46877
   653
    hence "succ(m) \<approx> A" by (rule eqpoll_sym)
paulson@46877
   654
    also have "... \<lesssim> m" by (rule A)
paulson@46877
   655
    finally have "succ(m) \<lesssim> m" .
paulson@46877
   656
    hence False by (rule succ_lepoll_natE) (rule m) }
paulson@46877
   657
  moreover have "A \<lesssim> succ(m)" by (blast intro: lepoll_trans A lepoll_succ)
paulson@46953
   658
  ultimately show ?thesis by (auto simp add: lesspoll_def)
paulson@46877
   659
qed
paulson@46877
   660
paulson@46877
   661
lemma lesspoll_succ_imp_lepoll:
paulson@46877
   662
     "[| A \<prec> succ(m); m \<in> nat |] ==> A \<lesssim> m"
paulson@46877
   663
apply (unfold lesspoll_def lepoll_def eqpoll_def bij_def)
paulson@46877
   664
apply (auto dest: inj_not_surj_succ)
paulson@13221
   665
done
paulson@13221
   666
paulson@46877
   667
lemma lesspoll_succ_iff: "m \<in> nat ==> A \<prec> succ(m) \<longleftrightarrow> A \<lesssim> m"
paulson@13221
   668
by (blast intro!: lepoll_imp_lesspoll_succ lesspoll_succ_imp_lepoll)
paulson@13221
   669
paulson@46877
   670
lemma lepoll_succ_disj: "[| A \<lesssim> succ(m);  m \<in> nat |] ==> A \<lesssim> m | A \<approx> succ(m)"
paulson@13221
   671
apply (rule disjCI)
paulson@13221
   672
apply (rule lesspoll_succ_imp_lepoll)
paulson@13221
   673
prefer 2 apply assumption
paulson@13221
   674
apply (simp (no_asm_simp) add: lesspoll_def)
paulson@13221
   675
done
paulson@13221
   676
paulson@13221
   677
lemma lesspoll_cardinal_lt: "[| A \<prec> i; Ord(i) |] ==> |A| < i"
paulson@13221
   678
apply (unfold lesspoll_def, clarify)
paulson@13221
   679
apply (frule lepoll_cardinal_le, assumption)
paulson@13221
   680
apply (blast intro: well_ord_Memrel well_ord_cardinal_eqpoll [THEN eqpoll_sym]
paulson@13221
   681
             dest: lepoll_well_ord  elim!: leE)
paulson@13221
   682
done
paulson@13221
   683
paulson@13221
   684
paulson@13356
   685
subsection{*The first infinite cardinal: Omega, or nat *}
paulson@13221
   686
paulson@13221
   687
(*This implies Kunen's Lemma 10.6*)
paulson@46877
   688
lemma lt_not_lepoll:
paulson@46877
   689
  assumes n: "n<i" "n \<in> nat" shows "~ i \<lesssim> n"
paulson@46877
   690
proof -
paulson@46877
   691
  { assume i: "i \<lesssim> n"
paulson@46877
   692
    have "succ(n) \<lesssim> i" using n
paulson@46953
   693
      by (elim ltE, blast intro: Ord_succ_subsetI [THEN subset_imp_lepoll])
paulson@46877
   694
    also have "... \<lesssim> n" by (rule i)
paulson@46877
   695
    finally have "succ(n) \<lesssim> n" .
paulson@46877
   696
    hence False  by (rule succ_lepoll_natE) (rule n) }
paulson@46877
   697
  thus ?thesis by auto
paulson@46877
   698
qed
paulson@13221
   699
paulson@46877
   700
text{*A slightly weaker version of @{text nat_eqpoll_iff}*}
paulson@46877
   701
lemma Ord_nat_eqpoll_iff:
paulson@46877
   702
  assumes i: "Ord(i)" and n: "n \<in> nat" shows "i \<approx> n \<longleftrightarrow> i=n"
paulson@47016
   703
using i nat_into_Ord [OF n]
paulson@47016
   704
proof (cases rule: Ord_linear_lt)
paulson@47016
   705
  case lt
paulson@46877
   706
  hence  "i \<in> nat" by (rule lt_nat_in_nat) (rule n)
paulson@46953
   707
  thus ?thesis by (simp add: nat_eqpoll_iff n)
paulson@46877
   708
next
paulson@47016
   709
  case eq
paulson@46953
   710
  thus ?thesis by (simp add: eqpoll_refl)
paulson@46877
   711
next
paulson@47016
   712
  case gt
paulson@46953
   713
  hence  "~ i \<lesssim> n" using n  by (rule lt_not_lepoll)
paulson@46877
   714
  hence  "~ i \<approx> n" using n  by (blast intro: eqpoll_imp_lepoll)
paulson@46877
   715
  moreover have "i \<noteq> n" using `n<i` by auto
paulson@46877
   716
  ultimately show ?thesis by blast
paulson@46877
   717
qed
paulson@13221
   718
paulson@13221
   719
lemma Card_nat: "Card(nat)"
paulson@46877
   720
proof -
paulson@46877
   721
  { fix i
paulson@46953
   722
    assume i: "i < nat" "i \<approx> nat"
paulson@46953
   723
    hence "~ nat \<lesssim> i"
paulson@46953
   724
      by (simp add: lt_def lt_not_lepoll)
paulson@46953
   725
    hence False using i
paulson@46877
   726
      by (simp add: eqpoll_iff)
paulson@46877
   727
  }
paulson@46953
   728
  hence "(\<mu> i. i \<approx> nat) = nat" by (blast intro: Least_equality eqpoll_refl)
paulson@46877
   729
  thus ?thesis
paulson@46953
   730
    by (auto simp add: Card_def cardinal_def)
paulson@46877
   731
qed
paulson@13221
   732
paulson@13221
   733
(*Allows showing that |i| is a limit cardinal*)
paulson@46820
   734
lemma nat_le_cardinal: "nat \<le> i ==> nat \<le> |i|"
paulson@13221
   735
apply (rule Card_nat [THEN Card_cardinal_eq, THEN subst])
paulson@13221
   736
apply (erule cardinal_mono)
paulson@13221
   737
done
paulson@13221
   738
paulson@46841
   739
lemma n_lesspoll_nat: "n \<in> nat ==> n \<prec> nat"
paulson@46841
   740
  by (blast intro: Ord_nat Card_nat ltI lt_Card_imp_lesspoll)
paulson@46841
   741
paulson@13221
   742
paulson@13356
   743
subsection{*Towards Cardinal Arithmetic *}
paulson@13221
   744
(** Congruence laws for successor, cardinal addition and multiplication **)
paulson@13221
   745
paulson@13221
   746
(*Congruence law for  cons  under equipollence*)
paulson@46820
   747
lemma cons_lepoll_cong:
paulson@46820
   748
    "[| A \<lesssim> B;  b \<notin> B |] ==> cons(a,A) \<lesssim> cons(b,B)"
paulson@13221
   749
apply (unfold lepoll_def, safe)
paulson@46820
   750
apply (rule_tac x = "\<lambda>y\<in>cons (a,A) . if y=a then b else f`y" in exI)
paulson@46953
   751
apply (rule_tac d = "%z. if z \<in> B then converse (f) `z else a" in lam_injective)
paulson@46820
   752
apply (safe elim!: consE')
paulson@13221
   753
   apply simp_all
paulson@46820
   754
apply (blast intro: inj_is_fun [THEN apply_type])+
paulson@13221
   755
done
paulson@13221
   756
paulson@13221
   757
lemma cons_eqpoll_cong:
paulson@46820
   758
     "[| A \<approx> B;  a \<notin> A;  b \<notin> B |] ==> cons(a,A) \<approx> cons(b,B)"
paulson@13221
   759
by (simp add: eqpoll_iff cons_lepoll_cong)
paulson@13221
   760
paulson@13221
   761
lemma cons_lepoll_cons_iff:
paulson@46821
   762
     "[| a \<notin> A;  b \<notin> B |] ==> cons(a,A) \<lesssim> cons(b,B)  \<longleftrightarrow>  A \<lesssim> B"
paulson@13221
   763
by (blast intro: cons_lepoll_cong cons_lepoll_consD)
paulson@13221
   764
paulson@13221
   765
lemma cons_eqpoll_cons_iff:
paulson@46821
   766
     "[| a \<notin> A;  b \<notin> B |] ==> cons(a,A) \<approx> cons(b,B)  \<longleftrightarrow>  A \<approx> B"
paulson@13221
   767
by (blast intro: cons_eqpoll_cong cons_eqpoll_consD)
paulson@13221
   768
paulson@13221
   769
lemma singleton_eqpoll_1: "{a} \<approx> 1"
paulson@13221
   770
apply (unfold succ_def)
paulson@13221
   771
apply (blast intro!: eqpoll_refl [THEN cons_eqpoll_cong])
paulson@13221
   772
done
paulson@13221
   773
paulson@13221
   774
lemma cardinal_singleton: "|{a}| = 1"
paulson@13221
   775
apply (rule singleton_eqpoll_1 [THEN cardinal_cong, THEN trans])
paulson@13221
   776
apply (simp (no_asm) add: nat_into_Card [THEN Card_cardinal_eq])
paulson@13221
   777
done
paulson@13221
   778
paulson@46820
   779
lemma not_0_is_lepoll_1: "A \<noteq> 0 ==> 1 \<lesssim> A"
paulson@13221
   780
apply (erule not_emptyE)
paulson@13221
   781
apply (rule_tac a = "cons (x, A-{x}) " in subst)
paulson@13221
   782
apply (rule_tac [2] a = "cons(0,0)" and P= "%y. y \<lesssim> cons (x, A-{x})" in subst)
paulson@13221
   783
prefer 3 apply (blast intro: cons_lepoll_cong subset_imp_lepoll, auto)
paulson@13221
   784
done
paulson@13221
   785
paulson@13221
   786
(*Congruence law for  succ  under equipollence*)
paulson@13221
   787
lemma succ_eqpoll_cong: "A \<approx> B ==> succ(A) \<approx> succ(B)"
paulson@13221
   788
apply (unfold succ_def)
paulson@13221
   789
apply (simp add: cons_eqpoll_cong mem_not_refl)
paulson@13221
   790
done
paulson@13221
   791
paulson@13221
   792
(*Congruence law for + under equipollence*)
paulson@13221
   793
lemma sum_eqpoll_cong: "[| A \<approx> C;  B \<approx> D |] ==> A+B \<approx> C+D"
paulson@13221
   794
apply (unfold eqpoll_def)
paulson@13221
   795
apply (blast intro!: sum_bij)
paulson@13221
   796
done
paulson@13221
   797
paulson@13221
   798
(*Congruence law for * under equipollence*)
paulson@46820
   799
lemma prod_eqpoll_cong:
paulson@13221
   800
    "[| A \<approx> C;  B \<approx> D |] ==> A*B \<approx> C*D"
paulson@13221
   801
apply (unfold eqpoll_def)
paulson@13221
   802
apply (blast intro!: prod_bij)
paulson@13221
   803
done
paulson@13221
   804
paulson@46820
   805
lemma inj_disjoint_eqpoll:
paulson@46953
   806
    "[| f \<in> inj(A,B);  A \<inter> B = 0 |] ==> A \<union> (B - range(f)) \<approx> B"
paulson@13221
   807
apply (unfold eqpoll_def)
paulson@13221
   808
apply (rule exI)
paulson@46953
   809
apply (rule_tac c = "%x. if x \<in> A then f`x else x"
paulson@46953
   810
            and d = "%y. if y \<in> range (f) then converse (f) `y else y"
paulson@13221
   811
       in lam_bijective)
paulson@13221
   812
apply (blast intro!: if_type inj_is_fun [THEN apply_type])
paulson@13221
   813
apply (simp (no_asm_simp) add: inj_converse_fun [THEN apply_funtype])
paulson@46820
   814
apply (safe elim!: UnE')
paulson@13221
   815
   apply (simp_all add: inj_is_fun [THEN apply_rangeI])
paulson@46820
   816
apply (blast intro: inj_converse_fun [THEN apply_type])+
paulson@13221
   817
done
paulson@13221
   818
paulson@13221
   819
paulson@13356
   820
subsection{*Lemmas by Krzysztof Grabczewski*}
paulson@13356
   821
paulson@13356
   822
(*New proofs using cons_lepoll_cons. Could generalise from succ to cons.*)
paulson@13221
   823
paulson@46953
   824
text{*If @{term A} has at most @{term"n+1"} elements and @{term"a \<in> A"}
paulson@46877
   825
      then @{term"A-{a}"} has at most @{term n}.*}
paulson@46820
   826
lemma Diff_sing_lepoll:
paulson@46877
   827
      "[| a \<in> A;  A \<lesssim> succ(n) |] ==> A - {a} \<lesssim> n"
paulson@13221
   828
apply (unfold succ_def)
paulson@13221
   829
apply (rule cons_lepoll_consD)
paulson@13221
   830
apply (rule_tac [3] mem_not_refl)
paulson@13221
   831
apply (erule cons_Diff [THEN ssubst], safe)
paulson@13221
   832
done
paulson@13221
   833
paulson@46877
   834
text{*If @{term A} has at least @{term"n+1"} elements then @{term"A-{a}"} has at least @{term n}.*}
paulson@46820
   835
lemma lepoll_Diff_sing:
paulson@46877
   836
  assumes A: "succ(n) \<lesssim> A" shows "n \<lesssim> A - {a}"
paulson@46877
   837
proof -
paulson@46877
   838
  have "cons(n,n) \<lesssim> A" using A
paulson@46877
   839
    by (unfold succ_def)
paulson@46953
   840
  also have "... \<lesssim> cons(a, A-{a})"
paulson@46877
   841
    by (blast intro: subset_imp_lepoll)
paulson@46877
   842
  finally have "cons(n,n) \<lesssim> cons(a, A-{a})" .
paulson@46877
   843
  thus ?thesis
paulson@46953
   844
    by (blast intro: cons_lepoll_consD mem_irrefl)
paulson@46877
   845
qed
paulson@13221
   846
paulson@46877
   847
lemma Diff_sing_eqpoll: "[| a \<in> A; A \<approx> succ(n) |] ==> A - {a} \<approx> n"
paulson@46820
   848
by (blast intro!: eqpollI
paulson@46820
   849
          elim!: eqpollE
paulson@13221
   850
          intro: Diff_sing_lepoll lepoll_Diff_sing)
paulson@13221
   851
paulson@46877
   852
lemma lepoll_1_is_sing: "[| A \<lesssim> 1; a \<in> A |] ==> A = {a}"
paulson@13221
   853
apply (frule Diff_sing_lepoll, assumption)
paulson@13221
   854
apply (drule lepoll_0_is_0)
paulson@13221
   855
apply (blast elim: equalityE)
paulson@13221
   856
done
paulson@13221
   857
paulson@46820
   858
lemma Un_lepoll_sum: "A \<union> B \<lesssim> A+B"
paulson@13221
   859
apply (unfold lepoll_def)
paulson@46877
   860
apply (rule_tac x = "\<lambda>x\<in>A \<union> B. if x\<in>A then Inl (x) else Inr (x)" in exI)
paulson@46877
   861
apply (rule_tac d = "%z. snd (z)" in lam_injective)
paulson@46820
   862
apply force
paulson@13221
   863
apply (simp add: Inl_def Inr_def)
paulson@13221
   864
done
paulson@13221
   865
paulson@13221
   866
lemma well_ord_Un:
paulson@46820
   867
     "[| well_ord(X,R); well_ord(Y,S) |] ==> \<exists>T. well_ord(X \<union> Y, T)"
paulson@46820
   868
by (erule well_ord_radd [THEN Un_lepoll_sum [THEN lepoll_well_ord]],
paulson@13221
   869
    assumption)
paulson@13221
   870
paulson@13221
   871
(*Krzysztof Grabczewski*)
paulson@46820
   872
lemma disj_Un_eqpoll_sum: "A \<inter> B = 0 ==> A \<union> B \<approx> A + B"
paulson@13221
   873
apply (unfold eqpoll_def)
paulson@46877
   874
apply (rule_tac x = "\<lambda>a\<in>A \<union> B. if a \<in> A then Inl (a) else Inr (a)" in exI)
paulson@46877
   875
apply (rule_tac d = "%z. case (%x. x, %x. x, z)" in lam_bijective)
paulson@13221
   876
apply auto
paulson@13221
   877
done
paulson@13221
   878
paulson@13221
   879
paulson@13244
   880
subsection {*Finite and infinite sets*}
paulson@13221
   881
paulson@47018
   882
lemma eqpoll_imp_Finite_iff: "A \<approx> B ==> Finite(A) \<longleftrightarrow> Finite(B)"
paulson@47018
   883
apply (unfold Finite_def)
paulson@47018
   884
apply (blast intro: eqpoll_trans eqpoll_sym)
paulson@47018
   885
done
paulson@47018
   886
paulson@13244
   887
lemma Finite_0 [simp]: "Finite(0)"
paulson@13221
   888
apply (unfold Finite_def)
paulson@13221
   889
apply (blast intro!: eqpoll_refl nat_0I)
paulson@13221
   890
done
paulson@13221
   891
paulson@47018
   892
lemma Finite_cons: "Finite(x) ==> Finite(cons(y,x))"
paulson@13221
   893
apply (unfold Finite_def)
paulson@47018
   894
apply (case_tac "y \<in> x")
paulson@47018
   895
apply (simp add: cons_absorb)
paulson@47018
   896
apply (erule bexE)
paulson@47018
   897
apply (rule bexI)
paulson@47018
   898
apply (erule_tac [2] nat_succI)
paulson@47018
   899
apply (simp (no_asm_simp) add: succ_def cons_eqpoll_cong mem_not_refl)
paulson@47018
   900
done
paulson@47018
   901
paulson@47018
   902
lemma Finite_succ: "Finite(x) ==> Finite(succ(x))"
paulson@47018
   903
apply (unfold succ_def)
paulson@47018
   904
apply (erule Finite_cons)
paulson@13221
   905
done
paulson@13221
   906
paulson@47018
   907
lemma lepoll_nat_imp_Finite:
paulson@47018
   908
  assumes A: "A \<lesssim> n" and n: "n \<in> nat" shows "Finite(A)"
paulson@47018
   909
proof -
paulson@47018
   910
  have "A \<lesssim> n \<Longrightarrow> Finite(A)" using n
paulson@47018
   911
    proof (induct n)
paulson@47018
   912
      case 0
paulson@47018
   913
      hence "A = 0" by (rule lepoll_0_is_0) 
paulson@47018
   914
      thus ?case by simp
paulson@47018
   915
    next
paulson@47018
   916
      case (succ n)
paulson@47018
   917
      hence "A \<lesssim> n \<or> A \<approx> succ(n)" by (blast dest: lepoll_succ_disj)
paulson@47018
   918
      thus ?case using succ by (auto simp add: Finite_def) 
paulson@47018
   919
    qed
paulson@47018
   920
  thus ?thesis using A .
paulson@47018
   921
qed
paulson@47018
   922
paulson@46820
   923
lemma lesspoll_nat_is_Finite:
paulson@13221
   924
     "A \<prec> nat ==> Finite(A)"
paulson@13221
   925
apply (unfold Finite_def)
paulson@46820
   926
apply (blast dest: ltD lesspoll_cardinal_lt
paulson@13221
   927
                   lesspoll_imp_eqpoll [THEN eqpoll_sym])
paulson@13221
   928
done
paulson@13221
   929
paulson@46820
   930
lemma lepoll_Finite:
paulson@46877
   931
  assumes Y: "Y \<lesssim> X" and X: "Finite(X)" shows "Finite(Y)"
paulson@46877
   932
proof -
paulson@46953
   933
  obtain n where n: "n \<in> nat" "X \<approx> n" using X
paulson@46953
   934
    by (auto simp add: Finite_def)
paulson@46877
   935
  have "Y \<lesssim> X"         by (rule Y)
paulson@46877
   936
  also have "... \<approx> n"  by (rule n)
paulson@46877
   937
  finally have "Y \<lesssim> n" .
paulson@46877
   938
  thus ?thesis using n by (simp add: lepoll_nat_imp_Finite)
paulson@46877
   939
qed
paulson@13221
   940
wenzelm@45602
   941
lemmas subset_Finite = subset_imp_lepoll [THEN lepoll_Finite]
paulson@13221
   942
paulson@46821
   943
lemma Finite_cons_iff [iff]: "Finite(cons(y,x)) \<longleftrightarrow> Finite(x)"
paulson@13244
   944
by (blast intro: Finite_cons subset_Finite)
paulson@13244
   945
paulson@46821
   946
lemma Finite_succ_iff [iff]: "Finite(succ(x)) \<longleftrightarrow> Finite(x)"
paulson@13244
   947
by (simp add: succ_def)
paulson@13244
   948
paulson@47018
   949
lemma Finite_Int: "Finite(A) | Finite(B) ==> Finite(A \<inter> B)"
paulson@47018
   950
by (blast intro: subset_Finite)
paulson@47018
   951
paulson@47018
   952
lemmas Finite_Diff = Diff_subset [THEN subset_Finite]
paulson@47018
   953
paulson@46820
   954
lemma nat_le_infinite_Ord:
paulson@46820
   955
      "[| Ord(i);  ~ Finite(i) |] ==> nat \<le> i"
paulson@13221
   956
apply (unfold Finite_def)
paulson@13221
   957
apply (erule Ord_nat [THEN [2] Ord_linear2])
paulson@13221
   958
prefer 2 apply assumption
paulson@13221
   959
apply (blast intro!: eqpoll_refl elim!: ltE)
paulson@13221
   960
done
paulson@13221
   961
paulson@46820
   962
lemma Finite_imp_well_ord:
paulson@46820
   963
    "Finite(A) ==> \<exists>r. well_ord(A,r)"
paulson@13221
   964
apply (unfold Finite_def eqpoll_def)
paulson@13221
   965
apply (blast intro: well_ord_rvimage bij_is_inj well_ord_Memrel nat_into_Ord)
paulson@13221
   966
done
paulson@13221
   967
paulson@13244
   968
lemma succ_lepoll_imp_not_empty: "succ(x) \<lesssim> y ==> y \<noteq> 0"
paulson@13244
   969
by (fast dest!: lepoll_0_is_0)
paulson@13244
   970
paulson@13244
   971
lemma eqpoll_succ_imp_not_empty: "x \<approx> succ(n) ==> x \<noteq> 0"
paulson@13244
   972
by (fast elim!: eqpoll_sym [THEN eqpoll_0_is_0, THEN succ_neq_0])
paulson@13244
   973
paulson@13244
   974
lemma Finite_Fin_lemma [rule_format]:
paulson@46820
   975
     "n \<in> nat ==> \<forall>A. (A\<approx>n & A \<subseteq> X) \<longrightarrow> A \<in> Fin(X)"
paulson@13244
   976
apply (induct_tac n)
paulson@13244
   977
apply (rule allI)
paulson@13244
   978
apply (fast intro!: Fin.emptyI dest!: eqpoll_imp_lepoll [THEN lepoll_0_is_0])
paulson@13244
   979
apply (rule allI)
paulson@13244
   980
apply (rule impI)
paulson@13244
   981
apply (erule conjE)
paulson@13244
   982
apply (rule eqpoll_succ_imp_not_empty [THEN not_emptyE], assumption)
paulson@13244
   983
apply (frule Diff_sing_eqpoll, assumption)
paulson@13244
   984
apply (erule allE)
paulson@13244
   985
apply (erule impE, fast)
paulson@13244
   986
apply (drule subsetD, assumption)
paulson@13244
   987
apply (drule Fin.consI, assumption)
paulson@13244
   988
apply (simp add: cons_Diff)
paulson@13244
   989
done
paulson@13244
   990
paulson@13244
   991
lemma Finite_Fin: "[| Finite(A); A \<subseteq> X |] ==> A \<in> Fin(X)"
paulson@46820
   992
by (unfold Finite_def, blast intro: Finite_Fin_lemma)
paulson@13244
   993
paulson@46953
   994
lemma Fin_lemma [rule_format]: "n \<in> nat ==> \<forall>A. A \<approx> n \<longrightarrow> A \<in> Fin(A)"
paulson@13244
   995
apply (induct_tac n)
paulson@13244
   996
apply (simp add: eqpoll_0_iff, clarify)
paulson@46953
   997
apply (subgoal_tac "\<exists>u. u \<in> A")
paulson@13244
   998
apply (erule exE)
wenzelm@46471
   999
apply (rule Diff_sing_eqpoll [elim_format])
paulson@13244
  1000
prefer 2 apply assumption
paulson@13244
  1001
apply assumption
paulson@13784
  1002
apply (rule_tac b = A in cons_Diff [THEN subst], assumption)
paulson@13244
  1003
apply (rule Fin.consI, blast)
paulson@13244
  1004
apply (blast intro: subset_consI [THEN Fin_mono, THEN subsetD])
paulson@13244
  1005
(*Now for the lemma assumed above*)
paulson@13244
  1006
apply (unfold eqpoll_def)
paulson@13244
  1007
apply (blast intro: bij_converse_bij [THEN bij_is_fun, THEN apply_type])
paulson@13244
  1008
done
paulson@13244
  1009
paulson@46820
  1010
lemma Finite_into_Fin: "Finite(A) ==> A \<in> Fin(A)"
paulson@13244
  1011
apply (unfold Finite_def)
paulson@13244
  1012
apply (blast intro: Fin_lemma)
paulson@13244
  1013
done
paulson@13244
  1014
paulson@46820
  1015
lemma Fin_into_Finite: "A \<in> Fin(U) ==> Finite(A)"
paulson@13244
  1016
by (fast intro!: Finite_0 Finite_cons elim: Fin_induct)
paulson@13244
  1017
paulson@46821
  1018
lemma Finite_Fin_iff: "Finite(A) \<longleftrightarrow> A \<in> Fin(A)"
paulson@13244
  1019
by (blast intro: Finite_into_Fin Fin_into_Finite)
paulson@13244
  1020
paulson@46820
  1021
lemma Finite_Un: "[| Finite(A); Finite(B) |] ==> Finite(A \<union> B)"
paulson@46820
  1022
by (blast intro!: Fin_into_Finite Fin_UnI
paulson@13244
  1023
          dest!: Finite_into_Fin
paulson@46820
  1024
          intro: Un_upper1 [THEN Fin_mono, THEN subsetD]
paulson@13244
  1025
                 Un_upper2 [THEN Fin_mono, THEN subsetD])
paulson@13244
  1026
paulson@46821
  1027
lemma Finite_Un_iff [simp]: "Finite(A \<union> B) \<longleftrightarrow> (Finite(A) & Finite(B))"
paulson@46820
  1028
by (blast intro: subset_Finite Finite_Un)
paulson@14883
  1029
paulson@14883
  1030
text{*The converse must hold too.*}
paulson@46820
  1031
lemma Finite_Union: "[| \<forall>y\<in>X. Finite(y);  Finite(X) |] ==> Finite(\<Union>(X))"
paulson@13244
  1032
apply (simp add: Finite_Fin_iff)
paulson@13244
  1033
apply (rule Fin_UnionI)
paulson@13244
  1034
apply (erule Fin_induct, simp)
paulson@13244
  1035
apply (blast intro: Fin.consI Fin_mono [THEN [2] rev_subsetD])
paulson@13244
  1036
done
paulson@13244
  1037
paulson@13244
  1038
(* Induction principle for Finite(A), by Sidi Ehmety *)
wenzelm@13524
  1039
lemma Finite_induct [case_names 0 cons, induct set: Finite]:
paulson@13244
  1040
"[| Finite(A); P(0);
paulson@46820
  1041
    !! x B.   [| Finite(B); x \<notin> B; P(B) |] ==> P(cons(x, B)) |]
paulson@13244
  1042
 ==> P(A)"
paulson@46820
  1043
apply (erule Finite_into_Fin [THEN Fin_induct])
paulson@13244
  1044
apply (blast intro: Fin_into_Finite)+
paulson@13244
  1045
done
paulson@13244
  1046
paulson@13244
  1047
(*Sidi Ehmety.  The contrapositive says ~Finite(A) ==> ~Finite(A-{a}) *)
paulson@13244
  1048
lemma Diff_sing_Finite: "Finite(A - {a}) ==> Finite(A)"
paulson@13244
  1049
apply (unfold Finite_def)
paulson@46877
  1050
apply (case_tac "a \<in> A")
paulson@13244
  1051
apply (subgoal_tac [2] "A-{a}=A", auto)
paulson@13244
  1052
apply (rule_tac x = "succ (n) " in bexI)
paulson@13244
  1053
apply (subgoal_tac "cons (a, A - {a}) = A & cons (n, n) = succ (n) ")
paulson@13784
  1054
apply (drule_tac a = a and b = n in cons_eqpoll_cong)
paulson@13244
  1055
apply (auto dest: mem_irrefl)
paulson@13244
  1056
done
paulson@13244
  1057
paulson@13244
  1058
(*Sidi Ehmety.  And the contrapositive of this says
paulson@13244
  1059
   [| ~Finite(A); Finite(B) |] ==> ~Finite(A-B) *)
paulson@46820
  1060
lemma Diff_Finite [rule_format]: "Finite(B) ==> Finite(A-B) \<longrightarrow> Finite(A)"
paulson@13244
  1061
apply (erule Finite_induct, auto)
paulson@46953
  1062
apply (case_tac "x \<in> A")
paulson@13244
  1063
 apply (subgoal_tac [2] "A-cons (x, B) = A - B")
paulson@13615
  1064
apply (subgoal_tac "A - cons (x, B) = (A - B) - {x}", simp)
paulson@13244
  1065
apply (drule Diff_sing_Finite, auto)
paulson@13244
  1066
done
paulson@13244
  1067
paulson@13244
  1068
lemma Finite_RepFun: "Finite(A) ==> Finite(RepFun(A,f))"
paulson@13244
  1069
by (erule Finite_induct, simp_all)
paulson@13244
  1070
paulson@13244
  1071
lemma Finite_RepFun_iff_lemma [rule_format]:
paulson@46820
  1072
     "[|Finite(x); !!x y. f(x)=f(y) ==> x=y|]
paulson@46820
  1073
      ==> \<forall>A. x = RepFun(A,f) \<longrightarrow> Finite(A)"
paulson@13244
  1074
apply (erule Finite_induct)
paulson@46820
  1075
 apply clarify
paulson@13244
  1076
 apply (case_tac "A=0", simp)
paulson@46820
  1077
 apply (blast del: allE, clarify)
paulson@46820
  1078
apply (subgoal_tac "\<exists>z\<in>A. x = f(z)")
paulson@46820
  1079
 prefer 2 apply (blast del: allE elim: equalityE, clarify)
paulson@13244
  1080
apply (subgoal_tac "B = {f(u) . u \<in> A - {z}}")
paulson@46820
  1081
 apply (blast intro: Diff_sing_Finite)
paulson@46820
  1082
apply (thin_tac "\<forall>A. ?P(A) \<longrightarrow> Finite(A)")
paulson@46820
  1083
apply (rule equalityI)
paulson@46820
  1084
 apply (blast intro: elim: equalityE)
paulson@46820
  1085
apply (blast intro: elim: equalityCE)
paulson@13244
  1086
done
paulson@13244
  1087
paulson@13244
  1088
text{*I don't know why, but if the premise is expressed using meta-connectives
paulson@13244
  1089
then  the simplifier cannot prove it automatically in conditional rewriting.*}
paulson@13244
  1090
lemma Finite_RepFun_iff:
paulson@46821
  1091
     "(\<forall>x y. f(x)=f(y) \<longrightarrow> x=y) ==> Finite(RepFun(A,f)) \<longleftrightarrow> Finite(A)"
paulson@46820
  1092
by (blast intro: Finite_RepFun Finite_RepFun_iff_lemma [of _ f])
paulson@13244
  1093
paulson@13244
  1094
lemma Finite_Pow: "Finite(A) ==> Finite(Pow(A))"
paulson@46820
  1095
apply (erule Finite_induct)
paulson@46820
  1096
apply (simp_all add: Pow_insert Finite_Un Finite_RepFun)
paulson@13244
  1097
done
paulson@13244
  1098
paulson@13244
  1099
lemma Finite_Pow_imp_Finite: "Finite(Pow(A)) ==> Finite(A)"
paulson@13244
  1100
apply (subgoal_tac "Finite({{x} . x \<in> A})")
paulson@46820
  1101
 apply (simp add: Finite_RepFun_iff )
paulson@46820
  1102
apply (blast intro: subset_Finite)
paulson@13244
  1103
done
paulson@13244
  1104
paulson@46821
  1105
lemma Finite_Pow_iff [iff]: "Finite(Pow(A)) \<longleftrightarrow> Finite(A)"
paulson@13244
  1106
by (blast intro: Finite_Pow Finite_Pow_imp_Finite)
paulson@13244
  1107
paulson@47101
  1108
lemma Finite_cardinal_iff:
paulson@47101
  1109
  assumes i: "Ord(i)" shows "Finite(|i|) \<longleftrightarrow> Finite(i)"
paulson@47101
  1110
  by (auto simp add: Finite_def) (blast intro: eqpoll_trans eqpoll_sym Ord_cardinal_eqpoll [OF i])+
paulson@13244
  1111
paulson@13221
  1112
paulson@13221
  1113
(*Krzysztof Grabczewski's proof that the converse of a finite, well-ordered
paulson@13221
  1114
  set is well-ordered.  Proofs simplified by lcp. *)
paulson@13221
  1115
paulson@46877
  1116
lemma nat_wf_on_converse_Memrel: "n \<in> nat ==> wf[n](converse(Memrel(n)))"
paulson@47018
  1117
proof (induct n rule: nat_induct)
paulson@47018
  1118
  case 0 thus ?case by (blast intro: wf_onI)
paulson@47018
  1119
next
paulson@47018
  1120
  case (succ x)
paulson@47018
  1121
  hence wfx: "\<And>Z. Z = 0 \<or> (\<exists>z\<in>Z. \<forall>y. z \<in> y \<and> z \<in> x \<and> y \<in> x \<and> z \<in> x \<longrightarrow> y \<notin> Z)"
paulson@47018
  1122
    by (simp add: wf_on_def wf_def)  --{*not easy to erase the duplicate @{term"z \<in> x"}!*}
paulson@47018
  1123
  show ?case
paulson@47018
  1124
    proof (rule wf_onI)
paulson@47018
  1125
      fix Z u
paulson@47018
  1126
      assume Z: "u \<in> Z" "\<forall>z\<in>Z. \<exists>y\<in>Z. \<langle>y, z\<rangle> \<in> converse(Memrel(succ(x)))"
paulson@47018
  1127
      show False 
paulson@47018
  1128
        proof (cases "x \<in> Z")
paulson@47018
  1129
          case True thus False using Z
paulson@47018
  1130
            by (blast elim: mem_irrefl mem_asym)
paulson@47018
  1131
          next
paulson@47018
  1132
          case False thus False using wfx [of Z] Z
paulson@47018
  1133
            by blast
paulson@47018
  1134
        qed
paulson@47018
  1135
    qed
paulson@47018
  1136
qed
paulson@13221
  1137
paulson@46877
  1138
lemma nat_well_ord_converse_Memrel: "n \<in> nat ==> well_ord(n,converse(Memrel(n)))"
paulson@13221
  1139
apply (frule Ord_nat [THEN Ord_in_Ord, THEN well_ord_Memrel])
paulson@47018
  1140
apply (simp add: well_ord_def tot_ord_converse nat_wf_on_converse_Memrel) 
paulson@13221
  1141
done
paulson@13221
  1142
paulson@13221
  1143
lemma well_ord_converse:
paulson@46820
  1144
     "[|well_ord(A,r);
paulson@13221
  1145
        well_ord(ordertype(A,r), converse(Memrel(ordertype(A, r)))) |]
paulson@13221
  1146
      ==> well_ord(A,converse(r))"
paulson@13221
  1147
apply (rule well_ord_Int_iff [THEN iffD1])
paulson@13221
  1148
apply (frule ordermap_bij [THEN bij_is_inj, THEN well_ord_rvimage], assumption)
paulson@13221
  1149
apply (simp add: rvimage_converse converse_Int converse_prod
paulson@13221
  1150
                 ordertype_ord_iso [THEN ord_iso_rvimage_eq])
paulson@13221
  1151
done
paulson@13221
  1152
paulson@13221
  1153
lemma ordertype_eq_n:
paulson@46953
  1154
  assumes r: "well_ord(A,r)" and A: "A \<approx> n" and n: "n \<in> nat"
paulson@46877
  1155
  shows "ordertype(A,r) = n"
paulson@46877
  1156
proof -
paulson@46953
  1157
  have "ordertype(A,r) \<approx> A"
paulson@46953
  1158
    by (blast intro: bij_imp_eqpoll bij_converse_bij ordermap_bij r)
paulson@46877
  1159
  also have "... \<approx> n" by (rule A)
paulson@46877
  1160
  finally have "ordertype(A,r) \<approx> n" .
paulson@46877
  1161
  thus ?thesis
paulson@46953
  1162
    by (simp add: Ord_nat_eqpoll_iff Ord_ordertype n r)
paulson@46877
  1163
qed
paulson@13221
  1164
paulson@46820
  1165
lemma Finite_well_ord_converse:
paulson@13221
  1166
    "[| Finite(A);  well_ord(A,r) |] ==> well_ord(A,converse(r))"
paulson@13221
  1167
apply (unfold Finite_def)
paulson@13221
  1168
apply (rule well_ord_converse, assumption)
paulson@13221
  1169
apply (blast dest: ordertype_eq_n intro!: nat_well_ord_converse_Memrel)
paulson@13221
  1170
done
paulson@13221
  1171
paulson@46877
  1172
lemma nat_into_Finite: "n \<in> nat ==> Finite(n)"
paulson@47018
  1173
  by (auto simp add: Finite_def intro: eqpoll_refl) 
paulson@13221
  1174
paulson@46877
  1175
lemma nat_not_Finite: "~ Finite(nat)"
paulson@46877
  1176
proof -
paulson@46877
  1177
  { fix n
paulson@46877
  1178
    assume n: "n \<in> nat" "nat \<approx> n"
paulson@46953
  1179
    have "n \<in> nat"    by (rule n)
paulson@46877
  1180
    also have "... = n" using n
paulson@46953
  1181
      by (simp add: Ord_nat_eqpoll_iff Ord_nat)
paulson@46877
  1182
    finally have "n \<in> n" .
paulson@46953
  1183
    hence False
paulson@46953
  1184
      by (blast elim: mem_irrefl)
paulson@46877
  1185
  }
paulson@46877
  1186
  thus ?thesis
paulson@46953
  1187
    by (auto simp add: Finite_def)
paulson@46877
  1188
qed
paulson@14076
  1189
lcp@435
  1190
end