src/HOL/Library/Infinite_Set.thy
author traytel
Mon, 25 Nov 2013 10:14:29 +0100
changeset 54578 9387251b6a46
parent 54557 d71c2737ee21
child 54579 9733ab5c1df6
permissions -rw-r--r--
eliminated dependence of BNF on Infinite_Set by moving 3 theorems from the latter to Main
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27407
68e111812b83 rename lemmas INF_foo to INFM_foo; add new lemmas about MOST and INFM
huffman
parents: 27368
diff changeset
     1
(*  Title:      HOL/Library/Infinite_Set.thy
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
     2
    Author:     Stephan Merz
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
     3
*)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
     4
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
     5
header {* Infinite Sets and Related Concepts *}
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
     6
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
     7
theory Infinite_Set
30663
0b6aff7451b2 Main is (Complex_Main) base entry point in library theories
haftmann
parents: 29901
diff changeset
     8
imports Main
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
     9
begin
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    10
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    11
subsection "Infinite Sets"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    12
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    13
text {*
54557
d71c2737ee21 correctly account for dead variables when naming set functions
blanchet
parents: 53239
diff changeset
    14
  Some elementary facts about infinite sets, mostly by Stephan Merz.
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    15
  Beware! Because "infinite" merely abbreviates a negation, these
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    16
  lemmas may not work well with @{text "blast"}.
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    17
*}
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    18
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
    19
abbreviation infinite :: "'a set \<Rightarrow> bool"
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
    20
  where "infinite S \<equiv> \<not> finite S"
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    21
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    22
text {*
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    23
  Infinite sets are non-empty, and if we remove some elements from an
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    24
  infinite set, the result is still infinite.
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    25
*}
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    26
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
    27
lemma infinite_imp_nonempty: "infinite S \<Longrightarrow> S \<noteq> {}"
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    28
  by auto
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    29
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
    30
lemma infinite_remove: "infinite S \<Longrightarrow> infinite (S - {a})"
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    31
  by simp
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    32
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    33
lemma Diff_infinite_finite:
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    34
  assumes T: "finite T" and S: "infinite S"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    35
  shows "infinite (S - T)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    36
  using T
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    37
proof induct
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    38
  from S
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    39
  show "infinite (S - {})" by auto
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    40
next
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    41
  fix T x
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    42
  assume ih: "infinite (S - T)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    43
  have "S - (insert x T) = (S - T) - {x}"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    44
    by (rule Diff_insert)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    45
  with ih
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    46
  show "infinite (S - (insert x T))"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    47
    by (simp add: infinite_remove)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    48
qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    49
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    50
lemma Un_infinite: "infinite S \<Longrightarrow> infinite (S \<union> T)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    51
  by simp
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    52
35844
65258d2c3214 added lemma infinite_Un
Christian Urban <urbanc@in.tum.de>
parents: 35056
diff changeset
    53
lemma infinite_Un: "infinite (S \<union> T) \<longleftrightarrow> infinite S \<or> infinite T"
65258d2c3214 added lemma infinite_Un
Christian Urban <urbanc@in.tum.de>
parents: 35056
diff changeset
    54
  by simp
65258d2c3214 added lemma infinite_Un
Christian Urban <urbanc@in.tum.de>
parents: 35056
diff changeset
    55
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    56
lemma infinite_super:
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    57
  assumes T: "S \<subseteq> T" and S: "infinite S"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    58
  shows "infinite T"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    59
proof
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    60
  assume "finite T"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    61
  with T have "finite S" by (simp add: finite_subset)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    62
  with S show False by simp
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    63
qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    64
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    65
text {*
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    66
  As a concrete example, we prove that the set of natural numbers is
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    67
  infinite.
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    68
*}
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    69
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    70
lemma finite_nat_bounded:
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    71
  assumes S: "finite (S::nat set)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    72
  shows "\<exists>k. S \<subseteq> {..<k}"  (is "\<exists>k. ?bounded S k")
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
    73
  using S
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    74
proof induct
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    75
  have "?bounded {} 0" by simp
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    76
  then show "\<exists>k. ?bounded {} k" ..
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    77
next
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    78
  fix S x
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    79
  assume "\<exists>k. ?bounded S k"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    80
  then obtain k where k: "?bounded S k" ..
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    81
  show "\<exists>k. ?bounded (insert x S) k"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    82
  proof (cases "x < k")
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    83
    case True
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    84
    with k show ?thesis by auto
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    85
  next
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    86
    case False
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    87
    with k have "?bounded S (Suc x)" by auto
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    88
    then show ?thesis by auto
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    89
  qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    90
qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    91
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    92
lemma finite_nat_iff_bounded:
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
    93
  "finite (S::nat set) \<longleftrightarrow> (\<exists>k. S \<subseteq> {..<k})"  (is "?lhs \<longleftrightarrow> ?rhs")
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    94
proof
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    95
  assume ?lhs
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    96
  then show ?rhs by (rule finite_nat_bounded)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    97
next
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    98
  assume ?rhs
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    99
  then obtain k where "S \<subseteq> {..<k}" ..
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   100
  then show "finite S"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   101
    by (rule finite_subset) simp
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   102
qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   103
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   104
lemma finite_nat_iff_bounded_le:
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   105
  "finite (S::nat set) \<longleftrightarrow> (\<exists>k. S \<subseteq> {..k})"  (is "?lhs \<longleftrightarrow> ?rhs")
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   106
proof
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   107
  assume ?lhs
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   108
  then obtain k where "S \<subseteq> {..<k}"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   109
    by (blast dest: finite_nat_bounded)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   110
  then have "S \<subseteq> {..k}" by auto
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   111
  then show ?rhs ..
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   112
next
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   113
  assume ?rhs
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   114
  then obtain k where "S \<subseteq> {..k}" ..
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   115
  then show "finite S"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   116
    by (rule finite_subset) simp
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   117
qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   118
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   119
lemma infinite_nat_iff_unbounded:
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   120
  "infinite (S::nat set) \<longleftrightarrow> (\<forall>m. \<exists>n. m < n \<and> n \<in> S)"
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   121
  (is "?lhs \<longleftrightarrow> ?rhs")
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   122
proof
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   123
  assume ?lhs
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   124
  show ?rhs
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   125
  proof (rule ccontr)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   126
    assume "\<not> ?rhs"
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   127
    then obtain m where m: "\<forall>n. m < n \<longrightarrow> n \<notin> S" by blast
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   128
    then have "S \<subseteq> {..m}"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   129
      by (auto simp add: sym [OF linorder_not_less])
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   130
    with `?lhs` show False
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   131
      by (simp add: finite_nat_iff_bounded_le)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   132
  qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   133
next
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   134
  assume ?rhs
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   135
  show ?lhs
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   136
  proof
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   137
    assume "finite S"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   138
    then obtain m where "S \<subseteq> {..m}"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   139
      by (auto simp add: finite_nat_iff_bounded_le)
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   140
    then have "\<forall>n. m < n \<longrightarrow> n \<notin> S" by auto
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   141
    with `?rhs` show False by blast
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   142
  qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   143
qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   144
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   145
lemma infinite_nat_iff_unbounded_le:
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   146
  "infinite (S::nat set) \<longleftrightarrow> (\<forall>m. \<exists>n. m \<le> n \<and> n \<in> S)"
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   147
  (is "?lhs \<longleftrightarrow> ?rhs")
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   148
proof
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   149
  assume ?lhs
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   150
  show ?rhs
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   151
  proof
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   152
    fix m
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   153
    from `?lhs` obtain n where "m < n \<and> n \<in> S"
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   154
      by (auto simp add: infinite_nat_iff_unbounded)
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   155
    then have "m \<le> n \<and> n \<in> S" by simp
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   156
    then show "\<exists>n. m \<le> n \<and> n \<in> S" ..
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   157
  qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   158
next
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   159
  assume ?rhs
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   160
  show ?lhs
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   161
  proof (auto simp add: infinite_nat_iff_unbounded)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   162
    fix m
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   163
    from `?rhs` obtain n where "Suc m \<le> n \<and> n \<in> S"
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   164
      by blast
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   165
    then have "m < n \<and> n \<in> S" by simp
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   166
    then show "\<exists>n. m < n \<and> n \<in> S" ..
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   167
  qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   168
qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   169
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   170
text {*
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   171
  For a set of natural numbers to be infinite, it is enough to know
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   172
  that for any number larger than some @{text k}, there is some larger
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   173
  number that is an element of the set.
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   174
*}
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   175
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   176
lemma unbounded_k_infinite:
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   177
  assumes k: "\<forall>m. k < m \<longrightarrow> (\<exists>n. m < n \<and> n \<in> S)"
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   178
  shows "infinite (S::nat set)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   179
proof -
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   180
  {
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   181
    fix m have "\<exists>n. m < n \<and> n \<in> S"
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   182
    proof (cases "k < m")
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   183
      case True
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   184
      with k show ?thesis by blast
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   185
    next
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   186
      case False
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   187
      from k obtain n where "Suc k < n \<and> n \<in> S" by auto
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   188
      with False have "m < n \<and> n \<in> S" by auto
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   189
      then show ?thesis ..
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   190
    qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   191
  }
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   192
  then show ?thesis
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   193
    by (auto simp add: infinite_nat_iff_unbounded)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   194
qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   195
35056
d97b5c3af6d5 remove redundant theorem attributes
huffman
parents: 34941
diff changeset
   196
(* duplicates Finite_Set.infinite_UNIV_nat *)
d97b5c3af6d5 remove redundant theorem attributes
huffman
parents: 34941
diff changeset
   197
lemma nat_infinite: "infinite (UNIV :: nat set)"
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   198
  by (auto simp add: infinite_nat_iff_unbounded)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   199
35056
d97b5c3af6d5 remove redundant theorem attributes
huffman
parents: 34941
diff changeset
   200
lemma nat_not_finite: "finite (UNIV::nat set) \<Longrightarrow> R"
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   201
  by simp
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   202
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   203
lemma range_inj_infinite:
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   204
  "inj (f::nat \<Rightarrow> 'a) \<Longrightarrow> infinite (range f)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   205
proof
27407
68e111812b83 rename lemmas INF_foo to INFM_foo; add new lemmas about MOST and INFM
huffman
parents: 27368
diff changeset
   206
  assume "finite (range f)" and "inj f"
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   207
  then have "finite (UNIV::nat set)"
27407
68e111812b83 rename lemmas INF_foo to INFM_foo; add new lemmas about MOST and INFM
huffman
parents: 27368
diff changeset
   208
    by (rule finite_imageD)
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   209
  then show False by simp
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   210
qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   211
54578
9387251b6a46 eliminated dependence of BNF on Infinite_Set by moving 3 theorems from the latter to Main
traytel
parents: 54557
diff changeset
   212
(* duplicates Int.infinite_UNIV_int *)
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   213
lemma int_infinite [simp]: "infinite (UNIV::int set)"
22226
699385e6cb45 new theorem int_infinite
paulson
parents: 21404
diff changeset
   214
proof -
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   215
  from inj_int have "infinite (range int)"
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   216
    by (rule range_inj_infinite)
22226
699385e6cb45 new theorem int_infinite
paulson
parents: 21404
diff changeset
   217
  moreover 
699385e6cb45 new theorem int_infinite
paulson
parents: 21404
diff changeset
   218
  have "range int \<subseteq> (UNIV::int set)" by simp
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   219
  ultimately show "infinite (UNIV::int set)"
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   220
    by (simp add: infinite_super)
22226
699385e6cb45 new theorem int_infinite
paulson
parents: 21404
diff changeset
   221
qed
699385e6cb45 new theorem int_infinite
paulson
parents: 21404
diff changeset
   222
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   223
text {*
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   224
  For any function with infinite domain and finite range there is some
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   225
  element that is the image of infinitely many domain elements.  In
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   226
  particular, any infinite sequence of elements from a finite set
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   227
  contains some element that occurs infinitely often.
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   228
*}
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   229
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   230
lemma inf_img_fin_dom:
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   231
  assumes img: "finite (f`A)" and dom: "infinite A"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   232
  shows "\<exists>y \<in> f`A. infinite (f -` {y})"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   233
proof (rule ccontr)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   234
  assume "\<not> ?thesis"
40786
0a54cfc9add3 gave more standard finite set rules simp and intro attribute
nipkow
parents: 35844
diff changeset
   235
  with img have "finite (UN y:f`A. f -` {y})" by blast
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   236
  moreover have "A \<subseteq> (UN y:f`A. f -` {y})" by auto
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   237
  moreover note dom
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   238
  ultimately show False by (simp add: infinite_super)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   239
qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   240
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   241
lemma inf_img_fin_domE:
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   242
  assumes "finite (f`A)" and "infinite A"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   243
  obtains y where "y \<in> f`A" and "infinite (f -` {y})"
23394
474ff28210c0 tuned proofs;
wenzelm
parents: 22432
diff changeset
   244
  using assms by (blast dest: inf_img_fin_dom)
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   245
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   246
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   247
subsection "Infinitely Many and Almost All"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   248
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   249
text {*
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   250
  We often need to reason about the existence of infinitely many
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   251
  (resp., all but finitely many) objects satisfying some predicate, so
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   252
  we introduce corresponding binders and their proof rules.
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   253
*}
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   254
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   255
definition Inf_many :: "('a \<Rightarrow> bool) \<Rightarrow> bool"  (binder "INFM " 10)
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   256
  where "Inf_many P \<longleftrightarrow> infinite {x. P x}"
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21256
diff changeset
   257
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   258
definition Alm_all :: "('a \<Rightarrow> bool) \<Rightarrow> bool"  (binder "MOST " 10)
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   259
  where "Alm_all P \<longleftrightarrow> \<not> (INFM x. \<not> P x)"
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   260
21210
c17fd2df4e9e renamed 'const_syntax' to 'notation';
wenzelm
parents: 20809
diff changeset
   261
