src/HOL/Library/Infinite_Set.thy
author berghofe
Sat Mar 10 16:25:57 2007 +0100 (2007-03-10)
changeset 22432 1d00d26fee0d
parent 22226 699385e6cb45
child 23394 474ff28210c0
permissions -rw-r--r--
Renamed INF to INFM to avoid clash with INF operator defined in FixedPoint theory.
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@21256
     9
imports Main
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@21404
    21
  infinite :: "'a set \<Rightarrow> bool" where
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
paulson@22226
   218
lemma int_infinite [simp]:
paulson@22226
   219
  shows "infinite (UNIV::int set)"
paulson@22226
   220
proof -
paulson@22226
   221
  from inj_int have "infinite (range int)" by (rule range_inj_infinite)
paulson@22226
   222
  moreover 
paulson@22226
   223
  have "range int \<subseteq> (UNIV::int set)" by simp
paulson@22226
   224
  ultimately show "infinite (UNIV::int set)" by (simp add: infinite_super)
paulson@22226
   225
qed
paulson@22226
   226
wenzelm@20809
   227
text {*
wenzelm@20809
   228
  The ``only if'' direction is harder because it requires the
wenzelm@20809
   229
  construction of a sequence of pairwise different elements of an
wenzelm@20809
   230
  infinite set @{text S}. The idea is to construct a sequence of
wenzelm@20809
   231
  non-empty and infinite subsets of @{text S} obtained by successively
wenzelm@20809
   232
  removing elements of @{text S}.
wenzelm@20809
   233
*}
wenzelm@20809
   234
wenzelm@20809
   235
lemma linorder_injI:
wenzelm@20809
   236
  assumes hyp: "!!x y. x < (y::'a::linorder) ==> f x \<noteq> f y"
wenzelm@20809
   237
  shows "inj f"
wenzelm@20809
   238
proof (rule inj_onI)
wenzelm@20809
   239
  fix x y
wenzelm@20809
   240
  assume f_eq: "f x = f y"
wenzelm@20809
   241
  show "x = y"
wenzelm@20809
   242
  proof (rule linorder_cases)
wenzelm@20809
   243
    assume "x < y"
wenzelm@20809
   244
    with hyp have "f x \<noteq> f y" by blast
wenzelm@20809
   245
    with f_eq show ?thesis by simp
wenzelm@20809
   246
  next
wenzelm@20809
   247
    assume "x = y"
wenzelm@20809
   248
    then show ?thesis .
wenzelm@20809
   249
  next
wenzelm@20809
   250
    assume "y < x"
wenzelm@20809
   251
    with hyp have "f y \<noteq> f x" by blast
wenzelm@20809
   252
    with f_eq show ?thesis by simp
wenzelm@20809
   253
  qed
wenzelm@20809
   254
qed
wenzelm@20809
   255
wenzelm@20809
   256
lemma infinite_countable_subset:
wenzelm@20809
   257
  assumes inf: "infinite (S::'a set)"
wenzelm@20809
   258
  shows "\<exists>f. inj (f::nat \<Rightarrow> 'a) \<and> range f \<subseteq> S"
wenzelm@20809
   259
proof -
wenzelm@20809
   260
  def Sseq \<equiv> "nat_rec S (\<lambda>n T. T - {SOME e. e \<in> T})"
wenzelm@20809
   261
  def pick \<equiv> "\<lambda>n. (SOME e. e \<in> Sseq n)"
wenzelm@20809
   262
  have Sseq_inf: "\<And>n. infinite (Sseq n)"
wenzelm@20809
   263
  proof -
wenzelm@20809
   264
    fix n
wenzelm@20809
   265
    show "infinite (Sseq n)"
wenzelm@20809
   266
    proof (induct n)
wenzelm@20809
   267
      from inf show "infinite (Sseq 0)"
wenzelm@20809
   268
        by (simp add: Sseq_def)
