src/HOL/Library/Infinite_Set.thy
author wenzelm
Sun, 01 Oct 2006 18:29:26 +0200
changeset 20809 6c4fd0b4b63a
child 21210 c17fd2df4e9e
permissions -rw-r--r--
moved theory Infinite_Set to Library;
wenzelm@20809
     1
(*  Title:      HOL/Infnite_Set.thy
wenzelm@20809
     2
    ID:         $Id$
wenzelm@20809
     3
    Author:     Stephan Merz
wenzelm@20809
     4
*)
wenzelm@20809
     5
wenzelm@20809
     6
header {* Infinite Sets and Related Concepts *}
wenzelm@20809
     7
wenzelm@20809
     8
theory Infinite_Set
wenzelm@20809
     9
imports Hilbert_Choice Binomial
wenzelm@20809
    10
begin
wenzelm@20809
    11
wenzelm@20809
    12
subsection "Infinite Sets"
wenzelm@20809
    13
wenzelm@20809
    14
text {*
wenzelm@20809
    15
  Some elementary facts about infinite sets, mostly by Stefan Merz.
wenzelm@20809
    16
  Beware! Because "infinite" merely abbreviates a negation, these
wenzelm@20809
    17
  lemmas may not work well with @{text "blast"}.
wenzelm@20809
    18
*}
wenzelm@20809
    19
wenzelm@20809
    20
abbreviation
wenzelm@20809
    21
  infinite :: "'a set \<Rightarrow> bool"
wenzelm@20809
    22
  "infinite S == \<not> finite S"
wenzelm@20809
    23
wenzelm@20809
    24
text {*
wenzelm@20809
    25
  Infinite sets are non-empty, and if we remove some elements from an
wenzelm@20809
    26
  infinite set, the result is still infinite.
wenzelm@20809
    27
*}
wenzelm@20809
    28
wenzelm@20809
    29
lemma infinite_imp_nonempty: "infinite S ==> S \<noteq> {}"
wenzelm@20809
    30
  by auto
wenzelm@20809
    31
wenzelm@20809
    32
lemma infinite_remove:
wenzelm@20809
    33
  "infinite S \<Longrightarrow> infinite (S - {a})"
wenzelm@20809
    34
  by simp
wenzelm@20809
    35
wenzelm@20809
    36
lemma Diff_infinite_finite:
wenzelm@20809
    37
  assumes T: "finite T" and S: "infinite S"
wenzelm@20809
    38
  shows "infinite (S - T)"
wenzelm@20809
    39
  using T
wenzelm@20809
    40
proof induct
wenzelm@20809
    41
  from S
wenzelm@20809
    42
  show "infinite (S - {})" by auto
wenzelm@20809
    43
next
wenzelm@20809
    44
  fix T x
wenzelm@20809
    45
  assume ih: "infinite (S - T)"
wenzelm@20809
    46
  have "S - (insert x T) = (S - T) - {x}"
wenzelm@20809
    47
    by (rule Diff_insert)
wenzelm@20809
    48
  with ih
wenzelm@20809
    49
  show "infinite (S - (insert x T))"
wenzelm@20809
    50
    by (simp add: infinite_remove)
wenzelm@20809
    51
qed
wenzelm@20809
    52
wenzelm@20809
    53
lemma Un_infinite: "infinite S \<Longrightarrow> infinite (S \<union> T)"
wenzelm@20809
    54
  by simp
wenzelm@20809
    55
wenzelm@20809
    56
lemma infinite_super:
wenzelm@20809
    57
  assumes T: "S \<subseteq> T" and S: "infinite S"
wenzelm@20809
    58
  shows "infinite T"
wenzelm@20809
    59
proof
wenzelm@20809
    60
  assume "finite T"
wenzelm@20809
    61
  with T have "finite S" by (simp add: finite_subset)
wenzelm@20809
    62
  with S show False by simp
wenzelm@20809
    63
qed
wenzelm@20809
    64
wenzelm@20809
    65
