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