| author | paulson <lp15@cam.ac.uk> | 
| Sun, 15 Jan 2023 15:58:05 +0000 | |
| changeset 76953 | f70d431b5016 | 
| parent 74438 | 5827b91ef30e | 
| child 77138 | c8597292cd41 | 
| permissions | -rw-r--r-- | 
| 50134 | 1 | (* Title: HOL/Library/Countable_Set.thy | 
| 2 | Author: Johannes Hölzl | |
| 3 | Author: Andrei Popescu | |
| 4 | *) | |
| 5 | ||
| 60500 | 6 | section \<open>Countable sets\<close> | 
| 50134 | 7 | |
| 8 | theory Countable_Set | |
| 51542 | 9 | imports Countable Infinite_Set | 
| 50134 | 10 | begin | 
| 11 | ||
| 60500 | 12 | subsection \<open>Predicate for countable sets\<close> | 
| 50134 | 13 | |
| 14 | definition countable :: "'a set \<Rightarrow> bool" where | |
| 15 | "countable S \<longleftrightarrow> (\<exists>f::'a \<Rightarrow> nat. inj_on f S)" | |
| 16 | ||
| 17 | lemma countableE: | |
| 18 | assumes S: "countable S" obtains f :: "'a \<Rightarrow> nat" where "inj_on f S" | |
| 19 | using S by (auto simp: countable_def) | |
| 20 | ||
| 21 | lemma countableI: "inj_on (f::'a \<Rightarrow> nat) S \<Longrightarrow> countable S" | |
| 22 | by (auto simp: countable_def) | |
| 23 | ||
| 24 | lemma countableI': "inj_on (f::'a \<Rightarrow> 'b::countable) S \<Longrightarrow> countable S" | |
| 25 | using comp_inj_on[of f S to_nat] by (auto intro: countableI) | |
| 26 | ||
| 27 | lemma countableE_bij: | |
| 28 | assumes S: "countable S" obtains f :: "nat \<Rightarrow> 'a" and C :: "nat set" where "bij_betw f C S" | |
| 29 | using S by (blast elim: countableE dest: inj_on_imp_bij_betw bij_betw_inv) | |
| 30 | ||
| 31 | lemma countableI_bij: "bij_betw f (C::nat set) S \<Longrightarrow> countable S" | |
| 32 | by (blast intro: countableI bij_betw_inv_into bij_betw_imp_inj_on) | |
| 33 | ||
| 34 | lemma countable_finite: "finite S \<Longrightarrow> countable S" | |
| 35 | by (blast dest: finite_imp_inj_to_nat_seg countableI) | |
| 36 | ||
| 37 | lemma countableI_bij1: "bij_betw f A B \<Longrightarrow> countable A \<Longrightarrow> countable B" | |
| 38 | by (blast elim: countableE_bij intro: bij_betw_trans countableI_bij) | |
| 39 | ||
| 40 | lemma countableI_bij2: "bij_betw f B A \<Longrightarrow> countable A \<Longrightarrow> countable B" | |
| 41 | by (blast elim: countableE_bij intro: bij_betw_trans bij_betw_inv_into countableI_bij) | |
| 42 | ||
| 43 | lemma countable_iff_bij[simp]: "bij_betw f A B \<Longrightarrow> countable A \<longleftrightarrow> countable B" | |
| 44 | by (blast intro: countableI_bij1 countableI_bij2) | |
| 45 | ||
| 46 | lemma countable_subset: "A \<subseteq> B \<Longrightarrow> countable B \<Longrightarrow> countable A" | |
| 47 | by (auto simp: countable_def intro: subset_inj_on) | |
| 48 | ||
| 49 | lemma countableI_type[intro, simp]: "countable (A:: 'a :: countable set)" | |
| 50 | using countableI[of to_nat A] by auto | |
| 51 | ||
| 60500 | 52 | subsection \<open>Enumerate a countable set\<close> | 
| 50134 | 53 | |
| 54 | lemma countableE_infinite: | |
| 55 | assumes "countable S" "infinite S" | |
| 56 | obtains e :: "'a \<Rightarrow> nat" where "bij_betw e S UNIV" | |
| 57 | proof - | |
| 53381 | 58 | obtain f :: "'a \<Rightarrow> nat" where "inj_on f S" | 
| 60500 | 59 | using \<open>countable S\<close> by (rule countableE) | 
| 50134 | 60 | then have "bij_betw f S (f`S)" | 
| 61 | unfolding bij_betw_def by simp | |
| 62 | moreover | |
| 60500 | 63 | from \<open>inj_on f S\<close> \<open>infinite S\<close> have inf_fS: "infinite (f`S)" | 
| 50134 | 64 | by (auto dest: finite_imageD) | 
| 65 | then have "bij_betw (the_inv_into UNIV (enumerate (f`S))) (f`S) UNIV" | |
| 66 | by (intro bij_betw_the_inv_into bij_enumerate) | |
| 67 | ultimately have "bij_betw (the_inv_into UNIV (enumerate (f`S)) \<circ> f) S UNIV" | |
| 68 | by (rule bij_betw_trans) | |
| 69 | then show thesis .. | |
| 70 | qed | |
| 71 | ||
| 68860 
f443ec10447d
Some basic materials on filters and topology
 Manuel Eberl <eberlm@in.tum.de> parents: 
67613diff
changeset | 72 | lemma countable_infiniteE': | 
| 
f443ec10447d
Some basic materials on filters and topology
 Manuel Eberl <eberlm@in.tum.de> parents: 
67613diff
changeset | 73 | assumes "countable A" "infinite A" | 
| 
f443ec10447d
Some basic materials on filters and topology
 Manuel Eberl <eberlm@in.tum.de> parents: 
67613diff
changeset | 74 | obtains g where "bij_betw g (UNIV :: nat set) A" | 
| 
f443ec10447d
Some basic materials on filters and topology
 Manuel Eberl <eberlm@in.tum.de> parents: 
67613diff
changeset | 75 | using bij_betw_inv[OF countableE_infinite[OF assms]] that by blast | 
| 
f443ec10447d
Some basic materials on filters and topology
 Manuel Eberl <eberlm@in.tum.de> parents: 
67613diff
changeset | 76 | |
| 50134 | 77 | lemma countable_enum_cases: | 
| 78 | assumes "countable S" | |
| 79 |   obtains (finite) f :: "'a \<Rightarrow> nat" where "finite S" "bij_betw f S {..<card S}"
 | |
