src/HOL/Library/Cardinality.thy
 author haftmann Fri Aug 27 19:34:23 2010 +0200 (2010-08-27 ago) changeset 38857 97775f3e8722 parent 37653 847e95ca9b0a child 42245 29e3967550d5 permissions -rw-r--r--
renamed class/constant eq to equal; tuned some instantiations
```     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 {*
```
```    38 let
```
```    39   fun card_univ_tr' show_sorts _ [Const (@{const_syntax UNIV}, Type(_, [T, _]))] =
```
```    40     Syntax.const @{syntax_const "_type_card"} \$ Syntax.term_of_typ show_sorts T;
```
```    41 in [(@{const_syntax card}, card_univ_tr')]
```
```    42 end
```
```    43 *}
```
```    44
```
```    45 lemma card_unit [simp]: "CARD(unit) = 1"
```
```    46   unfolding UNIV_unit by simp
```
```    47
```
```    48 lemma card_prod [simp]: "CARD('a \<times> 'b) = CARD('a::finite) * CARD('b::finite)"
```
```    49   unfolding UNIV_Times_UNIV [symmetric] by (simp only: card_cartesian_product)
```
```    50
```
```    51 lemma card_sum [simp]: "CARD('a + 'b) = CARD('a::finite) + CARD('b::finite)"
```
```    52   unfolding UNIV_Plus_UNIV [symmetric] by (simp only: finite card_Plus)
```
```    53
```
```    54 lemma card_option [simp]: "CARD('a option) = Suc CARD('a::finite)"
```
```    55   unfolding UNIV_option_conv
```
```    56   apply (subgoal_tac "(None::'a option) \<notin> range Some")
```
```    57   apply (simp add: card_image)
```
```    58   apply fast
```
```    59   done
```
```    60
```
```    61 lemma card_set [simp]: "CARD('a set) = 2 ^ CARD('a::finite)"
```
```    62   unfolding Pow_UNIV [symmetric]
```
```    63   by (simp only: card_Pow finite numeral_2_eq_2)
```
```    64
```
```    65 lemma card_nat [simp]: "CARD(nat) = 0"
```
```    66   by (simp add: infinite_UNIV_nat card_eq_0_iff)
```
```    67
```
```    68
```
```    69 subsection {* Classes with at least 1 and 2  *}
```
```    70
```
```    71 text {* Class finite already captures "at least 1" *}
```
```    72
```
```    73 lemma zero_less_card_finite [simp]: "0 < CARD('a::finite)"
```
```    74   unfolding neq0_conv [symmetric] by simp
```
```    75
```
```    76 lemma one_le_card_finite [simp]: "Suc 0 \<le> CARD('a::finite)"
```
```    77   by (simp add: less_Suc_eq_le [symmetric])
```
```    78
```
```    79 text {* Class for cardinality "at least 2" *}
```
```    80
```
```    81 class card2 = finite +
```
```    82   assumes two_le_card: "2 \<le> CARD('a)"
```
```    83
```
```    84 lemma one_less_card: "Suc 0 < CARD('a::card2)"
```
```    85   using two_le_card [where 'a='a] by simp
```
```    86
```
```    87 lemma one_less_int_card: "1 < int CARD('a::card2)"
```
```    88   using one_less_card [where 'a='a] by simp
```
```    89
```
```    90 end
```