text {*
wenzelm@20809
    66
  As a concrete example, we prove that the set of natural numbers is
wenzelm@20809
    67
  infinite.
wenzelm@20809
    68
*}
wenzelm@20809
    69
wenzelm@20809
    70
lemma finite_nat_bounded:
wenzelm@20809
    71
  assumes S: "finite (S::nat set)"
wenzelm@20809
    72
  shows "\<exists>k. S \<subseteq> {..<k}"  (is "\<exists>k. ?bounded S k")
wenzelm@20809
    73
using S
wenzelm@20809
    74
proof induct
wenzelm@20809
    75
  have "?bounded {} 0" by simp
wenzelm@20809
    76
  then show "\<exists>k. ?bounded {} k" ..
wenzelm@20809
    77
next
wenzelm@20809
    78
  fix S x
wenzelm@20809
    79
  assume "\<exists>k. ?bounded S k"
wenzelm@20809
    80
  then obtain k where k: "?bounded S k" ..
wenzelm@20809
    81
  show "\<exists>k. ?bounded (insert x S) k"
wenzelm@20809
    82
  proof (cases "x < k")
wenzelm@20809
    83
    case True
wenzelm@20809
    84
    with k show ?thesis by auto
wenzelm@20809
    85
  next
wenzelm@20809
    86
    case False
wenzelm@20809
    87
    with k have "?bounded S (Suc x)" by auto
wenzelm@20809
    88
    then show ?thesis by auto
wenzelm@20809
    89
  qed
wenzelm@20809
    90
qed
wenzelm@20809
    91
wenzelm@20809
    92
lemma finite_nat_iff_bounded:
wenzelm@20809
    93
  "finite (S::nat set) = (\<exists>k. S \<subseteq> {..<k})"  (is "?lhs = ?rhs")
wenzelm@20809
    94
proof
wenzelm@20809
    95
  assume ?lhs
wenzelm@20809
    96
  then show ?rhs by (rule finite_nat_bounded)
wenzelm@20809
    97
next
wenzelm@20809
    98
  assume ?rhs
wenzelm@20809
    99
  then obtain k where "S \<subseteq> {..<k}" ..
wenzelm@20809
   100
  then show "finite S"
wenzelm@20809
   101
    by (rule finite_subset) simp
wenzelm@20809
   102
qed
wenzelm@20809
   103
wenzelm@20809
   104
lemma finite_nat_iff_bounded_le:
wenzelm@20809
   105
  "finite (S::nat set) = (\<exists>k. S \<subseteq> {..k})"  (is "?lhs = ?rhs")
wenzelm@20809
   106
proof
wenzelm@20809
   107
  assume ?lhs
wenzelm@20809
   108
  then obtain k where "S \<subseteq> {..<k}"
wenzelm@20809
   109
    by (blast dest: finite_nat_bounded)
wenzelm@20809
   110
  then have "S \<subseteq> {..k}" by auto
wenzelm@20809
   111
  then show ?rhs ..
wenzelm@20809
   112
next
wenzelm@20809
   113
  assume ?rhs
wenzelm@20809
   114
  then obtain k where "S \<subseteq> {..k}" ..
wenzelm@20809
   115
  then show "finite S"
wenzelm@20809
   116
    by (rule finite_subset) simp
wenzelm@20809
   117
qed
wenzelm@20809
   118
wenzelm@20809
   119
lemma infinite_nat_iff_unbounded:
wenzelm@20809
   120
  "infinite (S::nat set) = (\<forall>m. \<exists>n. m<n \<and> n\<in>S)"
wenzelm@20809
   121
  (is "?lhs = ?rhs")
wenzelm@20809
   122
proof
wenzelm@20809
   123
  assume ?lhs
wenzelm@20809
   124
  show ?rhs
wenzelm@20809
   125
  proof (rule ccontr)
wenzelm@20809
   126
    assume "\<not> ?rhs"
wenzelm@20809
   127
    then obtain m where m: "\<forall>n. m<n \<longrightarrow> n\<notin>S" by blast
wenzelm@20809
   128
    then have "S \<subseteq> {..m}"
