src/HOL/BNF/Countable_Type.thy
author traytel
Tue, 16 Jul 2013 15:59:55 +0200
changeset 53799 c7cae5ce217d
parent 53797 7f7311d04727
child 54150 3fbcfa911863
permissions -rw-r--r--
use transfer/lifting for proving countable set and multisets being BNFs
hoelzl@51159
     1
(*  Title:      HOL/BNF/Countable_Type.thy
blanchet@49990
     2
    Author:     Andrei Popescu, TU Muenchen
blanchet@49990
     3
    Copyright   2012
blanchet@49990
     4
blanchet@49990
     5
(At most) countable sets.
blanchet@49990
     6
*)
blanchet@49990
     7
blanchet@49990
     8
header {* (At Most) Countable Sets *}
blanchet@49990
     9
hoelzl@51159
    10
theory Countable_Type
traytel@53799
    11
imports
traytel@53799
    12
  "~~/src/HOL/Cardinals/Cardinals"
traytel@53799
    13
  "~~/src/HOL/Library/Countable_Set"
traytel@53799
    14
  "~~/src/HOL/Library/Quotient_Set"
blanchet@49990
    15
begin
blanchet@49990
    16
hoelzl@51159
    17
subsection{* Cardinal stuff *}
blanchet@49990
    18
hoelzl@51159
    19
lemma countable_card_of_nat: "countable A \<longleftrightarrow> |A| \<le>o |UNIV::nat set|"
hoelzl@51159
    20
  unfolding countable_def card_of_ordLeq[symmetric] by auto
blanchet@49990
    21
hoelzl@51159
    22
lemma countable_card_le_natLeq: "countable A \<longleftrightarrow> |A| \<le>o natLeq"
hoelzl@51159
    23
  unfolding countable_card_of_nat using card_of_nat ordLeq_ordIso_trans ordIso_symmetric by blast
blanchet@49990
    24
blanchet@49990
    25
lemma countable_or_card_of:
blanchet@49990
    26
assumes "countable A"
blanchet@49990
    27
shows "(finite A \<and> |A| <o |UNIV::nat set| ) \<or>
blanchet@49990
    28
       (infinite A  \<and> |A| =o |UNIV::nat set| )"
traytel@53799
    29
proof (cases "finite A")
traytel@53799
    30
  case True thus ?thesis by (metis finite_iff_cardOf_nat)
traytel@53799
    31
next
traytel@53799
    32
  case False with assms show ?thesis
traytel@53799
    33
    by (metis countable_card_of_nat infinite_iff_card_of_nat ordIso_iff_ordLeq)
traytel@53799
    34
qed
blanchet@49990
    35
hoelzl@51159
    36
lemma countable_cases_card_of[elim]:
hoelzl@51159
    37
  assumes "countable A"
hoelzl@51159
    38
  obtains (Fin) "finite A" "|A| <o |UNIV::nat set|"
hoelzl@51159
    39
        | (Inf) "infinite A" "|A| =o |UNIV::nat set|"
hoelzl@51159
    40
  using assms countable_or_card_of by blast
hoelzl@51159
    41
blanchet@49990
    42
lemma countable_or:
hoelzl@51159
    43
  "countable A \<Longrightarrow> (\<exists> f::'a\<Rightarrow>nat. finite A \<and> inj_on f A) \<or> (\<exists> f::'a\<Rightarrow>nat. infinite A \<and> bij_betw f A UNIV)"
traytel@53799
    44
  by (elim countable_enum_cases) fastforce+
blanchet@49990
    45
hoelzl@51159
    46
lemma countable_cases[elim]:
hoelzl@51159
    47
  assumes "countable A"
hoelzl@51159
    48
  obtains (Fin) f :: "'a\<Rightarrow>nat" where "finite A" "inj_on f A"
hoelzl@51159
    49
        | (Inf) f :: "'a\<Rightarrow>nat" where "infinite A" "bij_betw f A UNIV"
hoelzl@51159
    50
  using assms countable_or by metis
blanchet@49990
    51
blanchet@49990
    52
lemma countable_ordLeq:
blanchet@49990
    53
assumes "|A| \<le>o |B|" and "countable B"
blanchet@49990
    54
shows "countable A"
blanchet@49990
    55
using assms unfolding countable_card_of_nat by(rule ordLeq_transitive)
blanchet@49990
    56
blanchet@49990
    57
lemma countable_ordLess:
blanchet@49990
    58
assumes AB: "|A| <o |B|" and B: "countable B"
blanchet@49990
    59
shows "countable A"
blanchet@49990
    60
using countable_ordLeq[OF ordLess_imp_ordLeq[OF AB] B] .
blanchet@49990
    61
blanchet@49990
    62
subsection{*  The type of countable sets *}
blanchet@49990
    63
traytel@53799
    64
typedef 'a cset = "{A :: 'a set. countable A}" morphisms rcset acset
traytel@53799
    65
  by (rule exI[of _ "{}"]) simp
blanchet@49990
    66
traytel@53799
    67
setup_lifting type_definition_cset
blanchet@49990
    68
traytel@53799
    69
declare
traytel@53799
    70
  rcset_inverse[simp]
traytel@53799
    71
  acset_inverse[Transfer.transferred, unfolded mem_Collect_eq, simp]
traytel@53799
    72
  acset_inject[Transfer.transferred, unfolded mem_Collect_eq, simp]
traytel@53799
    73
  rcset[Transfer.transferred, unfolded mem_Collect_eq, simp]
blanchet@49990
    74
traytel@53799
    75
lift_definition cin :: "'a \<Rightarrow> 'a cset \<Rightarrow> bool" is "op \<in>" parametric member_transfer
traytel@53799
    76
  ..
traytel@53799
    77
lift_definition cempty :: "'a cset" is "{}" parametric empty_transfer
traytel@53799
    78
  by (rule countable_empty)
traytel@53799
    79
lift_definition cinsert :: "'a \<Rightarrow> 'a cset \<Rightarrow> 'a cset" is insert parametric insert_transfer
traytel@53799
    80
  by (rule countable_insert)
traytel@53799
    81
lift_definition csingle :: "'a \<Rightarrow> 'a cset" is "\<lambda>x. {x}"
traytel@53799
    82
  by (rule countable_insert[OF countable_empty])
traytel@53799
    83
lift_definition cUn :: "'a cset \<Rightarrow> 'a cset \<Rightarrow> 'a cset" is "op \<union>" parametric union_transfer
traytel@53799
    84
  by (rule countable_Un)
traytel@53799
    85
lift_definition cInt :: "'a cset \<Rightarrow> 'a cset \<Rightarrow> 'a cset" is "op \<inter>" parametric inter_transfer
traytel@53799
    86
  by (rule countable_Int1)
traytel@53799
    87
lift_definition cDiff :: "'a cset \<Rightarrow> 'a cset \<Rightarrow> 'a cset" is "op -" parametric Diff_transfer
traytel@53799
    88
  by (rule countable_Diff)
traytel@53799
    89
lift_definition cimage :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a cset \<Rightarrow> 'b cset" is "op `" parametric image_transfer
traytel@53799
    90
  by (rule countable_image)
blanchet@49990
    91
blanchet@49990
    92
end