notation (xsymbols)
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21256
diff changeset
   262
  Inf_many  (binder "\<exists>\<^sub>\<infinity>" 10) and
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   263
  Alm_all  (binder "\<forall>\<^sub>\<infinity>" 10)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   264
21210
c17fd2df4e9e renamed 'const_syntax' to 'notation';
wenzelm
parents: 20809
diff changeset
   265
notation (HTML output)
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21256
diff changeset
   266
  Inf_many  (binder "\<exists>\<^sub>\<infinity>" 10) and
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   267
  Alm_all  (binder "\<forall>\<^sub>\<infinity>" 10)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   268
34112
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   269
lemma INFM_iff_infinite: "(INFM x. P x) \<longleftrightarrow> infinite {x. P x}"
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   270
  unfolding Inf_many_def ..
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   271
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   272
lemma MOST_iff_cofinite: "(MOST x. P x) \<longleftrightarrow> finite {x. \<not> P x}"
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   273
  unfolding Alm_all_def Inf_many_def by simp
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   274
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   275
(* legacy name *)
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   276
lemmas MOST_iff_finiteNeg = MOST_iff_cofinite
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   277
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   278
lemma not_INFM [simp]: "\<not> (INFM x. P x) \<longleftrightarrow> (MOST x. \<not> P x)"
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   279
  unfolding Alm_all_def not_not ..
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   280
34112
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   281
lemma not_MOST [simp]: "\<not> (MOST x. P x) \<longleftrightarrow> (INFM x. \<not> P x)"
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   282
  unfolding Alm_all_def not_not ..
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   283
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   284
lemma INFM_const [simp]: "(INFM x::'a. P) \<longleftrightarrow> P \<and> infinite (UNIV::'a set)"
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   285
  unfolding Inf_many_def by simp
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   286
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   287
lemma MOST_const [simp]: "(MOST x::'a. P) \<longleftrightarrow> P \<or> finite (UNIV::'a set)"
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   288
  unfolding Alm_all_def by simp
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   289
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   290
lemma INFM_EX: "(\<exists>\<^sub>\<infinity>x. P x) \<Longrightarrow> (\<exists>x. P x)"
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   291
  apply (erule contrapos_pp)
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   292
  apply simp
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   293
  done
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   294
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   295
lemma ALL_MOST: "\<forall>x. P x \<Longrightarrow> \<forall>\<^sub>\<infinity>x. P x"
34112
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   296
  by simp
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   297
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   298
lemma INFM_E:
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   299
  assumes "INFM x. P x"
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   300
  obtains x where "P x"
34112
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   301
  using INFM_EX [OF assms] by (rule exE)
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   302
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   303
lemma MOST_I:
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   304
  assumes "\<And>x. P x"
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   305
  shows "MOST x. P x"
34112
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   306
  using assms by simp
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   307
27407
68e111812b83 rename lemmas INF_foo to INFM_foo; add new lemmas about MOST and INFM
huffman
parents: 27368
diff changeset
   308
lemma INFM_mono:
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   309
  assumes inf: "\<exists>\<^sub>\<infinity>x. P x" and q: "\<And>x. P x \<Longrightarrow> Q x"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   310
  shows "\<exists>\<^sub>\<infinity>x. Q x"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   311
proof -
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   312
  from inf have "infinite {x. P x}" unfolding Inf_many_def .
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   313
  moreover from q have "{x. P x} \<subseteq> {x. Q x}" by auto
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   314
  ultimately show ?thesis
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   315
    by (simp add: Inf_many_def infinite_super)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   316
qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   317
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   318
lemma MOST_mono: "\<forall>\<^sub>\<infinity>x. P x \<Longrightarrow> (\<And>x. P x \<Longrightarrow> Q x) \<Longrightarrow> \<forall>\<^sub>\<infinity>x. Q x"
27407
68e111812b83 rename lemmas INF_foo to INFM_foo; add new lemmas about MOST and INFM
huffman
parents: 27368
diff changeset
   319
  unfolding Alm_all_def by (blast intro: INFM_mono)
68e111812b83 rename lemmas INF_foo to INFM_foo; add new lemmas about MOST and INFM
huffman
parents: 27368
diff changeset
   320
68e111812b83 rename lemmas INF_foo to INFM_foo; add new lemmas about MOST and INFM
huffman
parents: 27368
diff changeset
   321