wenzelm@20809
   129
      by (auto simp add: sym [OF linorder_not_less])
wenzelm@20809
   130
    with `?lhs` show False
wenzelm@20809
   131
      by (simp add: finite_nat_iff_bounded_le)
wenzelm@20809
   132
  qed
wenzelm@20809
   133
next
wenzelm@20809
   134
  assume ?rhs
wenzelm@20809
   135
  show ?lhs
wenzelm@20809
   136
  proof
wenzelm@20809
   137
    assume "finite S"
wenzelm@20809
   138
    then obtain m where "S \<subseteq> {..m}"
wenzelm@20809
   139
      by (auto simp add: finite_nat_iff_bounded_le)
wenzelm@20809
   140
    then have "\<forall>n. m<n \<longrightarrow> n\<notin>S" by auto
wenzelm@20809
   141
    with `?rhs` show False by blast
wenzelm@20809
   142
  qed
wenzelm@20809
   143
qed
wenzelm@20809
   144
wenzelm@20809
   145
lemma infinite_nat_iff_unbounded_le:
wenzelm@20809
   146
  "infinite (S::nat set) = (\<forall>m. \<exists>n. m\<le>n \<and> n\<in>S)"
wenzelm@20809
   147
  (is "?lhs = ?rhs")
wenzelm@20809
   148
proof
wenzelm@20809
   149
  assume ?lhs
wenzelm@20809
   150
  show ?rhs
wenzelm@20809
   151
  proof
wenzelm@20809
   152
    fix m
wenzelm@20809
   153
    from `?lhs` obtain n where "m<n \<and> n\<in>S"
wenzelm@20809
   154
      by (auto simp add: infinite_nat_iff_unbounded)
wenzelm@20809
   155
    then have "m\<le>n \<and> n\<in>S" by simp
wenzelm@20809
   156
    then show "\<exists>n. m \<le> n \<and> n \<in> S" ..
wenzelm@20809
   157
  qed
wenzelm@20809
   158
next
wenzelm@20809
   159
  assume ?rhs
wenzelm@20809
   160
  show ?lhs
wenzelm@20809
   161
  proof (auto simp add: infinite_nat_iff_unbounded)
wenzelm@20809
   162
    fix m
wenzelm@20809
   163
    from `?rhs` obtain n where "Suc m \<le> n \<and> n\<in>S"
wenzelm@20809
   164
      by blast
wenzelm@20809
   165
    then have "m<n \<and> n\<in>S" by simp
wenzelm@20809
   166
    then show "\<exists>n. m < n \<and> n \<in> S" ..
wenzelm@20809
   167
  qed
wenzelm@20809
   168
qed
wenzelm@20809
   169
wenzelm@20809
   170
text {*
wenzelm@20809
   171
  For a set of natural numbers to be infinite, it is enough to know
wenzelm@20809
   172
  that for any number larger than some @{text k}, there is some larger
wenzelm@20809
   173
  number that is an element of the set.
wenzelm@20809
   174
*}
wenzelm@20809
   175
wenzelm@20809
   176
lemma unbounded_k_infinite:
wenzelm@20809
   177
  assumes k: "\<forall>m. k<m \<longrightarrow> (\<exists>n. m<n \<and> n\<in>S)"
wenzelm@20809
   178
  shows "infinite (S::nat set)"
wenzelm@20809
   179
proof -
wenzelm@20809
   180
  {
wenzelm@20809
   181
    fix m have "\<exists>n. m<n \<and> n\<in>S"
wenzelm@20809
   182
    proof (cases "k<m")
wenzelm@20809
   183
      case True
wenzelm@20809
   184
      with k show ?thesis by blast
wenzelm@20809
   185
    next
wenzelm@20809
   186
      case False
wenzelm@20809
   187
      from k obtain n where "Suc k < n \<and> n\<in>S" by auto
wenzelm@20809
   188
      with False have "m<n \<and> n\<in>S" by auto
wenzelm@20809
   189
      then show ?thesis ..
wenzelm@20809
   190
    qed
wenzelm@20809
   191
  }