wenzelm@20809
   269
    next
wenzelm@20809
   270
      fix n
wenzelm@20809
   271
      assume "infinite (Sseq n)" then show "infinite (Sseq (Suc n))"
wenzelm@20809
   272
        by (simp add: Sseq_def infinite_remove)
wenzelm@20809
   273
    qed
wenzelm@20809
   274
  qed
wenzelm@20809
   275
  have Sseq_S: "\<And>n. Sseq n \<subseteq> S"
wenzelm@20809
   276
  proof -
wenzelm@20809
   277
    fix n
wenzelm@20809
   278
    show "Sseq n \<subseteq> S"
wenzelm@20809
   279
      by (induct n) (auto simp add: Sseq_def)
wenzelm@20809
   280
  qed
wenzelm@20809
   281
  have Sseq_pick: "\<And>n. pick n \<in> Sseq n"
wenzelm@20809
   282
  proof -
wenzelm@20809
   283
    fix n
wenzelm@20809
   284
    show "pick n \<in> Sseq n"
wenzelm@20809
   285
    proof (unfold pick_def, rule someI_ex)
wenzelm@20809
   286
      from Sseq_inf have "infinite (Sseq n)" .
wenzelm@20809
   287
      then have "Sseq n \<noteq> {}" by auto
wenzelm@20809
   288
      then show "\<exists>x. x \<in> Sseq n" by auto
wenzelm@20809
   289
    qed
wenzelm@20809
   290
  qed
wenzelm@20809
   291
  with Sseq_S have rng: "range pick \<subseteq> S"
wenzelm@20809
   292
    by auto
wenzelm@20809
   293
  have pick_Sseq_gt: "\<And>n m. pick n \<notin> Sseq (n + Suc m)"
wenzelm@20809
   294
  proof -
wenzelm@20809
   295
    fix n m
wenzelm@20809
   296
    show "pick n \<notin> Sseq (n + Suc m)"
wenzelm@20809
   297
      by (induct m) (auto simp add: Sseq_def pick_def)
wenzelm@20809
   298
  qed
wenzelm@20809
   299
  have pick_pick: "\<And>n m. pick n \<noteq> pick (n + Suc m)"
wenzelm@20809
   300
  proof -
wenzelm@20809
   301
    fix n m
wenzelm@20809
   302
    from Sseq_pick have "pick (n + Suc m) \<in> Sseq (n + Suc m)" .
wenzelm@20809
   303
    moreover from pick_Sseq_gt
wenzelm@20809
   304
    have "pick n \<notin> Sseq (n + Suc m)" .
wenzelm@20809
   305
    ultimately show "pick n \<noteq> pick (n + Suc m)"
wenzelm@20809
   306
      by auto
wenzelm@20809
   307
  qed
wenzelm@20809
   308
  have inj: "inj pick"
wenzelm@20809
   309
  proof (rule linorder_injI)
wenzelm@20809
   310
    fix i j :: nat
wenzelm@20809
   311
    assume "i < j"
wenzelm@20809
   312
    show "pick i \<noteq> pick j"
wenzelm@20809
   313
    proof
wenzelm@20809
   314
      assume eq: "pick i = pick j"
wenzelm@20809
   315
      from `i < j` obtain k where "j = i + Suc k"
wenzelm@20809
   316
        by (auto simp add: less_iff_Suc_add)
wenzelm@20809
   317
      with pick_pick have "pick i \<noteq> pick j" by simp
wenzelm@20809
   318
      with eq show False by simp
wenzelm@20809
   319
    qed
wenzelm@20809
   320
  qed
wenzelm@20809
   321
  from rng inj show ?thesis by auto
wenzelm@20809
   322
qed
wenzelm@20809
   323
wenzelm@20809
   324
lemma infinite_iff_countable_subset:
wenzelm@20809
   325
    "infinite S = (\<exists>f. inj (f::nat \<Rightarrow> 'a) \<and> range f \<subseteq> S)"