| 80 | | (infinite) f :: "'a \<Rightarrow> nat" where "infinite S" "bij_betw f S UNIV" | |
| 60500 | 81 | using ex_bij_betw_finite_nat[of S] countableE_infinite \<open>countable S\<close> | 
| 50134 | 82 | by (cases "finite S") (auto simp add: atLeast0LessThan) | 
| 83 | ||
| 84 | definition to_nat_on :: "'a set \<Rightarrow> 'a \<Rightarrow> nat" where | |
| 85 |   "to_nat_on S = (SOME f. if finite S then bij_betw f S {..< card S} else bij_betw f S UNIV)"
 | |
| 86 | ||
| 87 | definition from_nat_into :: "'a set \<Rightarrow> nat \<Rightarrow> 'a" where | |
| 50144 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 88 | "from_nat_into S n = (if n \<in> to_nat_on S ` S then inv_into S (to_nat_on S) n else SOME s. s\<in>S)" | 
| 50134 | 89 | |
| 90 | lemma to_nat_on_finite: "finite S \<Longrightarrow> bij_betw (to_nat_on S) S {..< card S}"
 | |
| 91 | using ex_bij_betw_finite_nat unfolding to_nat_on_def | |
| 92 |   by (intro someI2_ex[where Q="\<lambda>f. bij_betw f S {..<card S}"]) (auto simp add: atLeast0LessThan)
 | |
| 93 | ||
| 94 | lemma to_nat_on_infinite: "countable S \<Longrightarrow> infinite S \<Longrightarrow> bij_betw (to_nat_on S) S UNIV" | |
| 95 | using countableE_infinite unfolding to_nat_on_def | |
| 96 | by (intro someI2_ex[where Q="\<lambda>f. bij_betw f S UNIV"]) auto | |
| 97 | ||
| 50148 
b8cff6a8fda2
Countable_Set: tuned lemma names; more generic lemmas
 hoelzl parents: 
50144diff
changeset | 98 | lemma bij_betw_from_nat_into_finite: "finite S \<Longrightarrow> bij_betw (from_nat_into S) {..< card S} S"
 | 
| 50144 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 99 | unfolding from_nat_into_def[abs_def] | 
| 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 100 | using to_nat_on_finite[of S] | 
| 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 101 | apply (subst bij_betw_cong) | 
| 62390 | 102 | apply (split if_split) | 
| 50144 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 103 | apply (simp add: bij_betw_def) | 
| 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 104 | apply (auto cong: bij_betw_cong | 
| 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 105 | intro: bij_betw_inv_into to_nat_on_finite) | 
| 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 106 | done | 
| 50134 | 107 | |
| 50148 
b8cff6a8fda2
Countable_Set: tuned lemma names; more generic lemmas
 hoelzl parents: 
50144diff
changeset | 108 | lemma bij_betw_from_nat_into: "countable S \<Longrightarrow> infinite S \<Longrightarrow> bij_betw (from_nat_into S) UNIV S" | 
| 50144 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 109 | unfolding from_nat_into_def[abs_def] | 
| 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 110 | using to_nat_on_infinite[of S, unfolded bij_betw_def] | 
| 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 111 | by (auto cong: bij_betw_cong intro: bij_betw_inv_into to_nat_on_infinite) | 
| 50134 | 112 | |
| 74438 
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
 paulson <lp15@cam.ac.uk> parents: 
74325diff
changeset | 113 | text \<open> | 
| 
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
 paulson <lp15@cam.ac.uk> parents: 
74325diff
changeset | 114 | The sum/product over the enumeration of a finite set equals simply the sum/product over the set | 
| 
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
 paulson <lp15@cam.ac.uk> parents: 
74325diff
changeset | 115 | \<close> | 
| 
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
 paulson <lp15@cam.ac.uk> parents: 
74325diff
changeset | 116 | context comm_monoid_set | 
| 
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
 paulson <lp15@cam.ac.uk> parents: 
74325diff
changeset | 117 | begin | 
| 
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
 paulson <lp15@cam.ac.uk> parents: 
74325diff
changeset | 118 | |
| 
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
 paulson <lp15@cam.ac.uk> parents: 
74325diff
changeset | 119 | lemma card_from_nat_into: | 
| 
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
 paulson <lp15@cam.ac.uk> parents: 
74325diff
changeset | 120 |   "F (\<lambda>i. h (from_nat_into A i)) {..<card A} = F h A"
 | 
| 
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
 paulson <lp15@cam.ac.uk> parents: 
74325diff
changeset | 121 | proof (cases "finite A") | 
| 
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
 paulson <lp15@cam.ac.uk> parents: 
74325diff
changeset | 122 | case True | 
| 
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
 paulson <lp15@cam.ac.uk> parents: 
74325diff
changeset | 123 |   have "F (\<lambda>i. h (from_nat_into A i)) {..<card A} = F h (from_nat_into A ` {..<card A})"
 | 
| 
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
 paulson <lp15@cam.ac.uk> parents: 
74325diff
changeset | 124 | by (metis True bij_betw_def bij_betw_from_nat_into_finite reindex_cong) | 
| 
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
 paulson <lp15@cam.ac.uk> parents: 
74325diff
changeset | 125 | also have "... = F h A" | 
| 
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
 paulson <lp15@cam.ac.uk> parents: 
74325diff
changeset | 126 | by (metis True bij_betw_def bij_betw_from_nat_into_finite) | 
| 
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
 paulson <lp15@cam.ac.uk> parents: 
74325diff
changeset | 127 | finally show ?thesis . | 
| 
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
 paulson <lp15@cam.ac.uk> parents: 
74325diff
changeset | 128 | qed auto | 
| 
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
 paulson <lp15@cam.ac.uk> parents: 
74325diff
changeset | 129 | |
| 
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
 paulson <lp15@cam.ac.uk> parents: 
74325diff
changeset | 130 | end | 
| 
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
 paulson <lp15@cam.ac.uk> parents: 