wenzelm@20809
   192
  then show ?thesis
wenzelm@20809
   193
    by (auto simp add: infinite_nat_iff_unbounded)
wenzelm@20809
   194
qed
wenzelm@20809
   195
wenzelm@20809
   196
lemma nat_infinite [simp]: "infinite (UNIV :: nat set)"
wenzelm@20809
   197
  by (auto simp add: infinite_nat_iff_unbounded)
wenzelm@20809
   198
wenzelm@20809
   199
lemma nat_not_finite [elim]: "finite (UNIV::nat set) \<Longrightarrow> R"
wenzelm@20809
   200
  by simp
wenzelm@20809
   201
wenzelm@20809
   202
text {*
wenzelm@20809
   203
  Every infinite set contains a countable subset. More precisely we
wenzelm@20809
   204
  show that a set @{text S} is infinite if and only if there exists an
wenzelm@20809
   205
  injective function from the naturals into @{text S}.
wenzelm@20809
   206
*}
wenzelm@20809
   207
wenzelm@20809
   208
lemma range_inj_infinite:
wenzelm@20809
   209
  "inj (f::nat \<Rightarrow> 'a) \<Longrightarrow> infinite (range f)"
wenzelm@20809
   210
proof
wenzelm@20809
   211
  assume "inj f"
wenzelm@20809
   212
    and  "finite (range f)"
wenzelm@20809
   213
  then have "finite (UNIV::nat set)"
wenzelm@20809
   214
    by (auto intro: finite_imageD simp del: nat_infinite)
wenzelm@20809
   215
  then show False by simp
wenzelm@20809
   216
qed
wenzelm@20809
   217
wenzelm@20809
   218
text {*
wenzelm@20809
   219
  The ``only if'' direction is harder because it requires the
wenzelm@20809
   220
  construction of a sequence of pairwise different elements of an
wenzelm@20809
   221
  infinite set @{text S}. The idea is to construct a sequence of
wenzelm@20809
   222
  non-empty and infinite subsets of @{text S} obtained by successively
wenzelm@20809
   223
  removing elements of @{text S}.
wenzelm@20809
   224
*}
wenzelm@20809
   225
wenzelm@20809
   226
lemma linorder_injI:
wenzelm@20809
   227
  assumes hyp: "!!x y. x < (y::'a::linorder) ==> f x \<noteq> f y"
wenzelm@20809
   228
  shows "inj f"
wenzelm@20809
   229
proof (rule inj_onI)
wenzelm@20809
   230
  fix x y
wenzelm@20809
   231
  assume f_eq: "f x = f y"
wenzelm@20809
   232
  show "x = y"
wenzelm@20809
   233
  proof (rule linorder_cases)
wenzelm@20809
   234
    assume "x < y"
wenzelm@20809
   235
    with hyp have "f x \<noteq> f y" by blast
wenzelm@20809
   236
    with f_eq show ?thesis by simp
wenzelm@20809
   237
  next
wenzelm@20809
   238
    assume "x = y"
wenzelm@20809
   239
    then show ?thesis .
wenzelm@20809
   240
  next
wenzelm@20809
   241
    assume "y < x"
wenzelm@20809
   242
    with hyp have "f y \<noteq> f x" by blast
wenzelm@20809
   243
    with f_eq show ?thesis by simp
wenzelm@20809
   244
  qed
wenzelm@20809
   245
qed
wenzelm@20809
   246
wenzelm@20809
   247
lemma infinite_countable_subset:
wenzelm@20809
   248
  assumes inf: "infinite (S::'a set)"
wenzelm@20809
   249
  shows "\<exists>f. inj (f::nat \<Rightarrow> 'a) \<and> range f \<subseteq> S"
wenzelm@20809
   250
proof -
wenzelm@20809
   251
  def Sseq \<equiv> "nat_rec S (\<lambda>n T. T - {SOME e. e \<in> T})"
wenzelm@20809
   252
  def pick \<equiv> "\<lambda>n. (SOME e. e \<in> Sseq n)"
