src/HOL/Library/Countable_Set.thy
author hoelzl
Tue, 20 Nov 2012 18:59:35 +0100
changeset 50134 13211e07d931
child 50144 885deccc264e
permissions -rw-r--r--
add Countable_Set theory
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50134
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
     1
(*  Title:      HOL/Library/Countable_Set.thy
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
     2
    Author:     Johannes Hölzl
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
     3
    Author:     Andrei Popescu
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
     4
*)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
     5
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
     6
header {* Countable sets *}
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
     7
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
     8
theory Countable_Set
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
     9
  imports "~~/src/HOL/Library/Countable" "~~/src/HOL/Library/Infinite_Set"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    10
begin
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    11
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    12
subsection {* Predicate for countable sets *}
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    13
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    14
definition countable :: "'a set \<Rightarrow> bool" where
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    15
  "countable S \<longleftrightarrow> (\<exists>f::'a \<Rightarrow> nat. inj_on f S)"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    16
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    17
lemma countableE:
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    18
  assumes S: "countable S" obtains f :: "'a \<Rightarrow> nat" where "inj_on f S"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    19
  using S by (auto simp: countable_def)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    20
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    21
lemma countableI: "inj_on (f::'a \<Rightarrow> nat) S \<Longrightarrow> countable S"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    22
  by (auto simp: countable_def)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    23
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    24
lemma countableI': "inj_on (f::'a \<Rightarrow> 'b::countable) S \<Longrightarrow> countable S"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    25
  using comp_inj_on[of f S to_nat] by (auto intro: countableI)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    26
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    27
lemma countableE_bij:
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    28
  assumes S: "countable S" obtains f :: "nat \<Rightarrow> 'a" and C :: "nat set" where "bij_betw f C S"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    29
  using S by (blast elim: countableE dest: inj_on_imp_bij_betw bij_betw_inv)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    30
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    31
lemma countableI_bij: "bij_betw f (C::nat set) S \<Longrightarrow> countable S"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    32
  by (blast intro: countableI bij_betw_inv_into bij_betw_imp_inj_on)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    33
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    34
lemma countable_finite: "finite S \<Longrightarrow> countable S"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    35
  by (blast dest: finite_imp_inj_to_nat_seg countableI)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    36
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    37
lemma countableI_bij1: "bij_betw f A B \<Longrightarrow> countable A \<Longrightarrow> countable B"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    38
  by (blast elim: countableE_bij intro: bij_betw_trans countableI_bij)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    39
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    40
lemma countableI_bij2: "bij_betw f B A \<Longrightarrow> countable A \<Longrightarrow> countable B"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    41
  by (blast elim: countableE_bij intro: bij_betw_trans bij_betw_inv_into countableI_bij)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    42
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    43
lemma countable_iff_bij[simp]: "bij_betw f A B \<Longrightarrow> countable A \<longleftrightarrow> countable B"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    44
  by (blast intro: countableI_bij1 countableI_bij2)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    45
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    46
lemma countable_subset: "A \<subseteq> B \<Longrightarrow> countable B \<Longrightarrow> countable A"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    47
  by (auto simp: countable_def intro: subset_inj_on)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    48
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    49
lemma countableI_type[intro, simp]: "countable (A:: 'a :: countable set)"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    50
  using countableI[of to_nat A] by auto
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    51
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    52
subsection {* Enumerate a countable set *}
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    53
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    54
lemma countableE_infinite:
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    55
  assumes "countable S" "infinite S"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    56
  obtains e :: "'a \<Rightarrow> nat" where "bij_betw e S UNIV"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    57