lemma INFM_disj_distrib:
68e111812b83 rename lemmas INF_foo to INFM_foo; add new lemmas about MOST and INFM
huffman
parents: 27368
diff changeset
   322
  "(\<exists>\<^sub>\<infinity>x. P x \<or> Q x) \<longleftrightarrow> (\<exists>\<^sub>\<infinity>x. P x) \<or> (\<exists>\<^sub>\<infinity>x. Q x)"
68e111812b83 rename lemmas INF_foo to INFM_foo; add new lemmas about MOST and INFM
huffman
parents: 27368
diff changeset
   323
  unfolding Inf_many_def by (simp add: Collect_disj_eq)
68e111812b83 rename lemmas INF_foo to INFM_foo; add new lemmas about MOST and INFM
huffman
parents: 27368
diff changeset
   324
34112
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   325
lemma INFM_imp_distrib:
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   326
  "(INFM x. P x \<longrightarrow> Q x) \<longleftrightarrow> ((MOST x. P x) \<longrightarrow> (INFM x. Q x))"
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   327
  by (simp only: imp_conv_disj INFM_disj_distrib not_MOST)
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   328
27407
68e111812b83 rename lemmas INF_foo to INFM_foo; add new lemmas about MOST and INFM
huffman
parents: 27368
diff changeset
   329
lemma MOST_conj_distrib:
68e111812b83 rename lemmas INF_foo to INFM_foo; add new lemmas about MOST and INFM
huffman
parents: 27368
diff changeset
   330
  "(\<forall>\<^sub>\<infinity>x. P x \<and> Q x) \<longleftrightarrow> (\<forall>\<^sub>\<infinity>x. P x) \<and> (\<forall>\<^sub>\<infinity>x. Q x)"
68e111812b83 rename lemmas INF_foo to INFM_foo; add new lemmas about MOST and INFM
huffman
parents: 27368
diff changeset
   331
  unfolding Alm_all_def by (simp add: INFM_disj_distrib del: disj_not1)
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   332
34112
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   333
lemma MOST_conjI:
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   334
  "MOST x. P x \<Longrightarrow> MOST x. Q x \<Longrightarrow> MOST x. P x \<and> Q x"
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   335
  by (simp add: MOST_conj_distrib)
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   336
34113
dbc0fb6e7eae add lemma INFM_conjI
huffman
parents: 34112
diff changeset
   337
lemma INFM_conjI:
dbc0fb6e7eae add lemma INFM_conjI
huffman
parents: 34112
diff changeset
   338
  "INFM x. P x \<Longrightarrow> MOST x. Q x \<Longrightarrow> INFM x. P x \<and> Q x"
dbc0fb6e7eae add lemma INFM_conjI
huffman
parents: 34112
diff changeset
   339
  unfolding MOST_iff_cofinite INFM_iff_infinite
dbc0fb6e7eae add lemma INFM_conjI
huffman
parents: 34112
diff changeset
   340
  apply (drule (1) Diff_infinite_finite)
dbc0fb6e7eae add lemma INFM_conjI
huffman
parents: 34112
diff changeset
   341
  apply (simp add: Collect_conj_eq Collect_neg_eq)
dbc0fb6e7eae add lemma INFM_conjI
huffman
parents: 34112
diff changeset
   342
  done
dbc0fb6e7eae add lemma INFM_conjI
huffman
parents: 34112
diff changeset
   343
27407
68e111812b83 rename lemmas INF_foo to INFM_foo; add new lemmas about MOST and INFM
huffman
parents: 27368
diff changeset
   344
lemma MOST_rev_mp:
68e111812b83 rename lemmas INF_foo to INFM_foo; add new lemmas about MOST and INFM
huffman
parents: 27368
diff changeset
   345
  assumes "\<forall>\<^sub>\<infinity>x. P x" and "\<forall>\<^sub>\<infinity>x. P x \<longrightarrow> Q x"
68e111812b83 rename lemmas INF_foo to INFM_foo; add new lemmas about MOST and INFM
huffman
parents: 27368
diff changeset
   346
  shows "\<forall>\<^sub>\<infinity>x. Q x"
68e111812b83 rename lemmas INF_foo to INFM_foo; add new lemmas about MOST and INFM
huffman
parents: 27368
diff changeset
   347
proof -
68e111812b83 rename lemmas INF_foo to INFM_foo; add new lemmas about MOST and INFM
huffman
parents: 27368
diff changeset
   348
  have "\<forall>\<^sub>\<infinity>x. P x \<and> (P x \<longrightarrow> Q x)"
34112
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   349
    using assms by (rule MOST_conjI)
27407
68e111812b83 rename lemmas INF_foo to INFM_foo; add new lemmas about MOST and INFM
huffman
parents: 27368
diff changeset
   350
  thus ?thesis by (rule MOST_mono) simp
