src/HOL/Library/Infinite_Set.thy
author haftmann
Mon, 26 Mar 2007 14:53:02 +0200
changeset 22519 eb70ed79dac7
parent 22432 1d00d26fee0d
child 23394 474ff28210c0
permissions -rw-r--r--
importing Eval theory
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
     1
(*  Title:      HOL/Infnite_Set.thy
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
     3
    Author:     Stephan Merz
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
     4
*)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
     5
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
     6
header {* Infinite Sets and Related Concepts *}
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
     7
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
     8
theory Infinite_Set
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents: 21210
diff changeset
     9
imports Main
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    10
begin
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    11
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    12
subsection "Infinite Sets"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    13
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    14
text {*
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    15
  Some elementary facts about infinite sets, mostly by Stefan Merz.
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    16
  Beware! Because "infinite" merely abbreviates a negation, these
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    17
  lemmas may not work well with @{text "blast"}.
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    18
*}
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    19
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    20
abbreviation
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21256
diff changeset
    21
  infinite :: "'a set \<Rightarrow> bool" where
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    22
  "infinite S == \<not> finite S"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    23
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    24
text {*
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    25
  Infinite sets are non-empty, and if we remove some elements from an
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    26
  infinite set, the result is still infinite.
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    27
*}
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    28
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    29
lemma infinite_imp_nonempty: "infinite S ==> S \<noteq> {}"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    30
  by auto
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    31
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    32
lemma infinite_remove:
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    33
  "infinite S \<Longrightarrow> infinite (S - {a})"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    34
  by simp
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    35
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    36
lemma Diff_infinite_finite:
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    37
  assumes T: "finite T" and S: "infinite S"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    38
  shows "infinite (S - T)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    39
  using T
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    40
proof induct
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    41
  from S
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    42
  show "infinite (S - {})" by auto
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    43
next
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    44
  fix T x
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    45
  assume ih: "infinite (S - T)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    46
  have "S - (insert x T) = (S - T) - {x}"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    47
    by (rule Diff_insert)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    48
  with ih
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    49
  show "infinite (S - (insert x T))"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    50
    by (simp add: infinite_remove)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    51
qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    52
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    53
lemma Un_infinite: "infinite S \<Longrightarrow> infinite (S \<union> T)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    54
  by simp
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    55
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")
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    73
using S
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:
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    93
  "finite (S::nat set) = (\<exists>k. S \<subseteq> {..<k})"  (is "?lhs = ?rhs")
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:
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   105
  "finite (S::nat set) = (\<exists>k. S \<subseteq> {..k})"  (is "?lhs = ?rhs")
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:
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   120
  "infinite (S::nat set) = (\<forall>m. \<exists>n. m<n \<and> n\<in>S)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   121
  (is "?lhs = ?rhs")
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"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   127
    then obtain m where m: "\<forall>n. m<n \<longrightarrow> n\<notin>S" by blast
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)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   140
    then have "\<forall>n. m<n \<longrightarrow> n\<notin>S" by auto
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:
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   146
  "infinite (S::nat set) = (\<forall>m. \<exists>n. m\<le>n \<and> n\<in>S)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   147
  (is "?lhs = ?rhs")
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
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   153
    from `?lhs` obtain n where "m<n \<and> n\<in>S"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   154
      by (auto simp add: infinite_nat_iff_unbounded)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   155
    then have "m\<le>n \<and> n\<in>S" by simp
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
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   163
    from `?rhs` obtain n where "Suc m \<le> n \<and> n\<in>S"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   164
      by blast
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   165
    then have "m<n \<and> n\<in>S" by simp
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:
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   177
  assumes k: "\<forall>m. k<m \<longrightarrow> (\<exists>n. m<n \<and> n\<in>S)"
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
  {
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   181
    fix m have "\<exists>n. m<n \<and> n\<in>S"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   182
    proof (cases "k<m")
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
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   187
      from k obtain n where "Suc k < n \<and> n\<in>S" by auto
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   188
      with False have "m<n \<and> n\<in>S" by auto
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
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   196
lemma nat_infinite [simp]: "infinite (UNIV :: nat set)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   197
  by (auto simp add: infinite_nat_iff_unbounded)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   198
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   199
lemma nat_not_finite [elim]: "finite (UNIV::nat set) \<Longrightarrow> R"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   200
  by simp
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   201
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   202
text {*
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   203
  Every infinite set contains a countable subset. More precisely we
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   204
  show that a set @{text S} is infinite if and only if there exists an
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   205
  injective function from the naturals into @{text S}.
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   206
*}
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   207
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   208
lemma range_inj_infinite:
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   209
  "inj (f::nat \<Rightarrow> 'a) \<Longrightarrow> infinite (range f)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   210
proof
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   211
  assume "inj f"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   212
    and  "finite (range f)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   213
  then have "finite (UNIV::nat set)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   214
    by (auto intro: finite_imageD simp del: nat_infinite)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   215
  then show False by simp
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   216
qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   217
22226
699385e6cb45 new theorem int_infinite
paulson
parents: 21404
diff changeset
   218
lemma int_infinite [simp]:
699385e6cb45 new theorem int_infinite
paulson
parents: 21404
diff changeset
   219
  shows "infinite (UNIV::int set)"
699385e6cb45 new theorem int_infinite
paulson
parents: 21404
diff changeset
   220
proof -
699385e6cb45 new theorem int_infinite
paulson
parents: 21404
diff changeset
   221
  from inj_int have "infinite (range int)" by (rule range_inj_infinite)
699385e6cb45 new theorem int_infinite
paulson
parents: 21404
diff changeset
   222
  moreover 
699385e6cb45 new theorem int_infinite
paulson
parents: 21404
diff changeset
   223
  have "range int \<subseteq> (UNIV::int set)" by simp
699385e6cb45 new theorem int_infinite
paulson
parents: 21404
diff changeset
   224
  ultimately show "infinite (UNIV::int set)" by (simp add: infinite_super)
699385e6cb45 new theorem int_infinite
paulson
parents: 21404
diff changeset
   225
qed
699385e6cb45 new theorem int_infinite
paulson
parents: 21404
diff changeset
   226
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   227
text {*
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   228
  The ``only if'' direction is harder because it requires the
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   229
  construction of a sequence of pairwise different elements of an
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   230
  infinite set @{text S}. The idea is to construct a sequence of
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   231
  non-empty and infinite subsets of @{text S} obtained by successively
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   232
  removing elements of @{text S}.
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   233
*}
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   234
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   235
lemma linorder_injI:
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   236
  assumes hyp: "!!x y. x < (y::'a::linorder) ==> f x \<noteq> f y"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   237
  shows "inj f"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   238
proof (rule inj_onI)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   239
  fix x y
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   240
  assume f_eq: "f x = f y"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   241
  show "x = y"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   242
  proof (rule linorder_cases)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   243
    assume "x < y"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   244
    with hyp have "f x \<noteq> f y" by blast
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   245
    with f_eq show ?thesis by simp
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   246
  next
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   247
    assume "x = y"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   248
    then show ?thesis .
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   249
  next
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   250
    assume "y < x"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   251
    with hyp have "f y \<noteq> f x" by blast
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   252
    with f_eq show ?thesis by simp
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   253
  qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   254
qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   255
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   256
lemma infinite_countable_subset:
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   257
  assumes inf: "infinite (S::'a set)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   258
  shows "\<exists>f. inj (f::nat \<Rightarrow> 'a) \<and> range f \<subseteq> S"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   259
proof -
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   260
  def Sseq \<equiv> "nat_rec S (\<lambda>n T. T - {SOME e. e \<in> T})"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   261
  def pick \<equiv> "\<lambda>n. (SOME e. e \<in> Sseq n)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   262
  have Sseq_inf: "\<And>n. infinite (Sseq n)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   263
  proof -
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   264
    fix n
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   265
    show "infinite (Sseq n)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   266
    proof (induct n)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   267
      from inf show "infinite (Sseq 0)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   268
        by (simp add: Sseq_def)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   269
    next
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   270
      fix n
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   271
      assume "infinite (Sseq n)" then show "infinite (Sseq (Suc n))"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   272
        by (simp add: Sseq_def infinite_remove)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   273
    qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   274
  qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   275
  have Sseq_S: "\<And>n. Sseq n \<subseteq> S"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   276
  proof -
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   277
    fix n
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   278
    show "Sseq n \<subseteq> S"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   279
      by (induct n) (auto simp add: Sseq_def)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   280
  qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   281
  have Sseq_pick: "\<And>n. pick n \<in> Sseq n"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   282
  proof -
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   283
    fix n
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   284
    show "pick n \<in> Sseq n"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   285
    proof (unfold pick_def, rule someI_ex)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   286
      from Sseq_inf have "infinite (Sseq n)" .
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   287
      then have "Sseq n \<noteq> {}" by auto
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   288
      then show "\<exists>x. x \<in> Sseq n" by auto
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   289
    qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   290
  qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   291
  with Sseq_S have rng: "range pick \<subseteq> S"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   292
    by auto
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   293
  have pick_Sseq_gt: "\<And>n m. pick n \<notin> Sseq (n + Suc m)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   294
  proof -
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   295
    fix n m
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   296
    show "pick n \<notin> Sseq (n + Suc m)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   297
      by (induct m) (auto simp add: Sseq_def pick_def)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   298
  qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   299
  have pick_pick: "\<And>n m. pick n \<noteq> pick (n + Suc m)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   300
  proof -
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   301
    fix n m
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   302
    from Sseq_pick have "pick (n + Suc m) \<in> Sseq (n + Suc m)" .
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   303
    moreover from pick_Sseq_gt
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   304
    have "pick n \<notin> Sseq (n + Suc m)" .
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   305
    ultimately show "pick n \<noteq> pick (n + Suc m)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   306
      by auto
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   307
  qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   308
  have inj: "inj pick"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   309
  proof (rule linorder_injI)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   310
    fix i j :: nat
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   311
    assume "i < j"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   312
    show "pick i \<noteq> pick j"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   313
    proof
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   314
      assume eq: "pick i = pick j"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   315
      from `i < j` obtain k where "j = i + Suc k"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   316
        by (auto simp add: less_iff_Suc_add)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   317
      with pick_pick have "pick i \<noteq> pick j" by simp
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   318
      with eq show False by simp
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   319
    qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   320
  qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   321
  from rng inj show ?thesis by auto
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   322
qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   323
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   324
lemma infinite_iff_countable_subset:
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   325
    "infinite S = (\<exists>f. inj (f::nat \<Rightarrow> 'a) \<and> range f \<subseteq> S)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   326
  by (auto simp add: infinite_countable_subset range_inj_infinite infinite_super)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   327
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   328
text {*
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   329
  For any function with infinite domain and finite range there is some
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   330
  element that is the image of infinitely many domain elements.  In
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   331
  particular, any infinite sequence of elements from a finite set
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   332
  contains some element that occurs infinitely often.
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   333
*}
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   334
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   335
lemma inf_img_fin_dom:
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   336
  assumes img: "finite (f`A)" and dom: "infinite A"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   337
  shows "\<exists>y \<in> f`A. infinite (f -` {y})"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   338
proof (rule ccontr)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   339
  assume "\<not> ?thesis"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   340
  with img have "finite (UN y:f`A. f -` {y})" by (blast intro: finite_UN_I)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   341
  moreover have "A \<subseteq> (UN y:f`A. f -` {y})" by auto
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   342
  moreover note dom
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   343
  ultimately show False by (simp add: infinite_super)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   344
qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   345
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   346
lemma inf_img_fin_domE:
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   347
  assumes "finite (f`A)" and "infinite A"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   348
  obtains y where "y \<in> f`A" and "infinite (f -` {y})"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   349
  using prems by (blast dest: inf_img_fin_dom)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   350
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   351
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   352
subsection "Infinitely Many and Almost All"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   353
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   354
text {*
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   355
  We often need to reason about the existence of infinitely many
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   356
  (resp., all but finitely many) objects satisfying some predicate, so
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   357
  we introduce corresponding binders and their proof rules.
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   358
*}
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   359
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   360
definition
22432
1d00d26fee0d Renamed INF to INFM to avoid clash with INF operator defined in FixedPoint theory.
berghofe
parents: 22226
diff changeset
   361
  Inf_many :: "('a \<Rightarrow> bool) \<Rightarrow> bool"  (binder "INFM " 10) where
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   362
  "Inf_many P = infinite {x. P x}"
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21256
diff changeset
   363
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21256
diff changeset
   364
definition
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21256
diff changeset
   365
  Alm_all :: "('a \<Rightarrow> bool) \<Rightarrow> bool"  (binder "MOST " 10) where
22432
1d00d26fee0d Renamed INF to INFM to avoid clash with INF operator defined in FixedPoint theory.
berghofe
parents: 22226
diff changeset
   366
  "Alm_all P = (\<not> (INFM x. \<not> P x))"
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   367
21210
c17fd2df4e9e renamed 'const_syntax' to 'notation';
wenzelm
parents: 20809
diff changeset
   368
notation (xsymbols)
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21256
diff changeset
   369
  Inf_many  (binder "\<exists>\<^sub>\<infinity>" 10) and
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   370
  Alm_all  (binder "\<forall>\<^sub>\<infinity>" 10)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   371
21210
c17fd2df4e9e renamed 'const_syntax' to 'notation';
wenzelm
parents: 20809
diff changeset
   372
notation (HTML output)
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21256
diff changeset
   373
  Inf_many  (binder "\<exists>\<^sub>\<infinity>" 10) and
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   374
  Alm_all  (binder "\<forall>\<^sub>\<infinity>" 10)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   375
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   376
lemma INF_EX:
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   377
  "(\<exists>\<^sub>\<infinity>x. P x) \<Longrightarrow> (\<exists>x. P x)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   378
  unfolding Inf_many_def
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   379
proof (rule ccontr)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   380
  assume inf: "infinite {x. P x}"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   381
  assume "\<not> ?thesis" then have "{x. P x} = {}" by simp
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   382
  then have "finite {x. P x}" by simp
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   383
  with inf show False by simp
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   384
qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   385
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   386
lemma MOST_iff_finiteNeg: "(\<forall>\<^sub>\<infinity>x. P x) = finite {x. \<not> P x}"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   387
  by (simp add: Alm_all_def Inf_many_def)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   388
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   389
lemma ALL_MOST: "\<forall>x. P x \<Longrightarrow> \<forall>\<^sub>\<infinity>x. P x"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   390
  by (simp add: MOST_iff_finiteNeg)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   391
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   392
lemma INF_mono:
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   393
  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
   394
  shows "\<exists>\<^sub>\<infinity>x. Q x"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   395
proof -
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   396
  from inf have "infinite {x. P x}" unfolding Inf_many_def .
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   397
  moreover from q have "{x. P x} \<subseteq> {x. Q x}" by auto
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   398
  ultimately show ?thesis
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   399
    by (simp add: Inf_many_def infinite_super)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   400
qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   401
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   402
lemma MOST_mono: "\<forall>\<^sub>\<infinity>x. P x \<Longrightarrow> (\<And>x. P x \<Longrightarrow> Q x) \<Longrightarrow> \<forall>\<^sub>\<infinity>x. Q x"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   403
  unfolding Alm_all_def by (blast intro: INF_mono)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   404
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   405
lemma INF_nat: "(\<exists>\<^sub>\<infinity>n. P (n::nat)) = (\<forall>m. \<exists>n. m<n \<and> P n)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   406
  by (simp add: Inf_many_def infinite_nat_iff_unbounded)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   407
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   408
lemma INF_nat_le: "(\<exists>\<^sub>\<infinity>n. P (n::nat)) = (\<forall>m. \<exists>n. m\<le>n \<and> P n)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   409
  by (simp add: Inf_many_def infinite_nat_iff_unbounded_le)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   410
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   411
lemma MOST_nat: "(\<forall>\<^sub>\<infinity>n. P (n::nat)) = (\<exists>m. \<forall>n. m<n \<longrightarrow> P n)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   412
  by (simp add: Alm_all_def INF_nat)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   413
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   414
lemma MOST_nat_le: "(\<forall>\<^sub>\<infinity>n. P (n::nat)) = (\<exists>m. \<forall>n. m\<le>n \<longrightarrow> P n)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   415
  by (simp add: Alm_all_def INF_nat_le)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   416
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   417
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   418
subsection "Enumeration of an Infinite Set"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   419
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   420
text {*
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   421
  The set's element type must be wellordered (e.g. the natural numbers).
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   422
*}
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   423
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   424
consts
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   425
  enumerate   :: "'a::wellorder set => (nat => 'a::wellorder)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   426
primrec
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   427
  enumerate_0:   "enumerate S 0       = (LEAST n. n \<in> S)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   428
  enumerate_Suc: "enumerate S (Suc n) = enumerate (S - {LEAST n. n \<in> S}) n"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   429
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   430
lemma enumerate_Suc':
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   431
    "enumerate S (Suc n) = enumerate (S - {enumerate S 0}) n"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   432
  by simp
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   433
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   434
lemma enumerate_in_set: "infinite S \<Longrightarrow> enumerate S n : S"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   435
  apply (induct n arbitrary: S)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   436
   apply (fastsimp intro: LeastI dest!: infinite_imp_nonempty)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   437
  apply (fastsimp iff: finite_Diff_singleton)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   438
  done
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   439
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   440
declare enumerate_0 [simp del] enumerate_Suc [simp del]
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   441
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   442
lemma enumerate_step: "infinite S \<Longrightarrow> enumerate S n < enumerate S (Suc n)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   443
  apply (induct n arbitrary: S)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   444
   apply (rule order_le_neq_trans)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   445
    apply (simp add: enumerate_0 Least_le enumerate_in_set)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   446
   apply (simp only: enumerate_Suc')
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   447
   apply (subgoal_tac "enumerate (S - {enumerate S 0}) 0 : S - {enumerate S 0}")
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   448
    apply (blast intro: sym)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   449
   apply (simp add: enumerate_in_set del: Diff_iff)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   450
  apply (simp add: enumerate_Suc')
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   451
  done
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   452
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   453
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
   454
  apply (erule less_Suc_induct)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   455
  apply (auto intro: enumerate_step)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   456
  done
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   457
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   458
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   459
subsection "Miscellaneous"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   460
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   461
text {*
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   462
  A few trivial lemmas about sets that contain at most one element.
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   463
  These simplify the reasoning about deterministic automata.
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   464
*}
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   465
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   466
definition
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21256
diff changeset
   467
  atmost_one :: "'a set \<Rightarrow> bool" where
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   468
  "atmost_one S = (\<forall>x y. x\<in>S \<and> y\<in>S \<longrightarrow> x=y)"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   469
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   470
lemma atmost_one_empty: "S = {} \<Longrightarrow> atmost_one S"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   471
  by (simp add: atmost_one_def)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   472
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   473
lemma atmost_one_singleton: "S = {x} \<Longrightarrow> atmost_one S"
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   474
  by (simp add: atmost_one_def)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   475
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   476
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
   477
  by (simp add: atmost_one_def)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   478
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   479
end