wenzelm@20809
   326
  by (auto simp add: infinite_countable_subset range_inj_infinite infinite_super)
wenzelm@20809
   327
wenzelm@20809
   328
text {*
wenzelm@20809
   329
  For any function with infinite domain and finite range there is some
wenzelm@20809
   330
  element that is the image of infinitely many domain elements.  In
wenzelm@20809
   331
  particular, any infinite sequence of elements from a finite set
wenzelm@20809
   332
  contains some element that occurs infinitely often.
wenzelm@20809
   333
*}
wenzelm@20809
   334
wenzelm@20809
   335
lemma inf_img_fin_dom:
wenzelm@20809
   336
  assumes img: "finite (f`A)" and dom: "infinite A"
wenzelm@20809
   337
  shows "\<exists>y \<in> f`A. infinite (f -` {y})"
wenzelm@20809
   338
proof (rule ccontr)
wenzelm@20809
   339
  assume "\<not> ?thesis"
wenzelm@20809
   340
  with img have "finite (UN y:f`A. f -` {y})" by (blast intro: finite_UN_I)
wenzelm@20809
   341
  moreover have "A \<subseteq> (UN y:f`A. f -` {y})" by auto
wenzelm@20809
   342
  moreover note dom
wenzelm@20809
   343
  ultimately show False by (simp add: infinite_super)
wenzelm@20809
   344
qed
wenzelm@20809
   345
wenzelm@20809
   346
lemma inf_img_fin_domE:
wenzelm@20809
   347
  assumes "finite (f`A)" and "infinite A"
wenzelm@20809
   348
  obtains y where "y \<in> f`A" and "infinite (f -` {y})"
wenzelm@20809
   349
  using prems by (blast dest: inf_img_fin_dom)
wenzelm@20809
   350
wenzelm@20809
   351
wenzelm@20809
   352
subsection "Infinitely Many and Almost All"
wenzelm@20809
   353
wenzelm@20809
   354
text {*
wenzelm@20809
   355
  We often need to reason about the existence of infinitely many
wenzelm@20809
   356
  (resp., all but finitely many) objects satisfying some predicate, so
wenzelm@20809
   357
  we introduce corresponding binders and their proof rules.
wenzelm@20809
   358
*}
wenzelm@20809
   359
wenzelm@20809
   360
definition
berghofe@22432
   361
  Inf_many :: "('a \<Rightarrow> bool) \<Rightarrow> bool"  (binder "INFM " 10) where
wenzelm@20809
   362
  "Inf_many P = infinite {x. P x}"
wenzelm@21404
   363
wenzelm@21404
   364
definition
wenzelm@21404
   365
  Alm_all :: "('a \<Rightarrow> bool) \<Rightarrow> bool"  (binder "MOST " 10) where
berghofe@22432
   366
  "Alm_all P = (\<not> (INFM x. \<not> P x))"
wenzelm@20809
   367
wenzelm@21210
   368
notation (xsymbols)
wenzelm@21404
   369
  Inf_many  (binder "\<exists>\<^sub>\<infinity>" 10) and
wenzelm@20809
   370
  Alm_all  (binder "\<forall>\<^sub>\<infinity>" 10)
wenzelm@20809
   371
wenzelm@21210
   372
notation (HTML output)
wenzelm@21404
   373
  Inf_many  (binder "\<exists>\<^sub>\<infinity>" 10) and
wenzelm@20809
   374
  Alm_all  (binder "\<forall>\<^sub>\<infinity>" 10)
wenzelm@20809
   375
wenzelm@20809
   376
lemma INF_EX:
wenzelm@20809
   377
  "(\<exists>\<^sub>\<infinity>x. P x) \<Longrightarrow> (\<exists>x. P x)"
wenzelm@20809
   378
  unfolding Inf_many_def
wenzelm@20809
   379