68e111812b83 rename lemmas INF_foo to INFM_foo; add new lemmas about MOST and INFM
huffman
parents: 27368
diff changeset
   351
qed
68e111812b83 rename lemmas INF_foo to INFM_foo; add new lemmas about MOST and INFM
huffman
parents: 27368
diff changeset
   352
34112
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   353
lemma MOST_imp_iff:
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   354
  assumes "MOST x. P x"
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   355
  shows "(MOST x. P x \<longrightarrow> Q x) \<longleftrightarrow> (MOST x. Q x)"
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   356
proof
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   357
  assume "MOST x. P x \<longrightarrow> Q x"
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   358
  with assms show "MOST x. Q x" by (rule MOST_rev_mp)
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   359
next
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   360
  assume "MOST x. Q x"
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   361
  then show "MOST x. P x \<longrightarrow> Q x" by (rule MOST_mono) simp
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   362
qed
27407
68e111812b83 rename lemmas INF_foo to INFM_foo; add new lemmas about MOST and INFM
huffman
parents: 27368
diff changeset
   363
34112
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   364
lemma INFM_MOST_simps [simp]:
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   365
  "\<And>P Q. (INFM x. P x \<and> Q) \<longleftrightarrow> (INFM x. P x) \<and> Q"
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   366
  "\<And>P Q. (INFM x. P \<and> Q x) \<longleftrightarrow> P \<and> (INFM x. Q x)"
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   367
  "\<And>P Q. (MOST x. P x \<or> Q) \<longleftrightarrow> (MOST x. P x) \<or> Q"
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   368
  "\<And>P Q. (MOST x. P \<or> Q x) \<longleftrightarrow> P \<or> (MOST x. Q x)"
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   369
  "\<And>P Q. (MOST x. P x \<longrightarrow> Q) \<longleftrightarrow> ((INFM x. P x) \<longrightarrow> Q)"
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   370
  "\<And>P Q. (MOST x. P \<longrightarrow> Q x) \<longleftrightarrow> (P \<longrightarrow> (MOST x. Q x))"
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   371
  unfolding Alm_all_def Inf_many_def
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   372
  by (simp_all add: Collect_conj_eq)
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   373
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   374
text {* Properties of quantifiers with injective functions. *}
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   375
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   376
lemma INFM_inj: "INFM x. P (f x) \<Longrightarrow> inj f \<Longrightarrow> INFM x. P x"
34112
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   377
  unfolding INFM_iff_infinite
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   378
  apply clarify
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   379
  apply (drule (1) finite_vimageI)
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   380
  apply simp
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   381
  done
27407
68e111812b83 rename lemmas INF_foo to INFM_foo; add new lemmas about MOST and INFM
huffman
parents: 27368
diff changeset
   382
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   383
lemma MOST_inj: "MOST x. P x \<Longrightarrow> inj f \<Longrightarrow> MOST x. P (f x)"
34112
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   384
  unfolding MOST_iff_cofinite
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   385
  apply (drule (1) finite_vimageI)
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   386
  apply simp
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   387
  done
34112
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   388
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   389
text {* Properties of quantifiers with singletons. *}
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   390
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   391
lemma not_INFM_eq [simp]:
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   392
  "\<not> (INFM x. x = a)"
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   393
  "\<not> (INFM x. a = x)"
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   394
  unfolding INFM_iff_infinite by simp_all
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   395
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   396
lemma MOST_neq [simp]:
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   397
  "MOST x. x \<noteq> a"
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   398
  "MOST x. a \<noteq> x"
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   399
  unfolding MOST_iff_cofinite by simp_all
27407
68e111812b83 rename lemmas INF_foo to INFM_foo; add new lemmas about MOST and INFM
huffman
parents: 27368
diff changeset
   400
