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