74325diff
changeset | 131 | |
| 63127 | 132 | lemma countable_as_injective_image: | 
| 133 | assumes "countable A" "infinite A" | |
| 134 | obtains f :: "nat \<Rightarrow> 'a" where "A = range f" "inj f" | |
| 135 | by (metis bij_betw_def bij_betw_from_nat_into [OF assms]) | |
| 136 | ||
| 50134 | 137 | lemma inj_on_to_nat_on[intro]: "countable A \<Longrightarrow> inj_on (to_nat_on A) A" | 
| 138 | using to_nat_on_infinite[of A] to_nat_on_finite[of A] | |
| 139 | by (cases "finite A") (auto simp: bij_betw_def) | |
| 140 | ||
| 141 | lemma to_nat_on_inj[simp]: | |
| 142 | "countable A \<Longrightarrow> a \<in> A \<Longrightarrow> b \<in> A \<Longrightarrow> to_nat_on A a = to_nat_on A b \<longleftrightarrow> a = b" | |
| 143 | using inj_on_to_nat_on[of A] by (auto dest: inj_onD) | |
| 144 | ||
| 50144 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 145 | lemma from_nat_into_to_nat_on[simp]: "countable A \<Longrightarrow> a \<in> A \<Longrightarrow> from_nat_into A (to_nat_on A a) = a" | 
| 50134 | 146 | by (auto simp: from_nat_into_def intro!: inv_into_f_f) | 
| 147 | ||
| 148 | lemma subset_range_from_nat_into: "countable A \<Longrightarrow> A \<subseteq> range (from_nat_into A)" | |
| 149 | by (auto intro: from_nat_into_to_nat_on[symmetric]) | |
| 150 | ||
| 50144 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 151 | lemma from_nat_into: "A \<noteq> {} \<Longrightarrow> from_nat_into A n \<in> A"
 | 
| 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 152 | unfolding from_nat_into_def by (metis equals0I inv_into_into someI_ex) | 
| 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 153 | |
| 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 154 | lemma range_from_nat_into_subset: "A \<noteq> {} \<Longrightarrow> range (from_nat_into A) \<subseteq> A"
 | 
| 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 155 | using from_nat_into[of A] by auto | 
| 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 156 | |
| 50148 
b8cff6a8fda2
Countable_Set: tuned lemma names; more generic lemmas
 hoelzl parents: 
50144diff
changeset | 157 | lemma range_from_nat_into[simp]: "A \<noteq> {} \<Longrightarrow> countable A \<Longrightarrow> range (from_nat_into A) = A"
 | 
| 50144 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 158 | by (metis equalityI range_from_nat_into_subset subset_range_from_nat_into) | 
| 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 159 | |
| 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 160 | lemma image_to_nat_on: "countable A \<Longrightarrow> infinite A \<Longrightarrow> to_nat_on A ` A = UNIV" | 
| 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 161 | using to_nat_on_infinite[of A] by (simp add: bij_betw_def) | 
| 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 162 | |
| 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 163 | lemma to_nat_on_surj: "countable A \<Longrightarrow> infinite A \<Longrightarrow> \<exists>a\<in>A. to_nat_on A a = n" | 
| 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 164 | by (metis (no_types) image_iff iso_tuple_UNIV_I image_to_nat_on) | 
| 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 165 | |
| 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 166 | lemma to_nat_on_from_nat_into[simp]: "n \<in> to_nat_on A ` A \<Longrightarrow> to_nat_on A (from_nat_into A n) = n" | 
| 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 167 | by (simp add: f_inv_into_f from_nat_into_def) | 
| 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 168 | |
| 50148 
b8cff6a8fda2
Countable_Set: tuned lemma names; more generic lemmas
 hoelzl parents: 
50144diff
changeset | 169 | lemma to_nat_on_from_nat_into_infinite[simp]: | 
| 50144 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 170 | "countable A \<Longrightarrow> infinite A \<Longrightarrow> to_nat_on A (from_nat_into A n) = n" | 
| 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 171 | by (metis image_iff to_nat_on_surj to_nat_on_from_nat_into) | 
| 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 172 | |
| 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 173 | lemma from_nat_into_inj: | 
| 50148 
b8cff6a8fda2
Countable_Set: tuned lemma names; more generic lemmas
 hoelzl parents: 
50144diff
changeset | 174 | "countable A \<Longrightarrow> m \<in> to_nat_on A ` A \<Longrightarrow> n \<in> to_nat_on A ` A \<Longrightarrow> | 
| 
b8cff6a8fda2
Countable_Set: tuned lemma names; more generic lemmas
 hoelzl parents: 
50144diff
changeset | 175 | from_nat_into A m = from_nat_into A n \<longleftrightarrow> m = n" | 
| 
b8cff6a8fda2
Countable_Set: tuned lemma names; more generic lemmas
 hoelzl parents: 
50144diff
changeset | 176 | by (subst to_nat_on_inj[symmetric, of A]) auto | 
| 
b8cff6a8fda2
Countable_Set: tuned lemma names; more generic lemmas
 hoelzl parents: 
50144diff
changeset | 177 | |
| 
b8cff6a8fda2
Countable_Set: tuned lemma names; more generic lemmas
 hoelzl parents: 
50144diff
changeset | 178 | lemma from_nat_into_inj_infinite[simp]: | 
| 
b8cff6a8fda2
Countable_Set: tuned lemma names; more generic lemmas
 hoelzl parents: 
50144diff
changeset | 179 | "countable A \<Longrightarrow> infinite A \<Longrightarrow> from_nat_into A m = from_nat_into A n \<longleftrightarrow> m = n" | 
| 
b8cff6a8fda2
Countable_Set: tuned lemma names; more generic lemmas
 hoelzl parents: 
50144diff
changeset | 180 | using image_to_nat_on[of A] from_nat_into_inj[of A m n] by simp | 
| 
b8cff6a8fda2
Countable_Set: tuned lemma names; more generic lemmas
 hoelzl parents: 
50144diff
changeset | 181 | |
| 
b8cff6a8fda2
Countable_Set: tuned lemma names; more generic lemmas
 hoelzl parents: 
50144diff
changeset | 182 | lemma eq_from_nat_into_iff: | 
| 
b8cff6a8fda2
Countable_Set: tuned lemma names; more generic lemmas
 hoelzl parents: 
50144diff
changeset | 183 | "countable A \<Longrightarrow> x \<in> A \<Longrightarrow> i \<in> to_nat_on A ` A \<Longrightarrow> x = from_nat_into A i \<longleftrightarrow> i = to_nat_on A x" | 
| 
b8cff6a8fda2
Countable_Set: tuned lemma names; more generic lemmas
 hoelzl parents: 
50144diff
changeset | 184 | by auto | 
| 50144 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 185 | |
| 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 186 | lemma from_nat_into_surj: "countable A \<Longrightarrow> a \<in> A \<Longrightarrow> \<exists>n. from_nat_into A n = a" | 
| 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 187 | by (rule exI[of _ "to_nat_on A a"]) simp | 
| 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 188 | |
| 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 189 | lemma from_nat_into_inject[simp]: | 
| 50148 
b8cff6a8fda2
Countable_Set: tuned lemma names; more generic lemmas
 hoelzl parents: 