proof (rule ccontr)
wenzelm@20809
   380
  assume inf: "infinite {x. P x}"
wenzelm@20809
   381
  assume "\<not> ?thesis" then have "{x. P x} = {}" by simp
wenzelm@20809
   382
  then have "finite {x. P x}" by simp
wenzelm@20809
   383
  with inf show False by simp
wenzelm@20809
   384
qed
wenzelm@20809
   385
wenzelm@20809
   386
lemma MOST_iff_finiteNeg: "(\<forall>\<^sub>\<infinity>x. P x) = finite {x. \<not> P x}"
wenzelm@20809
   387
  by (simp add: Alm_all_def Inf_many_def)
wenzelm@20809
   388
wenzelm@20809
   389
lemma ALL_MOST: "\<forall>x. P x \<Longrightarrow> \<forall>\<^sub>\<infinity>x. P x"
wenzelm@20809
   390
  by (simp add: MOST_iff_finiteNeg)
wenzelm@20809
   391
wenzelm@20809
   392
lemma INF_mono:
wenzelm@20809
   393
  assumes inf: "\<exists>\<^sub>\<infinity>x. P x" and q: "\<And>x. P x \<Longrightarrow> Q x"
wenzelm@20809
   394
  shows "\<exists>\<^sub>\<infinity>x. Q x"
wenzelm@20809
   395
proof -
wenzelm@20809
   396
  from inf have "infinite {x. P x}" unfolding Inf_many_def .
wenzelm@20809
   397
  moreover from q have "{x. P x} \<subseteq> {x. Q x}" by auto
wenzelm@20809
   398
  ultimately show ?thesis
wenzelm@20809
   399
    by (simp add: Inf_many_def infinite_super)
wenzelm@20809
   400
qed
wenzelm@20809
   401
wenzelm@20809
   402
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
   403
  unfolding Alm_all_def by (blast intro: INF_mono)
wenzelm@20809
   404
wenzelm@20809
   405
lemma INF_nat: "(\<exists>\<^sub>\<infinity>n. P (n::nat)) = (\<forall>m. \<exists>n. m<n \<and> P n)"
wenzelm@20809
   406
  by (simp add: Inf_many_def infinite_nat_iff_unbounded)
wenzelm@20809
   407
wenzelm@20809
   408
lemma INF_nat_le: "(\<exists>\<^sub>\<infinity>n. P (n::nat)) = (\<forall>m. \<exists>n. m\<le>n \<and> P n)"
wenzelm@20809
   409
  by (simp add: Inf_many_def infinite_nat_iff_unbounded_le)
wenzelm@20809
   410
wenzelm@20809
   411
lemma MOST_nat: "(\<forall>\<^sub>\<infinity>n. P (n::nat)) = (\<exists>m. \<forall>n. m<n \<longrightarrow> P n)"
wenzelm@20809
   412
  by (simp add: Alm_all_def INF_nat)
wenzelm@20809
   413
wenzelm@20809
   414
lemma MOST_nat_le: "(\<forall>\<^sub>\<infinity>n. P (n::nat)) = (\<exists>m. \<forall>n. m\<le>n \<longrightarrow> P n)"
wenzelm@20809
   415
  by (simp add: Alm_all_def INF_nat_le)
wenzelm@20809
   416
wenzelm@20809
   417
wenzelm@20809
   418
subsection "Enumeration of an Infinite Set"
wenzelm@20809
   419
wenzelm@20809
   420
text {*
wenzelm@20809
   421
  The set's element type must be wellordered (e.g. the natural numbers).
wenzelm@20809
   422
*}
wenzelm@20809
   423
wenzelm@20809
   424
consts
wenzelm@20809
   425
  enumerate   :: "'a::wellorder set => (nat => 'a::wellorder)"
wenzelm@20809
   426
primrec
wenzelm@20809
   427
  enumerate_0:   "enumerate S 0       = (LEAST n. n \<in> S)"
