src/HOL/Library/Cardinality.thy
 author huffman Sun Mar 25 20:15:39 2012 +0200 (2012-03-25) changeset 47108 2a1953f0d20d parent 44142 8e27e0177518 child 47221 7205eb4a0a05 permissions -rw-r--r--
merged fork with new numeral representation (see NEWS)
```     1 (*  Title:      HOL/Library/Cardinality.thy
```
```     2     Author:     Brian Huffman
```
```     3 *)
```
```     4
```
```     5 header {* Cardinality of types *}
```
```     6
```
```     7 theory Cardinality
```
```     8 imports "~~/src/HOL/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: 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
```