wenzelm@20809
   253
  have Sseq_inf: "\<And>n. infinite (Sseq n)"
wenzelm@20809
   254
  proof -
wenzelm@20809
   255
    fix n
wenzelm@20809
   256
    show "infinite (Sseq n)"
wenzelm@20809
   257
    proof (induct n)
wenzelm@20809
   258
      from inf show "infinite (Sseq 0)"
wenzelm@20809
   259
        by (simp add: Sseq_def)
wenzelm@20809
   260
    next
wenzelm@20809
   261
      fix n
wenzelm@20809
   262
      assume "infinite (Sseq n)" then show "infinite (Sseq (Suc n))"
wenzelm@20809
   263
        by (simp add: Sseq_def infinite_remove)
wenzelm@20809
   264
    qed
wenzelm@20809
   265
  qed
wenzelm@20809
   266
  have Sseq_S: "\<And>n. Sseq n \<subseteq> S"
wenzelm@20809
   267
  proof -
wenzelm@20809
   268
    fix n
wenzelm@20809
   269
    show "Sseq n \<subseteq> S"
wenzelm@20809
   270
      by (induct n) (auto simp add: Sseq_def)
wenzelm@20809
   271
  qed
wenzelm@20809
   272
  have Sseq_pick: "\<And>n. pick n \<in> Sseq n"
wenzelm@20809
   273
  proof -
wenzelm@20809
   274
    fix n
wenzelm@20809
   275
    show "pick n \<in> Sseq n"
wenzelm@20809
   276
    proof (unfold pick_def, rule someI_ex)
wenzelm@20809
   277
      from Sseq_inf have "infinite (Sseq n)" .
wenzelm@20809
   278
      then have "Sseq n \<noteq> {}" by auto
wenzelm@20809
   279
      then show "\<exists>x. x \<in> Sseq n" by auto
wenzelm@20809
   280
    qed
wenzelm@20809
   281
  qed
wenzelm@20809
   282
  with Sseq_S have rng: "range pick \<subseteq> S"
wenzelm@20809
   283
    by auto
wenzelm@20809
   284
  have pick_Sseq_gt: "\<And>n m. pick n \<notin> Sseq (n + Suc m)"
wenzelm@20809
   285
  proof -
wenzelm@20809
   286
    fix n m
wenzelm@20809
   287
    show "pick n \<notin> Sseq (n + Suc m)"
wenzelm@20809
   288
      by (induct m) (auto simp add: Sseq_def pick_def)
wenzelm@20809
   289
  qed
wenzelm@20809
   290
  have pick_pick: "\<And>n m. pick n \<noteq> pick (n + Suc m)"
wenzelm@20809
   291
  proof -
wenzelm@20809
   292
    fix n m
wenzelm@20809
   293
    from Sseq_pick have "pick (n + Suc m) \<in> Sseq (n + Suc m)" .
wenzelm@20809
   294
    moreover from pick_Sseq_gt
wenzelm@20809
   295
    have "pick n \<notin> Sseq (n + Suc m)" .
wenzelm@20809
   296
    ultimately show "pick n \<noteq> pick (n + Suc m)"
wenzelm@20809
   297
      by auto
wenzelm@20809
   298
  qed
wenzelm@20809
   299
  have inj: "inj pick"
wenzelm@20809
   300
  proof (rule linorder_injI)
wenzelm@20809
   301
    fix i j :: nat
wenzelm@20809
   302
    assume "i < j"
wenzelm@20809
   303
    show "pick i \<noteq> pick j"
wenzelm@20809
   304
    proof
wenzelm@20809
   305
      assume eq: "pick i = pick j"
wenzelm@20809
   306
      from `i < j` obtain k where "j = i + Suc k"
wenzelm@20809
   307
        by (auto simp add: less_iff_Suc_add)
wenzelm@20809
   308
      with pick_pick have "pick i \<noteq> pick j" by simp
wenzelm@20809
   309
      with eq show False by simp
wenzelm@20809
   310
    qed
wenzelm@20809
   311
  qed
