src/HOL/Library/Cardinality.thy
author wenzelm
Wed Apr 06 13:33:46 2011 +0200 (2011-04-06)
changeset 42247 12fe41a92cd5
parent 42245 29e3967550d5
child 44142 8e27e0177518
permissions -rw-r--r--
typed_print_translation: discontinued show_sorts argument;
     1 (*  Title:      HOL/Library/Cardinality.thy
     2     Author:     Brian Huffman
     3 *)
     4 
     5 header {* Cardinality of types *}
     6 
     7 theory Cardinality
     8 imports Main
     9 begin
    10 
    11 subsection {* Preliminary lemmas *}
    12 (* These should be moved elsewhere *)
    13 
    14 lemma (in type_definition) univ:
    15   "UNIV = Abs ` A"
    16 proof
    17   show "Abs ` A \<subseteq> UNIV" by (rule subset_UNIV)
    18   show "UNIV \<subseteq> Abs ` A"
    19   proof
    20     fix x :: 'b
    21     have "x = Abs (Rep x)" by (rule Rep_inverse [symmetric])
    22     moreover have "Rep x \<in> A" by (rule Rep)
    23     ultimately show "x \<in> Abs ` A" by (rule image_eqI)
    24   qed
    25 qed
    26 
    27 lemma (in type_definition) card: "card (UNIV :: 'b set) = card A"
    28   by (simp add: univ card_image inj_on_def Abs_inject)
    29 
    30 
    31 subsection {* Cardinalities of types *}
    32 
    33 syntax "_type_card" :: "type => nat" ("(1CARD/(1'(_')))")
    34 
    35 translations "CARD('t)" => "CONST card (CONST UNIV \<Colon> 't set)"
    36 
    37 typed_print_translation (advanced) {*
    38   let
    39     fun card_univ_tr' ctxt _ [Const (@{const_syntax UNIV}, Type (_, [T, _]))] =
    40       Syntax.const @{syntax_const "_type_card"} $ Syntax_Phases.term_of_typ ctxt T;
    41   in [(@{const_syntax card}, card_univ_tr')] end
    42 *}
    43 
    44 lemma card_unit [simp]: "CARD(unit) = 1"
    45   unfolding UNIV_unit by simp
    46 
    47 lemma card_prod [simp]: "CARD('a \<times> 'b) = CARD('a::finite) * CARD('b::finite)"
    48   unfolding UNIV_Times_UNIV [symmetric] by (simp only: card_cartesian_product)
    49 
    50 lemma card_sum [simp]: "CARD('a + 'b) = CARD('a::finite) + CARD('b::finite)"
    51   unfolding UNIV_Plus_UNIV [symmetric] by (simp only: finite card_Plus)
    52 
    53 lemma card_option [simp]: "CARD('a option) = Suc CARD('a::finite)"
    54   unfolding UNIV_option_conv
    55   apply (subgoal_tac "(None::'a option) \<notin> range Some")
    56   apply (simp add: card_image)
    57   apply fast
    58   done
    59 
    60 lemma card_set [simp]: "CARD('a set) = 2 ^ CARD('a::finite)"
    61   unfolding Pow_UNIV [symmetric]
    62   by (simp only: card_Pow finite numeral_2_eq_2)
    63 
    64 lemma card_nat [simp]: "CARD(nat) = 0"
    65   by (simp add: infinite_UNIV_nat card_eq_0_iff)
    66 
    67 
    68 subsection {* Classes with at least 1 and 2  *}
    69 
    70 text {* Class finite already captures "at least 1" *}
    71 
    72 lemma zero_less_card_finite [simp]: "0 < CARD('a::finite)"
    73   unfolding neq0_conv [symmetric] by simp
    74 
    75 lemma one_le_card_finite [simp]: "Suc 0 \<le> CARD('a::finite)"
    76   by (simp add: less_Suc_eq_le [symmetric])
    77 
    78 text {* Class for cardinality "at least 2" *}
    79 
    80 class card2 = finite + 
    81   assumes two_le_card: "2 \<le> CARD('a)"
    82 
    83 lemma one_less_card: "Suc 0 < CARD('a::card2)"
    84   using two_le_card [where 'a='a] by simp
    85 
    86 lemma one_less_int_card: "1 < int CARD('a::card2)"
    87   using one_less_card [where 'a='a] by simp
    88 
    89 end