50144diff
changeset | 190 |   "A \<noteq> {} \<Longrightarrow> countable A \<Longrightarrow> B \<noteq> {} \<Longrightarrow> countable B \<Longrightarrow> from_nat_into A = from_nat_into B \<longleftrightarrow> A = B"
 | 
| 
b8cff6a8fda2
Countable_Set: tuned lemma names; more generic lemmas
 hoelzl parents: 
50144diff
changeset | 191 | by (metis range_from_nat_into) | 
| 50144 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 192 | |
| 50148 
b8cff6a8fda2
Countable_Set: tuned lemma names; more generic lemmas
 hoelzl parents: 
50144diff
changeset | 193 | lemma inj_on_from_nat_into: "inj_on from_nat_into ({A. A \<noteq> {} \<and> countable A})"
 | 
| 
b8cff6a8fda2
Countable_Set: tuned lemma names; more generic lemmas
 hoelzl parents: 
50144diff
changeset | 194 | unfolding inj_on_def by auto | 
| 50144 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 195 | |
| 60500 | 196 | subsection \<open>Closure properties of countability\<close> | 
| 50134 | 197 | |
| 198 | lemma countable_SIGMA[intro, simp]: | |
| 199 | "countable I \<Longrightarrow> (\<And>i. i \<in> I \<Longrightarrow> countable (A i)) \<Longrightarrow> countable (SIGMA i : I. A i)" | |
| 200 | by (intro countableI'[of "\<lambda>(i, a). (to_nat_on I i, to_nat_on (A i) a)"]) (auto simp: inj_on_def) | |
| 201 | ||
| 53381 | 202 | lemma countable_image[intro, simp]: | 
| 203 | assumes "countable A" | |
| 204 | shows "countable (f`A)" | |
| 50134 | 205 | proof - | 
| 53381 | 206 | obtain g :: "'a \<Rightarrow> nat" where "inj_on g A" | 
| 207 | using assms by (rule countableE) | |
| 50134 | 208 | moreover have "inj_on (inv_into A f) (f`A)" "inv_into A f ` f ` A \<subseteq> A" | 
| 209 | by (auto intro: inj_on_inv_into inv_into_into) | |
| 210 | ultimately show ?thesis | |
| 211 | by (blast dest: comp_inj_on subset_inj_on intro: countableI) | |
| 212 | qed | |
| 213 | ||
| 60303 | 214 | lemma countable_image_inj_on: "countable (f ` A) \<Longrightarrow> inj_on f A \<Longrightarrow> countable A" | 
| 215 | by (metis countable_image the_inv_into_onto) | |
| 216 | ||
| 70178 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 217 | lemma countable_image_inj_Int_vimage: | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 218 | "\<lbrakk>inj_on f S; countable A\<rbrakk> \<Longrightarrow> countable (S \<inter> f -` A)" | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 219 | by (meson countable_image_inj_on countable_subset image_subset_iff_subset_vimage inf_le2 inj_on_Int) | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 220 | |
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 221 | lemma countable_image_inj_gen: | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 222 |    "\<lbrakk>inj_on f S; countable A\<rbrakk> \<Longrightarrow> countable {x \<in> S. f x \<in> A}"
 | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 223 | using countable_image_inj_Int_vimage | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 224 | by (auto simp: vimage_def Collect_conj_eq) | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 225 | |
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 226 | lemma countable_image_inj_eq: | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 227 | "inj_on f S \<Longrightarrow> countable(f ` S) \<longleftrightarrow> countable S" | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 228 | using countable_image_inj_on by blast | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 229 | |
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 230 | lemma countable_image_inj: | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 231 |    "\<lbrakk>countable A; inj f\<rbrakk> \<Longrightarrow> countable {x. f x \<in> A}"
 | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 232 | by (metis (mono_tags, lifting) countable_image_inj_eq countable_subset image_Collect_subsetI inj_on_inverseI the_inv_f_f) | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 233 | |
| 50134 | 234 | lemma countable_UN[intro, simp]: | 
| 235 | fixes I :: "'i set" and A :: "'i => 'a set" | |
| 236 | assumes I: "countable I" | |
| 237 | assumes A: "\<And>i. i \<in> I \<Longrightarrow> countable (A i)" | |
| 238 | shows "countable (\<Union>i\<in>I. A i)" | |
| 239 | proof - | |
| 240 | have "(\<Union>i\<in>I. A i) = snd ` (SIGMA i : I. A i)" by (auto simp: image_iff) | |
| 241 | then show ?thesis by (simp add: assms) | |
| 242 | qed | |
| 243 | ||
| 244 | lemma countable_Un[intro]: "countable A \<Longrightarrow> countable B \<Longrightarrow> countable (A \<union> B)" | |
| 245 |   by (rule countable_UN[of "{True, False}" "\<lambda>True \<Rightarrow> A | False \<Rightarrow> B", simplified])
 | |
| 246 | (simp split: bool.split) | |
| 247 | ||
| 248 | lemma countable_Un_iff[simp]: "countable (A \<union> B) \<longleftrightarrow> countable A \<and> countable B" | |
| 249 | by (metis countable_Un countable_subset inf_sup_ord(3,4)) | |
| 250 | ||
| 251 | lemma countable_Plus[intro, simp]: | |
| 252 | "countable A \<Longrightarrow> countable B \<Longrightarrow> countable (A <+> B)" | |
| 253 | by (simp add: Plus_def) | |
| 254 | ||
| 255 | lemma countable_empty[intro, simp]: "countable {}"
 | |
| 256 | by (blast intro: countable_finite) | |
| 257 | ||
| 258 | lemma countable_insert[intro, simp]: "countable A \<Longrightarrow> countable (insert a A)" | |
| 259 |   using countable_Un[of "{a}" A] by (auto simp: countable_finite)
 | |
| 260 | ||
| 261 | lemma countable_Int1[intro, simp]: "countable A \<Longrightarrow> countable (A \<inter> B)" | |
| 262 | by (force intro: countable_subset) | |
| 263 | ||
| 264 | lemma countable_Int2[intro, simp]: "countable B \<Longrightarrow> countable (A \<inter> B)" | |
| 265 | by (blast intro: countable_subset) | |
| 266 | ||
| 267 | lemma countable_INT[intro, simp]: "i \<in> I \<Longrightarrow> countable (A i) \<Longrightarrow> countable (\<Inter>i\<in>I. A i)" | |
| 268 | by (blast intro: countable_subset) | |
| 269 | ||
| 270 | lemma countable_Diff[intro, simp]: "countable A \<Longrightarrow> countable (A - B)" | |
| 271 | by (blast intro: countable_subset) | |
| 272 | ||
| 60303 | 273 | lemma countable_insert_eq [simp]: "countable (insert x A) = countable A" | 
| 274 | by auto (metis Diff_insert_absorb countable_Diff insert_absorb) | |
| 275 | ||
| 50134 | 276 | lemma countable_vimage: "B \<subseteq> range f \<Longrightarrow> countable (f -` B) \<Longrightarrow> countable B" | 
| 63092 | 277 | by (metis Int_absorb2 countable_image image_vimage_eq) | 
| 50134 | 278 | |
| 279 | lemma surj_countable_vimage: "surj f \<Longrightarrow> countable (f -` B) \<Longrightarrow> countable B" | |
| 280 | by (metis countable_vimage top_greatest) | |
| 281 | ||
| 50144 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 282 | lemma countable_Collect[simp]: "countable A \<Longrightarrow> countable {a \<in> A. \<phi> a}"
 | 
| 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 283 | by (metis Collect_conj_eq Int_absorb Int_commute Int_def countable_Int1) | 
| 
885deccc264e
renamed BNF/Countable_Set to Countable_Type and moved its generic stuff to Library/Countable_Set
 hoelzl parents: 
50134diff
changeset | 284 | |
| 54410 
0a578fb7fb73
countability of the image of a reflexive transitive closure
 hoelzl parents: 
53381diff
changeset | 285 | lemma countable_Image: | 
| 
0a578fb7fb73
countability of the image of a reflexive transitive closure
 hoelzl parents: 
53381diff
changeset | 286 |   assumes "\<And>y. y \<in> Y \<Longrightarrow> countable (X `` {y})"
 | 
| 
0a578fb7fb73
countability of the image of a reflexive transitive closure
 hoelzl parents: 
53381diff
changeset | 287 | assumes "countable Y" | 
| 
0a578fb7fb73
countability of the image of a reflexive transitive closure
 hoelzl parents: 
53381diff
changeset | 288 | shows "countable (X `` Y)" | 
| 
0a578fb7fb73
countability of the image of a reflexive transitive closure
 hoelzl parents: 
53381diff
changeset | 289 | proof - | 
| 
0a578fb7fb73
countability of the image of a reflexive transitive closure
 hoelzl parents: 
53381diff
changeset | 290 |   have "countable (X `` (\<Union>y\<in>Y. {y}))"
 | 
| 
0a578fb7fb73
countability of the image of a reflexive transitive closure
 hoelzl parents: 
53381diff
changeset | 291 | unfolding Image_UN by (intro countable_UN assms) | 
| 
0a578fb7fb73
countability of the image of a reflexive transitive closure
 hoelzl parents: 
53381diff
changeset | 292 | then show ?thesis by simp | 
| 
0a578fb7fb73
countability of the image of a reflexive transitive closure
 hoelzl parents: 
53381diff
changeset | 293 | qed | 
| 
0a578fb7fb73
countability of the image of a reflexive transitive closure
 hoelzl parents: 
53381diff
changeset | 294 | |
| 
0a578fb7fb73
countability of the image of a reflexive transitive closure
 hoelzl parents: 
53381diff
changeset | 295 | lemma countable_relpow: | 
| 
0a578fb7fb73
countability of the image of a reflexive transitive closure
 hoelzl parents: 
53381diff
changeset | 296 | fixes X :: "'a rel" | 
| 
0a578fb7fb73
countability of the image of a reflexive transitive closure
 hoelzl parents: 
53381diff
changeset | 297 | assumes Image_X: "\<And>Y. countable Y \<Longrightarrow> countable (X `` Y)" | 
| 
0a578fb7fb73
countability of the image of a reflexive transitive closure
 hoelzl parents: 
53381diff
changeset | 298 | assumes Y: "countable Y" | 
| 
0a578fb7fb73
countability of the image of a reflexive transitive closure
 hoelzl parents: 
53381diff
changeset | 299 | shows "countable ((X ^^ i) `` Y)" | 
| 
0a578fb7fb73
countability of the image of a reflexive transitive closure
 hoelzl parents: 
53381diff
changeset | 300 | using Y by (induct i arbitrary: Y) (auto simp: relcomp_Image Image_X) | 
| 
0a578fb7fb73
countability of the image of a reflexive transitive closure
 hoelzl parents: 
53381diff
changeset | 301 | |
| 60058 | 302 | lemma countable_funpow: | 
| 303 | fixes f :: "'a set \<Rightarrow> 'a set" | |
| 304 | assumes "\<And>A. countable A \<Longrightarrow> countable (f A)" | |
| 305 | and "countable A" | |
| 306 | shows "countable ((f ^^ n) A)" | |
| 307 | by(induction n)(simp_all add: assms) | |
| 308 | ||
| 54410 
0a578fb7fb73
countability of the image of a reflexive transitive closure
 hoelzl parents: 
53381diff
changeset | 309 | lemma countable_rtrancl: | 
| 67613 | 310 | "(\<And>Y. countable Y \<Longrightarrow> countable (X `` Y)) \<Longrightarrow> countable Y \<Longrightarrow> countable (X\<^sup>* `` Y)" | 
| 54410 
0a578fb7fb73
countability of the image of a reflexive transitive closure
 hoelzl parents: 
53381diff
changeset | 311 | unfolding rtrancl_is_UN_relpow UN_Image by (intro countable_UN countableI_type countable_relpow) | 
| 
0a578fb7fb73
countability of the image of a reflexive transitive closure
 hoelzl parents: 
53381diff
changeset | 312 | |
| 50134 | 313 | lemma countable_lists[intro, simp]: | 
| 314 | assumes A: "countable A" shows "countable (lists A)" | |
| 315 | proof - | |
| 316 | have "countable (lists (range (from_nat_into A)))" | |
| 317 | by (auto simp: lists_image) | |
| 318 | with A show ?thesis | |
| 319 | by (auto dest: subset_range_from_nat_into countable_subset lists_mono) | |
| 320 | qed | |
| 321 | ||
| 50245 
dea9363887a6
based countable topological basis on Countable_Set
 immler parents: 
50148diff
changeset | 322 | lemma Collect_finite_eq_lists: "Collect finite = set ` lists UNIV" | 
| 
dea9363887a6
based countable topological basis on Countable_Set
 immler parents: 
50148diff
changeset | 323 | using finite_list by auto | 
| 
dea9363887a6
based countable topological basis on Countable_Set
 immler parents: 
50148diff
changeset | 324 | |
| 
dea9363887a6
based countable topological basis on Countable_Set
 immler parents: 
50148diff
changeset | 325 | lemma countable_Collect_finite: "countable (Collect (finite::'a::countable set\<Rightarrow>bool))" | 
| 
dea9363887a6
based countable topological basis on Countable_Set
 immler parents: 
50148diff
changeset | 326 | by (simp add: Collect_finite_eq_lists) | 
| 
dea9363887a6
based countable topological basis on Countable_Set
 immler parents: 
50148diff
changeset | 327 | |
| 64008 
17a20ca86d62
HOL-Probability: more about probability, prepare for Markov processes in the AFP
 hoelzl parents: 
63649diff
changeset | 328 | lemma countable_int: "countable \<int>" | 
| 
17a20ca86d62
HOL-Probability: more about probability, prepare for Markov processes in the AFP
 hoelzl parents: 
63649diff
changeset | 329 | unfolding Ints_def by auto | 
| 
17a20ca86d62
HOL-Probability: more about probability, prepare for Markov processes in the AFP
 hoelzl parents: 
63649diff
changeset | 330 | |
| 50936 
b28f258ebc1a
countablility of finite subsets and rational numbers
 hoelzl parents: 
50245diff
changeset | 331 | lemma countable_rat: "countable \<rat>" | 
| 
b28f258ebc1a
countablility of finite subsets and rational numbers
 hoelzl parents: 
50245diff
changeset | 332 | unfolding Rats_def by auto | 
| 
b28f258ebc1a
countablility of finite subsets and rational numbers
 hoelzl parents: 
50245diff
changeset | 333 | |
| 
b28f258ebc1a
countablility of finite subsets and rational numbers
 hoelzl parents: 
50245diff
changeset | 334 | lemma Collect_finite_subset_eq_lists: "{A. finite A \<and> A \<subseteq> T} = set ` lists T"
 | 
| 
b28f258ebc1a
countablility of finite subsets and rational numbers
 hoelzl parents: 
50245diff
changeset | 335 | using finite_list by (auto simp: lists_eq_set) | 
| 
b28f258ebc1a
countablility of finite subsets and rational numbers
 hoelzl parents: 
50245diff
changeset | 336 | |
| 
b28f258ebc1a
countablility of finite subsets and rational numbers
 hoelzl parents: 
50245diff
changeset | 337 | lemma countable_Collect_finite_subset: | 
| 
b28f258ebc1a
countablility of finite subsets and rational numbers
 hoelzl parents: 
50245diff
changeset | 338 |   "countable T \<Longrightarrow> countable {A. finite A \<and> A \<subseteq> T}"
 | 
| 
b28f258ebc1a
countablility of finite subsets and rational numbers
 hoelzl parents: 
50245diff
changeset | 339 | unfolding Collect_finite_subset_eq_lists by auto | 
| 
b28f258ebc1a
countablility of finite subsets and rational numbers
 hoelzl parents: 
50245diff
changeset | 340 | |
| 71848 
3c7852327787
A few new theorems, plus some tidying up
 paulson <lp15@cam.ac.uk> parents: 
70178diff
changeset | 341 | lemma countable_Fpow: "countable S \<Longrightarrow> countable (Fpow S)" | 
| 
3c7852327787
A few new theorems, plus some tidying up
 paulson <lp15@cam.ac.uk> parents: 
70178diff
changeset | 342 | using countable_Collect_finite_subset | 
| 
3c7852327787
A few new theorems, plus some tidying up
 paulson <lp15@cam.ac.uk> parents: 
70178diff
changeset | 343 | by (force simp add: Fpow_def conj_commute) | 
| 
3c7852327787
A few new theorems, plus some tidying up
 paulson <lp15@cam.ac.uk> parents: 
70178diff
changeset | 344 | |
| 60058 | 345 | lemma countable_set_option [simp]: "countable (set_option x)" | 
| 71848 
3c7852327787
A few new theorems, plus some tidying up
 paulson <lp15@cam.ac.uk> parents: 
70178diff
changeset | 346 | by (cases x) auto | 
| 60058 | 347 | |
| 60500 | 348 | subsection \<open>Misc lemmas\<close> | 
| 50134 | 349 | |
| 63301 | 350 | lemma countable_subset_image: | 
| 351 | "countable B \<and> B \<subseteq> (f ` A) \<longleftrightarrow> (\<exists>A'. countable A' \<and> A' \<subseteq> A \<and> (B = f ` A'))" | |
| 352 | (is "?lhs = ?rhs") | |
| 353 | proof | |
| 354 | assume ?lhs | |
| 63649 | 355 | show ?rhs | 
| 356 | by (rule exI [where x="inv_into A f ` B"]) | |
| 357 | (use \<open>?lhs\<close> in \<open>auto simp: f_inv_into_f subset_iff image_inv_into_cancel inv_into_into\<close>) | |
| 63301 | 358 | next | 
| 359 | assume ?rhs | |
| 360 | then show ?lhs by force | |
| 361 | qed | |
| 362 | ||
| 70178 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 363 | lemma ex_subset_image_inj: | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 364 | "(\<exists>T. T \<subseteq> f ` S \<and> P T) \<longleftrightarrow> (\<exists>T. T \<subseteq> S \<and> inj_on f T \<and> P (f ` T))" | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 365 | by (auto simp: subset_image_inj) | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 366 | |
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 367 | lemma all_subset_image_inj: | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 368 | "(\<forall>T. T \<subseteq> f ` S \<longrightarrow> P T) \<longleftrightarrow> (\<forall>T. T \<subseteq> S \<and> inj_on f T \<longrightarrow> P(f ` T))" | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 369 | by (metis subset_image_inj) | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 370 | |
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 371 | lemma ex_countable_subset_image_inj: | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 372 | "(\<exists>T. countable T \<and> T \<subseteq> f ` S \<and> P T) \<longleftrightarrow> | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 373 | (\<exists>T. countable T \<and> T \<subseteq> S \<and> inj_on f T \<and> P (f ` T))" | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 374 | by (metis countable_image_inj_eq subset_image_inj) | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 375 | |
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 376 | lemma all_countable_subset_image_inj: | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 377 | "(\<forall>T. countable T \<and> T \<subseteq> f ` S \<longrightarrow> P T) \<longleftrightarrow> (\<forall>T. countable T \<and> T \<subseteq> S \<and> inj_on f T \<longrightarrow>P(f ` T))" | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 378 | by (metis countable_image_inj_eq subset_image_inj) | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 379 | |
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 380 | lemma ex_countable_subset_image: | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 381 | "(\<exists>T. countable T \<and> T \<subseteq> f ` S \<and> P T) \<longleftrightarrow> (\<exists>T. countable T \<and> T \<subseteq> S \<and> P (f ` T))" | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 382 | by (metis countable_subset_image) | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 383 | |
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 384 | lemma all_countable_subset_image: | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 385 | "(\<forall>T. countable T \<and> T \<subseteq> f ` S \<longrightarrow> P T) \<longleftrightarrow> (\<forall>T. countable T \<and> T \<subseteq> S \<longrightarrow> P(f ` T))" | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 386 | by (metis countable_subset_image) | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 387 | |
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 388 | lemma countable_image_eq: | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 389 | "countable(f ` S) \<longleftrightarrow> (\<exists>T. countable T \<and> T \<subseteq> S \<and> f ` S = f ` T)" | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 390 | by (metis countable_image countable_image_inj_eq order_refl subset_image_inj) | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 391 | |
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 392 | lemma countable_image_eq_inj: | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 393 | "countable(f ` S) \<longleftrightarrow> (\<exists>T. countable T \<and> T \<subseteq> S \<and> f ` S = f ` T \<and> inj_on f T)" | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 394 | by (metis countable_image_inj_eq order_refl subset_image_inj) | 
| 
4900351361b0
Lindelöf spaces and supporting material
 paulson <lp15@cam.ac.uk> parents: 
69661diff
changeset | 395 | |
| 62648 | 396 | lemma infinite_countable_subset': | 
| 397 | assumes X: "infinite X" shows "\<exists>C\<subseteq>X. countable C \<and> infinite C" | |
| 398 | proof - | |
| 74325 | 399 | obtain f :: "nat \<Rightarrow> 'a" where "inj f" "range f \<subseteq> X" | 
| 400 | using infinite_countable_subset [OF X] by blast | |
| 62648 | 401 | then show ?thesis | 
| 402 | by (intro exI[of _ "range f"]) (auto simp: range_inj_infinite) | |
| 403 | qed | |
| 404 | ||
| 50134 | 405 | lemma countable_all: | 
| 406 | assumes S: "countable S" | |
| 407 | shows "(\<forall>s\<in>S. P s) \<longleftrightarrow> (\<forall>n::nat. from_nat_into S n \<in> S \<longrightarrow> P (from_nat_into S n))" | |
| 408 | using S[THEN subset_range_from_nat_into] by auto | |
| 409 | ||
| 57025 | 410 | lemma finite_sequence_to_countable_set: | 
| 69661 | 411 | assumes "countable X" | 
| 412 | obtains F where "\<And>i. F i \<subseteq> X" "\<And>i. F i \<subseteq> F (Suc i)" "\<And>i. finite (F i)" "(\<Union>i. F i) = X" | |
| 413 | proof - | |
| 414 | show thesis | |
| 57025 | 415 |     apply (rule that[of "\<lambda>i. if X = {} then {} else from_nat_into X ` {..i}"])
 | 
| 69661 | 416 | apply (auto simp add: image_iff intro: from_nat_into split: if_splits) | 
| 417 | using assms from_nat_into_surj by (fastforce cong: image_cong) | |
| 57025 | 418 | qed | 
| 419 | ||
| 62370 | 420 | lemma transfer_countable[transfer_rule]: | 
| 67399 | 421 | "bi_unique R \<Longrightarrow> rel_fun (rel_set R) (=) countable countable" | 
| 62370 | 422 | by (rule rel_funI, erule (1) bi_unique_rel_set_lemma) | 
| 423 | (auto dest: countable_image_inj_on) | |
| 424 | ||
| 60500 | 425 | subsection \<open>Uncountable\<close> | 
| 57234 
596a499318ab
clean up ContNotDenum; add lemmas by Jeremy Avigad and Luke Serafin
 hoelzl parents: 
57025diff
changeset | 426 | |
| 
596a499318ab
clean up ContNotDenum; add lemmas by Jeremy Avigad and Luke Serafin
 hoelzl parents: 
57025diff
changeset | 427 | abbreviation uncountable where | 
| 
596a499318ab
clean up ContNotDenum; add lemmas by Jeremy Avigad and Luke Serafin
 hoelzl parents: 
57025diff
changeset | 428 | "uncountable A \<equiv> \<not> countable A" | 
| 
596a499318ab
clean up ContNotDenum; add lemmas by Jeremy Avigad and Luke Serafin
 hoelzl parents: 
57025diff
changeset | 429 | |
| 
596a499318ab
clean up ContNotDenum; add lemmas by Jeremy Avigad and Luke Serafin
 hoelzl parents: 
57025diff
changeset | 430 | lemma uncountable_def: "uncountable A \<longleftrightarrow> A \<noteq> {} \<and> \<not> (\<exists>f::(nat \<Rightarrow> 'a). range f = A)"
 | 
| 
596a499318ab
clean up ContNotDenum; add lemmas by Jeremy Avigad and Luke Serafin
 hoelzl parents: 
57025diff
changeset | 431 | by (auto intro: inj_on_inv_into simp: countable_def) | 
| 
596a499318ab
clean up ContNotDenum; add lemmas by Jeremy Avigad and Luke Serafin
 hoelzl parents: 
57025diff
changeset | 432 | (metis all_not_in_conv inj_on_iff_surj subset_UNIV) | 
| 
596a499318ab
clean up ContNotDenum; add lemmas by Jeremy Avigad and Luke Serafin
 hoelzl parents: 
57025diff
changeset | 433 | |
| 
596a499318ab
clean up ContNotDenum; add lemmas by Jeremy Avigad and Luke Serafin
 hoelzl parents: 
57025diff
changeset | 434 | lemma uncountable_bij_betw: "bij_betw f A B \<Longrightarrow> uncountable B \<Longrightarrow> uncountable A" | 
| 
596a499318ab
clean up ContNotDenum; add lemmas by Jeremy Avigad and Luke Serafin
 hoelzl parents: 
57025diff
changeset | 435 | unfolding bij_betw_def by (metis countable_image) | 
| 62370 | 436 | |
| 57234 
596a499318ab
clean up ContNotDenum; add lemmas by Jeremy Avigad and Luke Serafin
 hoelzl parents: 
57025diff
changeset | 437 | lemma uncountable_infinite: "uncountable A \<Longrightarrow> infinite A" | 
| 
596a499318ab
clean up ContNotDenum; add lemmas by Jeremy Avigad and Luke Serafin
 hoelzl parents: 
57025diff
changeset | 438 | by (metis countable_finite) | 
| 62370 | 439 | |
| 57234 
596a499318ab
clean up ContNotDenum; add lemmas by Jeremy Avigad and Luke Serafin
 hoelzl parents: 
57025diff
changeset | 440 | lemma uncountable_minus_countable: | 
| 
596a499318ab
clean up ContNotDenum; add lemmas by Jeremy Avigad and Luke Serafin
 hoelzl parents: 
57025diff
changeset | 441 | "uncountable A \<Longrightarrow> countable B \<Longrightarrow> uncountable (A - B)" | 
| 63092 | 442 | using countable_Un[of B "A - B"] by auto | 
| 57234 
596a499318ab
clean up ContNotDenum; add lemmas by Jeremy Avigad and Luke Serafin
 hoelzl parents: 
57025diff
changeset | 443 | |
| 60303 | 444 | lemma countable_Diff_eq [simp]: "countable (A - {x}) = countable A"
 | 
| 445 | by (meson countable_Diff countable_empty countable_insert uncountable_minus_countable) | |
| 446 | ||
| 71848 
3c7852327787
A few new theorems, plus some tidying up
 paulson <lp15@cam.ac.uk> parents: 
70178diff
changeset | 447 | text \<open>Every infinite set can be covered by a pairwise disjoint family of infinite sets. | 
| 
3c7852327787
A few new theorems, plus some tidying up
 paulson <lp15@cam.ac.uk> parents: 
70178diff
changeset | 448 | This version doesn't achieve equality, as it only covers a countable subset\<close> | 
| 
3c7852327787
A few new theorems, plus some tidying up
 paulson <lp15@cam.ac.uk> parents: 
70178diff
changeset | 449 | lemma infinite_infinite_partition: | 
| 
3c7852327787
A few new theorems, plus some tidying up
 paulson <lp15@cam.ac.uk> parents: 
70178diff
changeset | 450 | assumes "infinite A" | 
| 
3c7852327787
A few new theorems, plus some tidying up
 paulson <lp15@cam.ac.uk> parents: 
70178diff
changeset | 451 | obtains C :: "nat \<Rightarrow> 'a set" | 
| 
3c7852327787
A few new theorems, plus some tidying up
 paulson <lp15@cam.ac.uk> parents: 
70178diff
changeset | 452 | where "pairwise (\<lambda>i j. disjnt (C i) (C j)) UNIV" "(\<Union>i. C i) \<subseteq> A" "\<And>i. infinite (C i)" | 
| 
3c7852327787
A few new theorems, plus some tidying up
 paulson <lp15@cam.ac.uk> parents: 
70178diff
changeset | 453 | proof - | 
| 
3c7852327787
A few new theorems, plus some tidying up
 paulson <lp15@cam.ac.uk> parents: 
70178diff
changeset | 454 | obtain f :: "nat\<Rightarrow>'a" where "range f \<subseteq> A" "inj f" | 
| 
3c7852327787
A few new theorems, plus some tidying up
 paulson <lp15@cam.ac.uk> parents: 
70178diff
changeset | 455 | using assms infinite_countable_subset by blast | 
| 
3c7852327787
A few new theorems, plus some tidying up
 paulson <lp15@cam.ac.uk> parents: 
70178diff
changeset | 456 | let ?C = "\<lambda>i. range (\<lambda>j. f (prod_encode (i,j)))" | 
| 
3c7852327787
A few new theorems, plus some tidying up
 paulson <lp15@cam.ac.uk> parents: 
70178diff
changeset | 457 | show thesis | 
| 
3c7852327787
A few new theorems, plus some tidying up
 paulson <lp15@cam.ac.uk> parents: 
70178diff
changeset | 458 | proof | 
| 
3c7852327787
A few new theorems, plus some tidying up
 paulson <lp15@cam.ac.uk> parents: 
70178diff
changeset | 459 | show "pairwise (\<lambda>i j. disjnt (?C i) (?C j)) UNIV" | 
| 
3c7852327787
A few new theorems, plus some tidying up
 paulson <lp15@cam.ac.uk> parents: 
70178diff
changeset | 460 | by (auto simp: pairwise_def disjnt_def inj_on_eq_iff [OF \<open>inj f\<close>] inj_on_eq_iff [OF inj_prod_encode, of _ UNIV]) | 
| 
3c7852327787
A few new theorems, plus some tidying up
 paulson <lp15@cam.ac.uk> parents: 
70178diff
changeset | 461 | show "(\<Union>i. ?C i) \<subseteq> A" | 
| 
3c7852327787
A few new theorems, plus some tidying up
 paulson <lp15@cam.ac.uk> parents: 
70178diff
changeset | 462 | using \<open>range f \<subseteq> A\<close> by blast | 
| 
3c7852327787
A few new theorems, plus some tidying up
 paulson <lp15@cam.ac.uk> parents: 
70178diff
changeset | 463 | have "infinite (range (\<lambda>j. f (prod_encode (i, j))))" for i | 
| 
3c7852327787
A few new theorems, plus some tidying up
 paulson <lp15@cam.ac.uk> parents: 
70178diff
changeset | 464 | by (rule range_inj_infinite) (meson Pair_inject \<open>inj f\<close> inj_def prod_encode_eq) | 
| 
3c7852327787
A few new theorems, plus some tidying up
 paulson <lp15@cam.ac.uk> parents: 
70178diff
changeset | 465 | then show "\<And>i. infinite (?C i)" | 
| 
3c7852327787
A few new theorems, plus some tidying up
 paulson <lp15@cam.ac.uk> parents: 
70178diff
changeset | 466 | using that by auto | 
| 
3c7852327787
A few new theorems, plus some tidying up
 paulson <lp15@cam.ac.uk> parents: 
70178diff
changeset | 467 | qed | 
| 
3c7852327787
A few new theorems, plus some tidying up
 paulson <lp15@cam.ac.uk> parents: 
70178diff
changeset | 468 | qed | 
| 
3c7852327787
A few new theorems, plus some tidying up
 paulson <lp15@cam.ac.uk> parents: 
70178diff
changeset | 469 | |
| 50134 | 470 | end |