proof -
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    58
  from `countable S`[THEN countableE] guess f .
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    59
  then have "bij_betw f S (f`S)"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    60
    unfolding bij_betw_def by simp
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    61
  moreover
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    62
  from `inj_on f S` `infinite S` have inf_fS: "infinite (f`S)"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    63
    by (auto dest: finite_imageD)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    64
  then have "bij_betw (the_inv_into UNIV (enumerate (f`S))) (f`S) UNIV"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    65
    by (intro bij_betw_the_inv_into bij_enumerate)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    66
  ultimately have "bij_betw (the_inv_into UNIV (enumerate (f`S)) \<circ> f) S UNIV"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    67
    by (rule bij_betw_trans)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    68
  then show thesis ..
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    69
qed
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    70
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    71
lemma countable_enum_cases:
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    72
  assumes "countable S"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    73
  obtains (finite) f :: "'a \<Rightarrow> nat" where "finite S" "bij_betw f S {..<card S}"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    74
        | (infinite) f :: "'a \<Rightarrow> nat" where "infinite S" "bij_betw f S UNIV"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    75
  using ex_bij_betw_finite_nat[of S] countableE_infinite `countable S`
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    76
  by (cases "finite S") (auto simp add: atLeast0LessThan)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    77
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    78
definition to_nat_on :: "'a set \<Rightarrow> 'a \<Rightarrow> nat" where
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    79
  "to_nat_on S = (SOME f. if finite S then bij_betw f S {..< card S} else bij_betw f S UNIV)"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    80
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    81
definition from_nat_into :: "'a set \<Rightarrow> nat \<Rightarrow> 'a" where
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    82
  "from_nat_into S = inv_into S (to_nat_on S)"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    83
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    84
lemma to_nat_on_finite: "finite S \<Longrightarrow> bij_betw (to_nat_on S) S {..< card S}"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    85
  using ex_bij_betw_finite_nat unfolding to_nat_on_def
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    86
  by (intro someI2_ex[where Q="\<lambda>f. bij_betw f S {..<card S}"]) (auto simp add: atLeast0LessThan)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    87
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    88
lemma to_nat_on_infinite: "countable S \<Longrightarrow> infinite S \<Longrightarrow> bij_betw (to_nat_on S) S UNIV"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    89
  using countableE_infinite unfolding to_nat_on_def
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    90
  by (intro someI2_ex[where Q="\<lambda>f. bij_betw f S UNIV"]) auto
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    91
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    92
lemma from_nat_into_finite: "finite S \<Longrightarrow> bij_betw (from_nat_into S) {..< card S} S"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    93
  by (auto simp add: from_nat_into_def intro: bij_betw_inv_into to_nat_on_finite)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    94
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    95
lemma from_nat_into_infinite: "countable S \<Longrightarrow> infinite S \<Longrightarrow> bij_betw (from_nat_into S) UNIV S"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    96
  by (auto simp add: from_nat_into_def intro: bij_betw_inv_into to_nat_on_infinite)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    97
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    98
lemma inj_on_to_nat_on[intro]: "countable A \<Longrightarrow> inj_on (to_nat_on A) A"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
    99
  using to_nat_on_infinite[of A] to_nat_on_finite[of A]
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   100
  by (cases "finite A") (auto simp: bij_betw_def)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   101
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   102
lemma to_nat_on_inj[simp]:
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   103
  "countable A \<Longrightarrow> a \<in> A \<Longrightarrow> b \<in> A \<Longrightarrow> to_nat_on A a = to_nat_on A b \<longleftrightarrow> a = b"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   104
  using inj_on_to_nat_on[of A] by (auto dest: inj_onD)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   105
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   106
lemma from_nat_into_to_nat_on: "countable A \<Longrightarrow> a \<in> A \<Longrightarrow> from_nat_into A (to_nat_on A a) = a"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   107
  by (auto simp: from_nat_into_def intro!: inv_into_f_f)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   108
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   109
lemma subset_range_from_nat_into: "countable A \<Longrightarrow> A \<subseteq> range (from_nat_into A)"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   110
  by (auto intro: from_nat_into_to_nat_on[symmetric])
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   111
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   112
subsection {* Closure properties of countability *}
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   113
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   114
lemma countable_SIGMA[intro, simp]:
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   115
  "countable I \<Longrightarrow> (\<And>i. i \<in> I \<Longrightarrow> countable (A i)) \<Longrightarrow> countable (SIGMA i : I. A i)"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   116
  by (intro countableI'[of "\<lambda>(i, a). (to_nat_on I i, to_nat_on (A i) a)"]) (auto simp: inj_on_def)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   117
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   118
lemma countable_image[intro, simp]: assumes A: "countable A" shows "countable (f`A)"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   119
proof -
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   120
  from A guess g by (rule countableE)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   121
  moreover have "inj_on (inv_into A f) (f`A)" "inv_into A f ` f ` A \<subseteq> A"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   122
    by (auto intro: inj_on_inv_into inv_into_into)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   123
  ultimately show ?thesis
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   124
    by (blast dest: comp_inj_on subset_inj_on intro: countableI)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   125
qed
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   126
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   127
lemma countable_UN[intro, simp]:
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   128
  fixes I :: "'i set" and A :: "'i => 'a set"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   129
  assumes I: "countable I"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   130
  assumes A: "\<And>i. i \<in> I \<Longrightarrow> countable (A i)"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   131
  shows "countable (\<Union>i\<in>I. A i)"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   132
proof -
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   133
  have "(\<Union>i\<in>I. A i) = snd ` (SIGMA i : I. A i)" by (auto simp: image_iff)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   134
  then show ?thesis by (simp add: assms)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   135
qed
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   136
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   137
lemma countable_Un[intro]: "countable A \<Longrightarrow> countable B \<Longrightarrow> countable (A \<union> B)"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   138
  by (rule countable_UN[of "{True, False}" "\<lambda>True \<Rightarrow> A | False \<Rightarrow> B", simplified])
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   139
     (simp split: bool.split)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   140
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   141
lemma countable_Un_iff[simp]: "countable (A \<union> B) \<longleftrightarrow> countable A \<and> countable B"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   142
  by (metis countable_Un countable_subset inf_sup_ord(3,4))
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   143
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   144
lemma countable_Plus[intro, simp]:
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   145
  "countable A \<Longrightarrow> countable B \<Longrightarrow> countable (A <+> B)"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   146
  by (simp add: Plus_def)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   147
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   148
lemma countable_empty[intro, simp]: "countable {}"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   149
  by (blast intro: countable_finite)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   150
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   151
lemma countable_insert[intro, simp]: "countable A \<Longrightarrow> countable (insert a A)"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   152
  using countable_Un[of "{a}" A] by (auto simp: countable_finite)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   153
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   154
lemma countable_Int1[intro, simp]: "countable A \<Longrightarrow> countable (A \<inter> B)"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   155
  by (force intro: countable_subset)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   156
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   157
lemma countable_Int2[intro, simp]: "countable B \<Longrightarrow> countable (A \<inter> B)"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   158
  by (blast intro: countable_subset)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   159
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   160
lemma countable_INT[intro, simp]: "i \<in> I \<Longrightarrow> countable (A i) \<Longrightarrow> countable (\<Inter>i\<in>I. A i)"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   161
  by (blast intro: countable_subset)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   162
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   163
lemma countable_Diff[intro, simp]: "countable A \<Longrightarrow> countable (A - B)"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   164
  by (blast intro: countable_subset)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   165
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   166
lemma countable_vimage: "B \<subseteq> range f \<Longrightarrow> countable (f -` B) \<Longrightarrow> countable B"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   167
  by (metis Int_absorb2 assms countable_image image_vimage_eq)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   168
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   169
lemma surj_countable_vimage: "surj f \<Longrightarrow> countable (f -` B) \<Longrightarrow> countable B"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   170
  by (metis countable_vimage top_greatest)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   171
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   172
lemma countable_lists[intro, simp]:
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   173
  assumes A: "countable A" shows "countable (lists A)"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   174
proof -
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   175
  have "countable (lists (range (from_nat_into A)))"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   176
    by (auto simp: lists_image)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   177
  with A show ?thesis
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   178
    by (auto dest: subset_range_from_nat_into countable_subset lists_mono)
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   179
qed
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   180
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   181
subsection {* Misc lemmas *}
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   182
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   183
lemma countable_all:
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   184
  assumes S: "countable S"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   185
  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))"
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   186
  using S[THEN subset_range_from_nat_into] by auto
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   187
13211e07d931 add Countable_Set theory
hoelzl
parents:
diff changeset
   188
end