wenzelm@20809
   312
  from rng inj show ?thesis by auto
wenzelm@20809
   313
qed
wenzelm@20809
   314
wenzelm@20809
   315
lemma infinite_iff_countable_subset:
wenzelm@20809
   316
    "infinite S = (\<exists>f. inj (f::nat \<Rightarrow> 'a) \<and> range f \<subseteq> S)"
wenzelm@20809
   317
  by (auto simp add: infinite_countable_subset range_inj_infinite infinite_super)
wenzelm@20809
   318
wenzelm@20809
   319
text {*
wenzelm@20809
   320
  For any function with infinite domain and finite range there is some
wenzelm@20809
   321
  element that is the image of infinitely many domain elements.  In
wenzelm@20809
   322
  particular, any infinite sequence of elements from a finite set
wenzelm@20809
   323
  contains some element that occurs infinitely often.
wenzelm@20809
   324
*}
wenzelm@20809
   325
wenzelm@20809
   326
lemma inf_img_fin_dom:
wenzelm@20809
   327
  assumes img: "finite (f`A)" and dom: "infinite A"
wenzelm@20809
   328
  shows "\<exists>y \<in> f`A. infinite (f -` {y})"
wenzelm@20809
   329
proof (rule ccontr)
wenzelm@20809
   330
  assume "\<not> ?thesis"
wenzelm@20809
   331
  with img have "finite (UN y:f`A. f -` {y})" by (blast intro: finite_UN_I)
wenzelm@20809
   332
  moreover have "A \<subseteq> (UN y:f`A. f -` {y})" by auto
wenzelm@20809
   333
  moreover note dom
wenzelm@20809
   334
  ultimately show False by (simp add: infinite_super)
wenzelm@20809
   335
qed
wenzelm@20809
   336
wenzelm@20809
   337
lemma inf_img_fin_domE:
wenzelm@20809
   338
  assumes "finite (f`A)" and "infinite A"
wenzelm@20809
   339
  obtains y where "y \<in> f`A" and "infinite (f -` {y})"
wenzelm@20809
   340
  using prems by (blast dest: inf_img_fin_dom)
wenzelm@20809
   341
wenzelm@20809
   342
wenzelm@20809
   343
subsection "Infinitely Many and Almost All"
wenzelm@20809
   344
wenzelm@20809
   345
text {*
wenzelm@20809
   346
  We often need to reason about the existence of infinitely many
wenzelm@20809
   347
  (resp., all but finitely many) objects satisfying some predicate, so
wenzelm@20809
   348
  we introduce corresponding binders and their proof rules.
wenzelm@20809
   349
*}
wenzelm@20809
   350
wenzelm@20809
   351
definition
wenzelm@20809
   352
  Inf_many :: "('a \<Rightarrow> bool) \<Rightarrow> bool"      (binder "INF " 10)
wenzelm@20809
   353
  "Inf_many P = infinite {x. P x}"
wenzelm@20809
   354
  Alm_all  :: "('a \<Rightarrow> bool) \<Rightarrow> bool"      (binder "MOST " 10)
wenzelm@20809
   355
  "Alm_all P = (\<not> (INF x. \<not> P x))"
wenzelm@20809
   356
wenzelm@20809
   357
const_syntax (xsymbols)
wenzelm@20809
   358
  Inf_many  (binder "\<exists>\<^sub>\<infinity>" 10)
wenzelm@20809
   359
  Alm_all  (binder "\<forall>\<^sub>\<infinity>" 10)
wenzelm@20809
   360
wenzelm@20809
   361
const_syntax (HTML output)
wenzelm@20809
   362
  Inf_many  (binder "\<exists>\<^sub>\<infinity>" 10)
wenzelm@20809
   363
  Alm_all  (binder "\<forall>\<^sub>\<infinity>" 10)
wenzelm@20809
   364
wenzelm@20809
   365
lemma INF_EX:
wenzelm@20809
   366
  "(\<exists>\<^sub>\<infinity>x. P x) \<Longrightarrow> (\<exists>x. P x)"