34112
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   401
lemma INFM_neq [simp]:
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   402
  "(INFM x::'a. x \<noteq> a) \<longleftrightarrow> infinite (UNIV::'a set)"
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   403
  "(INFM x::'a. a \<noteq> x) \<longleftrightarrow> infinite (UNIV::'a set)"
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   404
  unfolding INFM_iff_infinite by simp_all
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   405
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   406
lemma MOST_eq [simp]:
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   407
  "(MOST x::'a. x = a) \<longleftrightarrow> finite (UNIV::'a set)"
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   408
  "(MOST x::'a. a = x) \<longleftrightarrow> finite (UNIV::'a set)"
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   409
  unfolding MOST_iff_cofinite by simp_all
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   410
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   411
lemma MOST_eq_imp:
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   412
  "MOST x. x = a \<longrightarrow> P x"
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   413
  "MOST x. a = x \<longrightarrow> P x"
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   414
  unfolding MOST_iff_cofinite by simp_all
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   415
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   416
text {* Properties of quantifiers over the naturals. *}
27407
68e111812b83 rename lemmas INF_foo to INFM_foo; add new lemmas about MOST and INFM
huffman
parents: 27368
diff changeset
   417
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   418
lemma INFM_nat: "(\<exists>\<^sub>\<infinity>n. P (n::nat)) \<longleftrightarrow> (\<forall>m. \<exists>n. m < n \<and> P n)"
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   419
  by (simp add: Inf_many_def infinite_nat_iff_unbounded)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   420
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   421
lemma INFM_nat_le: "(\<exists>\<^sub>\<infinity>n. P (n::nat)) \<longleftrightarrow> (\<forall>m. \<exists>n. m \<le> n \<and> P n)"
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   422
  by (simp add: Inf_many_def infinite_nat_iff_unbounded_le)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   423
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   424
lemma MOST_nat: "(\<forall>\<^sub>\<infinity>n. P (n::nat)) \<longleftrightarrow> (\<exists>m. \<forall>n. m < n \<longrightarrow> P n)"
27407
68e111812b83 rename lemmas INF_foo to INFM_foo; add new lemmas about MOST and INFM
huffman
parents: 27368
diff changeset
   425
  by (simp add: Alm_all_def INFM_nat)
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   426
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   427
lemma MOST_nat_le: "(\<forall>\<^sub>\<infinity>n. P (n::nat)) \<longleftrightarrow> (\<exists>m. \<forall>n. m \<le> n \<longrightarrow> P n)"
27407
68e111812b83 rename lemmas INF_foo to INFM_foo; add new lemmas about MOST and INFM
huffman
parents: 27368
diff changeset
   428
  by (simp add: Alm_all_def INFM_nat_le)
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   429
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   430
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   431
subsection "Enumeration of an Infinite Set"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   432
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   433
text {*
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   434
  The set's element type must be wellordered (e.g. the natural numbers).
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   435
*}
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   436
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   437
primrec (in wellorder) enumerate :: "'a set \<Rightarrow> nat \<Rightarrow> 'a"
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   438
where
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   439
  enumerate_0: "enumerate S 0 = (LEAST n. n \<in> S)"
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   440
| enumerate_Suc: "enumerate S (Suc n) = enumerate (S - {LEAST n. n \<in> S}) n"
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   441
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   442
lemma enumerate_Suc': "enumerate S (Suc n) = enumerate (S - {enumerate S 0}) n"
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   443
  by simp
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   444
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   445
lemma enumerate_in_set: "infinite S \<Longrightarrow> enumerate S n : S"
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   446
  apply (induct n arbitrary: S)
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   447
   apply (fastforce intro: LeastI dest!: infinite_imp_nonempty)
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   448
  apply simp
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   449
  apply (metis DiffE infinite_remove)
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   450
  done
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   451
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   452
declare enumerate_0 [simp del] enumerate_Suc [simp del]
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   453
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   454
lemma enumerate_step: "infinite S \<Longrightarrow> enumerate S n < enumerate S (Suc n)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   455
  apply (induct n arbitrary: S)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   456
   apply (rule order_le_neq_trans)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   457
    apply (simp add: enumerate_0 Least_le enumerate_in_set)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   458
   apply (simp only: enumerate_Suc')
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   459
   apply (subgoal_tac "enumerate (S - {enumerate S 0}) 0 : S - {enumerate S 0}")
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   460
    apply (blast intro: sym)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   461
   apply (simp add: enumerate_in_set del: Diff_iff)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   462
  apply (simp add: enumerate_Suc')
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   463
  done
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   464
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   465
lemma enumerate_mono: "m<n \<Longrightarrow> infinite S \<Longrightarrow> enumerate S m < enumerate S n"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   466
  apply (erule less_Suc_induct)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   467
  apply (auto intro: enumerate_step)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   468
  done
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   469
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   470
50134
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   471
lemma le_enumerate:
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   472
  assumes S: "infinite S"
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   473
  shows "n \<le> enumerate S n"
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   474
  using S 
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   475
proof (induct n)
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   476
  case 0
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   477
  then show ?case by simp
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   478
next
50134
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   479
  case (Suc n)
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   480
  then have "n \<le> enumerate S n" by simp
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   481
  also note enumerate_mono[of n "Suc n", OF _ `infinite S`]
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   482
  finally show ?case by simp
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   483
qed
50134
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   484
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   485
lemma enumerate_Suc'':
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   486
  fixes S :: "'a::wellorder set"
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   487
  assumes "infinite S"
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   488
  shows "enumerate S (Suc n) = (LEAST s. s \<in> S \<and> enumerate S n < s)"
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   489
  using assms
50134
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   490
proof (induct n arbitrary: S)
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   491
  case 0
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   492
  then have "\<forall>s \<in> S. enumerate S 0 \<le> s"
50134
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   493
    by (auto simp: enumerate.simps intro: Least_le)
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   494
  then show ?case
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   495
    unfolding enumerate_Suc' enumerate_0[of "S - {enumerate S 0}"]
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   496
    by (intro arg_cong[where f = Least] ext) auto
50134
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   497
next
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   498
  case (Suc n S)
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   499
  show ?case
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   500
    using enumerate_mono[OF zero_less_Suc `infinite S`, of n] `infinite S`
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   501
    apply (subst (1 2) enumerate_Suc')
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   502
    apply (subst Suc)
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   503
    using `infinite S`
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   504
    apply simp
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   505
    apply (intro arg_cong[where f = Least] ext)
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   506
    apply (auto simp: enumerate_Suc'[symmetric])
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   507
    done
50134
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   508
qed
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   509
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   510
lemma enumerate_Ex:
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   511
  assumes S: "infinite (S::nat set)"
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   512
  shows "s \<in> S \<Longrightarrow> \<exists>n. enumerate S n = s"
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   513
proof (induct s rule: less_induct)
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   514
  case (less s)
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   515
  show ?case
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   516
  proof cases
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   517
    let ?y = "Max {s'\<in>S. s' < s}"
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   518
    assume "\<exists>y\<in>S. y < s"
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   519
    then have y: "\<And>x. ?y < x \<longleftrightarrow> (\<forall>s'\<in>S. s' < s \<longrightarrow> s' < x)"
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   520
      by (subst Max_less_iff) auto
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   521
    then have y_in: "?y \<in> {s'\<in>S. s' < s}"
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   522
      by (intro Max_in) auto
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   523
    with less.hyps[of ?y] obtain n where "enumerate S n = ?y"
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   524
      by auto
50134
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   525
    with S have "enumerate S (Suc n) = s"
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   526
      by (auto simp: y less enumerate_Suc'' intro!: Least_equality)
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   527
    then show ?case by auto
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   528
  next
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   529
    assume *: "\<not> (\<exists>y\<in>S. y < s)"
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   530
    then have "\<forall>t\<in>S. s \<le> t" by auto
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   531
    with `s \<in> S` show ?thesis
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   532
      by (auto intro!: exI[of _ 0] Least_equality simp: enumerate_0)
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   533
  qed
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   534
qed
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   535
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   536
lemma bij_enumerate:
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   537
  fixes S :: "nat set"
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   538
  assumes S: "infinite S"
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   539
  shows "bij_betw (enumerate S) UNIV S"
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   540
proof -
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   541
  have "\<And>n m. n \<noteq> m \<Longrightarrow> enumerate S n \<noteq> enumerate S m"
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   542
    using enumerate_mono[OF _ `infinite S`] by (auto simp: neq_iff)
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   543
  then have "inj (enumerate S)"
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   544
    by (auto simp: inj_on_def)
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   545
  moreover have "\<forall>s \<in> S. \<exists>i. enumerate S i = s"
50134
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   546
    using enumerate_Ex[OF S] by auto
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   547
  moreover note `infinite S`
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   548
  ultimately show ?thesis
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   549
    unfolding bij_betw_def by (auto intro: enumerate_in_set)
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   550
qed
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   551
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   552
subsection "Miscellaneous"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   553
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   554
text {*
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   555
  A few trivial lemmas about sets that contain at most one element.
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   556
  These simplify the reasoning about deterministic automata.
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   557
*}
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   558
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   559
definition atmost_one :: "'a set \<Rightarrow> bool"
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   560
  where "atmost_one S \<longleftrightarrow> (\<forall>x y. x\<in>S \<and> y\<in>S \<longrightarrow> x = y)"
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   561
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   562
lemma atmost_one_empty: "S = {} \<Longrightarrow> atmost_one S"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   563
  by (simp add: atmost_one_def)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   564
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   565
lemma atmost_one_singleton: "S = {x} \<Longrightarrow> atmost_one S"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   566
  by (simp add: atmost_one_def)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   567
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   568
lemma atmost_one_unique [elim]: "atmost_one S \<Longrightarrow> x \<in> S \<Longrightarrow> y \<in> S \<Longrightarrow> y = x"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   569
  by (simp add: atmost_one_def)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   570
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   571
end
46783
3e89a5cab8d7 tuned whitespace
haftmann
parents: 44890
diff changeset
   572