wenzelm@20809
   428
  enumerate_Suc: "enumerate S (Suc n) = enumerate (S - {LEAST n. n \<in> S}) n"
wenzelm@20809
   429
wenzelm@20809
   430
lemma enumerate_Suc':
wenzelm@20809
   431
    "enumerate S (Suc n) = enumerate (S - {enumerate S 0}) n"
wenzelm@20809
   432
  by simp
wenzelm@20809
   433
wenzelm@20809
   434
lemma enumerate_in_set: "infinite S \<Longrightarrow> enumerate S n : S"
wenzelm@20809
   435
  apply (induct n arbitrary: S)
wenzelm@20809
   436
   apply (fastsimp intro: LeastI dest!: infinite_imp_nonempty)
wenzelm@20809
   437
  apply (fastsimp iff: finite_Diff_singleton)
wenzelm@20809
   438
  done
wenzelm@20809
   439
wenzelm@20809
   440
declare enumerate_0 [simp del] enumerate_Suc [simp del]
wenzelm@20809
   441
wenzelm@20809
   442
lemma enumerate_step: "infinite S \<Longrightarrow> enumerate S n < enumerate S (Suc n)"
wenzelm@20809
   443
  apply (induct n arbitrary: S)
wenzelm@20809
   444
   apply (rule order_le_neq_trans)
wenzelm@20809
   445
    apply (simp add: enumerate_0 Least_le enumerate_in_set)
wenzelm@20809
   446
   apply (simp only: enumerate_Suc')
wenzelm@20809
   447
   apply (subgoal_tac "enumerate (S - {enumerate S 0}) 0 : S - {enumerate S 0}")
wenzelm@20809
   448
    apply (blast intro: sym)
wenzelm@20809
   449
   apply (simp add: enumerate_in_set del: Diff_iff)
wenzelm@20809
   450
  apply (simp add: enumerate_Suc')
wenzelm@20809
   451
  done
wenzelm@20809
   452
wenzelm@20809
   453
lemma enumerate_mono: "m<n \<Longrightarrow> infinite S \<Longrightarrow> enumerate S m < enumerate S n"
wenzelm@20809
   454
  apply (erule less_Suc_induct)
wenzelm@20809
   455
  apply (auto intro: enumerate_step)
wenzelm@20809
   456
  done
wenzelm@20809
   457
wenzelm@20809
   458
wenzelm@20809
   459
subsection "Miscellaneous"
wenzelm@20809
   460
wenzelm@20809
   461
text {*
wenzelm@20809
   462
  A few trivial lemmas about sets that contain at most one element.
wenzelm@20809
   463
  These simplify the reasoning about deterministic automata.
wenzelm@20809
   464
*}
wenzelm@20809
   465
wenzelm@20809
   466
definition
wenzelm@21404
   467
  atmost_one :: "'a set \<Rightarrow> bool" where
wenzelm@20809
   468
  "atmost_one S = (\<forall>x y. x\<in>S \<and> y\<in>S \<longrightarrow> x=y)"
wenzelm@20809
   469
wenzelm@20809
   470
lemma atmost_one_empty: "S = {} \<Longrightarrow> atmost_one S"
wenzelm@20809
   471
  by (simp add: atmost_one_def)
wenzelm@20809
   472
wenzelm@20809
   473
lemma atmost_one_singleton: "S = {x} \<Longrightarrow> atmost_one S"
wenzelm@20809
   474
  by (simp add: atmost_one_def)
wenzelm@20809
   475
wenzelm@20809
   476
lemma atmost_one_unique [elim]: "atmost_one S \<Longrightarrow> x \<in> S \<Longrightarrow> y \<in> S \<Longrightarrow> y = x"
wenzelm@20809
   477
  by (simp add: atmost_one_def)
wenzelm@20809
   478
wenzelm@20809
   479
end