wenzelm@20809
   367
  unfolding Inf_many_def
wenzelm@20809
   368
proof (rule ccontr)
wenzelm@20809
   369
  assume inf: "infinite {x. P x}"
wenzelm@20809
   370
  assume "\<not> ?thesis" then have "{x. P x} = {}" by simp
wenzelm@20809
   371
  then have "finite {x. P x}" by simp
wenzelm@20809
   372
  with inf show False by simp
wenzelm@20809
   373
qed
wenzelm@20809
   374
wenzelm@20809
   375
lemma MOST_iff_finiteNeg: "(\<forall>\<^sub>\<infinity>x. P x) = finite {x. \<not> P x}"
wenzelm@20809
   376
  by (simp add: Alm_all_def Inf_many_def)
wenzelm@20809
   377
wenzelm@20809
   378
lemma ALL_MOST: "\<forall>x. P x \<Longrightarrow> \<forall>\<^sub>\<infinity>x. P x"
wenzelm@20809
   379
  by (simp add: MOST_iff_finiteNeg)
wenzelm@20809
   380
wenzelm@20809
   381
lemma INF_mono:
wenzelm@20809
   382
  assumes inf: "\<exists>\<^sub>\<infinity>x. P x" and q: "\<And>x. P x \<Longrightarrow> Q x"
wenzelm@20809
   383
  shows "\<exists>\<^sub>\<infinity>x. Q x"
wenzelm@20809
   384
proof -
wenzelm@20809
   385
  from inf have "infinite {x. P x}" unfolding Inf_many_def .
wenzelm@20809
   386
  moreover from q have "{x. P x} \<subseteq> {x. Q x}" by auto
wenzelm@20809
   387
  ultimately show ?thesis
wenzelm@20809
   388
    by (simp add: Inf_many_def infinite_super)
wenzelm@20809
   389
qed
wenzelm@20809
   390
wenzelm@20809
   391
lemma MOST_mono: "\<forall>\<^sub>\<infinity>x. P x \<Longrightarrow> (\<And>x. P x \<Longrightarrow> Q x) \<Longrightarrow> \<forall>\<^sub>\<infinity>x. Q x"
wenzelm@20809
   392
  unfolding Alm_all_def by (blast intro: INF_mono)
wenzelm@20809
   393
wenzelm@20809
   394
lemma INF_nat: "(\<exists>\<^sub>\<infinity>n. P (n::nat)) = (\<forall>m. \<exists>n. m<n \<and> P n)"
wenzelm@20809
   395
  by (simp add: Inf_many_def infinite_nat_iff_unbounded)
wenzelm@20809
   396
wenzelm@20809
   397
lemma INF_nat_le: "(\<exists>\<^sub>\<infinity>n. P (n::nat)) = (\<forall>m. \<exists>n. m\<le>n \<and> P n)"
wenzelm@20809
   398
  by (simp add: Inf_many_def infinite_nat_iff_unbounded_le)
wenzelm@20809
   399
wenzelm@20809
   400
lemma MOST_nat: "(\<forall>\<^sub>\<infinity>n. P (n::nat)) = (\<exists>m. \<forall>n. m<n \<longrightarrow> P n)"
wenzelm@20809
   401
  by (simp add: Alm_all_def INF_nat)
wenzelm@20809
   402
wenzelm@20809
   403
lemma MOST_nat_le: "(\<forall>\<^sub>\<infinity>n. P (n::nat)) = (\<exists>m. \<forall>n. m\<le>n \<longrightarrow> P n)"
wenzelm@20809
   404
  by (simp add: Alm_all_def INF_nat_le)
wenzelm@20809
   405
wenzelm@20809
   406
wenzelm@20809
   407
subsection "Enumeration of an Infinite Set"
wenzelm@20809
   408
wenzelm@20809
   409
text {*
wenzelm@20809
   410
  The set's element type must be wellordered (e.g. the natural numbers).
wenzelm@20809
   411
*}
wenzelm@20809
   412
wenzelm@20809
   413
consts
wenzelm@20809
   414
  enumerate   :: "'a::wellorder set => (nat => 'a::wellorder)"
