blanchet@55075: (* Title: HOL/Library/Countable_Set_Type.thy blanchet@48975: Author: Andrei Popescu, TU Muenchen blanchet@48975: Copyright 2012 blanchet@48975: blanchet@54539: Type of (at most) countable sets. blanchet@48975: *) blanchet@48975: blanchet@54539: header {* Type of (at Most) Countable Sets *} blanchet@48975: blanchet@54539: theory Countable_Set_Type blanchet@55075: imports Countable_Set Cardinal_Notations blanchet@48975: begin blanchet@48975: blanchet@57398: abbreviation "Grp \ BNF_Def.Grp" blanchet@55070: blanchet@55070: hoelzl@50144: subsection{* Cardinal stuff *} blanchet@48975: hoelzl@50144: lemma countable_card_of_nat: "countable A \ |A| \o |UNIV::nat set|" hoelzl@50144: unfolding countable_def card_of_ordLeq[symmetric] by auto blanchet@48975: hoelzl@50144: lemma countable_card_le_natLeq: "countable A \ |A| \o natLeq" hoelzl@50144: unfolding countable_card_of_nat using card_of_nat ordLeq_ordIso_trans ordIso_symmetric by blast blanchet@48975: blanchet@48975: lemma countable_or_card_of: blanchet@48975: assumes "countable A" blanchet@48975: shows "(finite A \ |A| blanchet@48975: (infinite A \ |A| =o |UNIV::nat set| )" blanchet@55070: by (metis assms countable_card_of_nat infinite_iff_card_of_nat ordIso_iff_ordLeq blanchet@55070: ordLeq_iff_ordLess_or_ordIso) blanchet@48975: hoelzl@50144: lemma countable_cases_card_of[elim]: hoelzl@50144: assumes "countable A" hoelzl@50144: obtains (Fin) "finite A" "|A| (\ f::'a\nat. finite A \ inj_on f A) \ (\ f::'a\nat. infinite A \ bij_betw f A UNIV)" traytel@52662: by (elim countable_enum_cases) fastforce+ blanchet@48975: hoelzl@50144: lemma countable_cases[elim]: hoelzl@50144: assumes "countable A" hoelzl@50144: obtains (Fin) f :: "'a\nat" where "finite A" "inj_on f A" hoelzl@50144: | (Inf) f :: "'a\nat" where "infinite A" "bij_betw f A UNIV" hoelzl@50144: using assms countable_or by metis blanchet@48975: blanchet@48975: lemma countable_ordLeq: blanchet@48975: assumes "|A| \o |B|" and "countable B" blanchet@48975: shows "countable A" blanchet@48975: using assms unfolding countable_card_of_nat by(rule ordLeq_transitive) blanchet@48975: blanchet@48975: lemma countable_ordLess: blanchet@48975: assumes AB: "|A| 'a cset \ bool" is "op \" parametric member_transfer kuncar@55565: . traytel@52662: lift_definition cempty :: "'a cset" is "{}" parametric empty_transfer traytel@52662: by (rule countable_empty) kuncar@53013: lift_definition cinsert :: "'a \ 'a cset \ 'a cset" is insert parametric Lifting_Set.insert_transfer traytel@52662: by (rule countable_insert) traytel@52662: lift_definition csingle :: "'a \ 'a cset" is "\x. {x}" traytel@52662: by (rule countable_insert[OF countable_empty]) traytel@52662: lift_definition cUn :: "'a cset \ 'a cset \ 'a cset" is "op \" parametric union_transfer traytel@52662: by (rule countable_Un) traytel@52662: lift_definition cInt :: "'a cset \ 'a cset \ 'a cset" is "op \" parametric inter_transfer traytel@52662: by (rule countable_Int1) traytel@52662: lift_definition cDiff :: "'a cset \ 'a cset \ 'a cset" is "op -" parametric Diff_transfer traytel@52662: by (rule countable_Diff) traytel@52662: lift_definition cimage :: "('a \ 'b) \ 'a cset \ 'b cset" is "op `" parametric image_transfer traytel@52662: by (rule countable_image) blanchet@48975: blanchet@54539: subsection {* Registration as BNF *} blanchet@54539: blanchet@54539: lemma card_of_countable_sets_range: blanchet@54539: fixes A :: "'a set" blanchet@54539: shows "|{X. X \ A \ countable X \ X \ {}}| \o |{f::nat \ 'a. range f \ A}|" blanchet@54539: apply(rule card_of_ordLeqI[of from_nat_into]) using inj_on_from_nat_into blanchet@54539: unfolding inj_on_def by auto blanchet@54539: blanchet@54539: lemma card_of_countable_sets_Func: blanchet@54539: "|{X. X \ A \ countable X \ X \ {}}| \o |A| ^c natLeq" blanchet@54539: using card_of_countable_sets_range card_of_Func_UNIV[THEN ordIso_symmetric] blanchet@54539: unfolding cexp_def Field_natLeq Field_card_of blanchet@54539: by (rule ordLeq_ordIso_trans) blanchet@54539: blanchet@54539: lemma ordLeq_countable_subsets: blanchet@54539: "|A| \o |{X. X \ A \ countable X}|" blanchet@54539: apply (rule card_of_ordLeqI[of "\ a. {a}"]) unfolding inj_on_def by auto blanchet@54539: blanchet@54539: lemma finite_countable_subset: blanchet@54539: "finite {X. X \ A \ countable X} \ finite A" blanchet@54539: apply default blanchet@54539: apply (erule contrapos_pp) blanchet@54539: apply (rule card_of_ordLeq_infinite) blanchet@54539: apply (rule ordLeq_countable_subsets) blanchet@54539: apply assumption blanchet@54539: apply (rule finite_Collect_conjI) blanchet@54539: apply (rule disjI1) blanchet@54539: by (erule finite_Collect_subsets) blanchet@54539: blanchet@54539: lemma rcset_to_rcset: "countable A \ rcset (the_inv rcset A) = A" blanchet@54539: apply (rule f_the_inv_into_f[unfolded inj_on_def image_iff]) blanchet@54539: apply transfer' apply simp blanchet@54539: apply transfer' apply simp blanchet@54539: done blanchet@54539: blanchet@54539: lemma Collect_Int_Times: blanchet@54539: "{(x, y). R x y} \ A \ B = {(x, y). R x y \ x \ A \ y \ B}" blanchet@54539: by auto blanchet@54539: blanchet@55934: definition rel_cset :: "('a \ 'b \ bool) \ 'a cset \ 'b cset \ bool" where blanchet@55934: "rel_cset R a b \ blanchet@54539: (\t \ rcset a. \u \ rcset b. R t u) \ blanchet@54539: (\t \ rcset b. \u \ rcset a. R u t)" blanchet@54539: blanchet@55934: lemma rel_cset_aux: blanchet@54539: "(\t \ rcset a. \u \ rcset b. R t u) \ (\t \ rcset b. \u \ rcset a. R u t) \ blanchet@54539: ((Grp {x. rcset x \ {(a, b). R a b}} (cimage fst))\\ OO blanchet@54539: Grp {x. rcset x \ {(a, b). R a b}} (cimage snd)) a b" (is "?L = ?R") blanchet@54539: proof blanchet@54539: assume ?L blanchet@54539: def R' \ "the_inv rcset (Collect (split R) \ (rcset a \ rcset b))" blanchet@54539: (is "the_inv rcset ?L'") blanchet@54539: have L: "countable ?L'" by auto blanchet@55070: hence *: "rcset R' = ?L'" unfolding R'_def by (intro rcset_to_rcset) blanchet@54539: thus ?R unfolding Grp_def relcompp.simps conversep.simps blanchet@55414: proof (intro CollectI case_prodI exI[of _ a] exI[of _ b] exI[of _ R'] conjI refl) blanchet@54539: from * `?L` show "a = cimage fst R'" by transfer (auto simp: image_def Collect_Int_Times) blanchet@54539: next blanchet@54539: from * `?L` show "b = cimage snd R'" by transfer (auto simp: image_def Collect_Int_Times) blanchet@54539: qed simp_all blanchet@54539: next blanchet@54539: assume ?R thus ?L unfolding Grp_def relcompp.simps conversep.simps blanchet@54539: by transfer force blanchet@54539: qed blanchet@54539: blanchet@54539: bnf "'a cset" blanchet@54539: map: cimage blanchet@54539: sets: rcset blanchet@54539: bd: natLeq blanchet@54539: wits: "cempty" blanchet@55934: rel: rel_cset blanchet@54539: proof - blanchet@54539: show "cimage id = id" by transfer' simp blanchet@54539: next blanchet@54539: fix f g show "cimage (g \ f) = cimage g \ cimage f" by transfer' fastforce blanchet@54539: next blanchet@54539: fix C f g assume eq: "\a. a \ rcset C \ f a = g a" blanchet@54539: thus "cimage f C = cimage g C" by transfer force blanchet@54539: next blanchet@54539: fix f show "rcset \ cimage f = op ` f \ rcset" by transfer' fastforce blanchet@54539: next blanchet@54539: show "card_order natLeq" by (rule natLeq_card_order) blanchet@54539: next blanchet@54539: show "cinfinite natLeq" by (rule natLeq_cinfinite) blanchet@54539: next blanchet@54539: fix C show "|rcset C| \o natLeq" by transfer (unfold countable_card_le_natLeq) blanchet@54539: next traytel@54841: fix R S blanchet@55934: show "rel_cset R OO rel_cset S \ rel_cset (R OO S)" blanchet@55934: unfolding rel_cset_def[abs_def] by fast blanchet@54539: next blanchet@54539: fix R blanchet@55934: show "rel_cset R = blanchet@54539: (Grp {x. rcset x \ Collect (split R)} (cimage fst))\\ OO blanchet@54539: Grp {x. rcset x \ Collect (split R)} (cimage snd)" blanchet@55934: unfolding rel_cset_def[abs_def] rel_cset_aux by simp blanchet@54539: qed (transfer, simp) blanchet@54539: blanchet@48975: end