wenzelm@20809
   415
primrec
wenzelm@20809
   416
  enumerate_0:   "enumerate S 0       = (LEAST n. n \<in> S)"
wenzelm@20809
   417
  enumerate_Suc: "enumerate S (Suc n) = enumerate (S - {LEAST n. n \<in> S}) n"
wenzelm@20809
   418
wenzelm@20809
   419
lemma enumerate_Suc':
wenzelm@20809
   420
    "enumerate S (Suc n) = enumerate (S - {enumerate S 0}) n"
wenzelm@20809
   421
  by simp
wenzelm@20809
   422
wenzelm@20809
   423
lemma enumerate_in_set: "infinite S \<Longrightarrow> enumerate S n : S"
wenzelm@20809
   424
  apply (induct n arbitrary: S)
wenzelm@20809
   425
   apply (fastsimp intro: LeastI dest!: infinite_imp_nonempty)
wenzelm@20809
   426
  apply (fastsimp iff: finite_Diff_singleton)
wenzelm@20809
   427
  done
wenzelm@20809
   428
wenzelm@20809
   429
declare enumerate_0 [simp del] enumerate_Suc [simp del]
wenzelm@20809
   430
wenzelm@20809
   431
lemma enumerate_step: "infinite S \<Longrightarrow> enumerate S n < enumerate S (Suc n)"
wenzelm@20809
   432
  apply (induct n arbitrary: S)
wenzelm@20809
   433
   apply (rule order_le_neq_trans)
wenzelm@20809
   434
    apply (simp add: enumerate_0 Least_le enumerate_in_set)
wenzelm@20809
   435
   apply (simp only: enumerate_Suc')
wenzelm@20809
   436
   apply (subgoal_tac "enumerate (S - {enumerate S 0}) 0 : S - {enumerate S 0}")
wenzelm@20809
   437
    apply (blast intro: sym)
wenzelm@20809
   438
   apply (simp add: enumerate_in_set del: Diff_iff)
wenzelm@20809
   439
  apply (simp add: enumerate_Suc')
wenzelm@20809
   440
  done
wenzelm@20809
   441
wenzelm@20809
   442
lemma enumerate_mono: "m<n \<Longrightarrow> infinite S \<Longrightarrow> enumerate S m < enumerate S n"
wenzelm@20809
   443
  apply (erule less_Suc_induct)
wenzelm@20809
   444
  apply (auto intro: enumerate_step)
wenzelm@20809
   445
  done
wenzelm@20809
   446
wenzelm@20809
   447
wenzelm@20809
   448
subsection "Miscellaneous"
wenzelm@20809
   449
wenzelm@20809
   450
text {*
wenzelm@20809
   451
  A few trivial lemmas about sets that contain at most one element.
wenzelm@20809
   452
  These simplify the reasoning about deterministic automata.
wenzelm@20809
   453
*}
wenzelm@20809
   454
wenzelm@20809
   455
definition
wenzelm@20809
   456
  atmost_one :: "'a set \<Rightarrow> bool"
wenzelm@20809
   457
  "atmost_one S = (\<forall>x y. x\<in>S \<and> y\<in>S \<longrightarrow> x=y)"
wenzelm@20809
   458
wenzelm@20809
   459
lemma atmost_one_empty: "S = {} \<Longrightarrow> atmost_one S"
wenzelm@20809
   460
  by (simp add: atmost_one_def)
wenzelm@20809
   461
wenzelm@20809
   462
lemma atmost_one_singleton: "S = {x} \<Longrightarrow> atmost_one S"
wenzelm@20809
   463
  by (simp add: atmost_one_def)
wenzelm@20809
   464
wenzelm@20809
   465
lemma atmost_one_unique [elim]: "atmost_one S \<Longrightarrow> x \<in> S \<Longrightarrow> y \<in> S \<Longrightarrow> y = x"
wenzelm@20809
   466
  by (simp add: atmost_one_def)
wenzelm@20809
   467
wenzelm@20809
   468
end