| author | wenzelm | 
| Wed, 11 Sep 2024 20:05:09 +0200 | |
| changeset 80858 | a392351d1ed4 | 
| parent 80768 | c7723cc15de8 | 
| child 80914 | d97fdabd9e2b | 
| permissions | -rw-r--r-- | 
| 37653 | 1 | (* Title: HOL/Library/Cardinality.thy | 
| 48051 | 2 | Author: Brian Huffman, Andreas Lochbihler | 
| 24332 
e3a2b75b1cf9
boolean algebras as locales and numbers as types by Brian Huffman
 kleing parents: diff
changeset | 3 | *) | 
| 
e3a2b75b1cf9
boolean algebras as locales and numbers as types by Brian Huffman
 kleing parents: diff
changeset | 4 | |
| 60500 | 5 | section \<open>Cardinality of types\<close> | 
| 24332 
e3a2b75b1cf9
boolean algebras as locales and numbers as types by Brian Huffman
 kleing parents: diff
changeset | 6 | |
| 37653 | 7 | theory Cardinality | 
| 48164 
e97369f20c30
change card_UNIV from itself to phantom type to avoid unnecessary closures in generated code
 Andreas Lochbihler parents: 
48070diff
changeset | 8 | imports Phantom_Type | 
| 24332 
e3a2b75b1cf9
boolean algebras as locales and numbers as types by Brian Huffman
 kleing parents: diff
changeset | 9 | begin | 
| 
e3a2b75b1cf9
boolean algebras as locales and numbers as types by Brian Huffman
 kleing parents: diff
changeset | 10 | |
| 60500 | 11 | subsection \<open>Preliminary lemmas\<close> | 
| 24332 
e3a2b75b1cf9
boolean algebras as locales and numbers as types by Brian Huffman
 kleing parents: diff
changeset | 12 | (* These should be moved elsewhere *) | 
| 
e3a2b75b1cf9
boolean algebras as locales and numbers as types by Brian Huffman
 kleing parents: diff
changeset | 13 | |
| 
e3a2b75b1cf9
boolean algebras as locales and numbers as types by Brian Huffman
 kleing parents: diff
changeset | 14 | lemma (in type_definition) univ: | 
| 
e3a2b75b1cf9
boolean algebras as locales and numbers as types by Brian Huffman
 kleing parents: diff
changeset | 15 | "UNIV = Abs ` A" | 
| 
e3a2b75b1cf9
boolean algebras as locales and numbers as types by Brian Huffman
 kleing parents: diff
changeset | 16 | proof | 
| 
e3a2b75b1cf9
boolean algebras as locales and numbers as types by Brian Huffman
 kleing parents: diff
changeset | 17 | show "Abs ` A \<subseteq> UNIV" by (rule subset_UNIV) | 
| 
e3a2b75b1cf9
boolean algebras as locales and numbers as types by Brian Huffman
 kleing parents: diff
changeset | 18 | show "UNIV \<subseteq> Abs ` A" | 
| 
e3a2b75b1cf9
boolean algebras as locales and numbers as types by Brian Huffman
 kleing parents: diff
changeset | 19 | proof | 
| 
e3a2b75b1cf9
boolean algebras as locales and numbers as types by Brian Huffman
 kleing parents: diff
changeset | 20 | fix x :: 'b | 
| 
e3a2b75b1cf9
boolean algebras as locales and numbers as types by Brian Huffman
 kleing parents: diff
changeset | 21 | have "x = Abs (Rep x)" by (rule Rep_inverse [symmetric]) | 
| 
e3a2b75b1cf9
boolean algebras as locales and numbers as types by Brian Huffman
 kleing parents: diff
changeset | 22 | moreover have "Rep x \<in> A" by (rule Rep) | 
| 
e3a2b75b1cf9
boolean algebras as locales and numbers as types by Brian Huffman
 kleing parents: diff
changeset | 23 | ultimately show "x \<in> Abs ` A" by (rule image_eqI) | 
| 
e3a2b75b1cf9
boolean algebras as locales and numbers as types by Brian Huffman
 kleing parents: diff
changeset | 24 | qed | 
| 
e3a2b75b1cf9
boolean algebras as locales and numbers as types by Brian Huffman
 kleing parents: diff
changeset | 25 | qed | 
| 
e3a2b75b1cf9
boolean algebras as locales and numbers as types by Brian Huffman
 kleing parents: diff
changeset | 26 | |
| 
e3a2b75b1cf9
boolean algebras as locales and numbers as types by Brian Huffman
 kleing parents: diff
changeset | 27 | lemma (in type_definition) card: "card (UNIV :: 'b set) = card A" | 
| 
e3a2b75b1cf9
boolean algebras as locales and numbers as types by Brian Huffman
 kleing parents: diff
changeset | 28 | by (simp add: univ card_image inj_on_def Abs_inject) | 
| 
e3a2b75b1cf9
boolean algebras as locales and numbers as types by Brian Huffman
 kleing parents: diff
changeset | 29 | |
| 
e3a2b75b1cf9
boolean algebras as locales and numbers as types by Brian Huffman
 kleing parents: diff
changeset | 30 | |
| 60500 | 31 | subsection \<open>Cardinalities of types\<close> | 
| 24332 
e3a2b75b1cf9
boolean algebras as locales and numbers as types by Brian Huffman
 kleing parents: diff
changeset | 32 | |
| 
e3a2b75b1cf9
boolean algebras as locales and numbers as types by Brian Huffman
 kleing parents: diff
changeset | 33 | syntax "_type_card" :: "type => nat" ("(1CARD/(1'(_')))")
 | 
| 
e3a2b75b1cf9
boolean algebras as locales and numbers as types by Brian Huffman
 kleing parents: diff
changeset | 34 | |
| 80768 | 35 | syntax_consts "_type_card" == card | 
| 36 | ||
| 61076 | 37 | translations "CARD('t)" => "CONST card (CONST UNIV :: 't set)"
 | 
| 24332 
e3a2b75b1cf9
boolean algebras as locales and numbers as types by Brian Huffman
 kleing parents: diff
changeset | 38 | |
| 60500 | 39 | print_translation \<open> | 
| 42247 
12fe41a92cd5
typed_print_translation: discontinued show_sorts argument;
 wenzelm parents: 
42245diff
changeset | 40 | let | 
| 69593 | 41 | fun card_univ_tr' ctxt [Const (\<^const_syntax>\<open>UNIV\<close>, Type (_, [T]))] = | 
| 42 | Syntax.const \<^syntax_const>\<open>_type_card\<close> $ Syntax_Phases.term_of_typ ctxt T | |
| 43 | in [(\<^const_syntax>\<open>card\<close>, card_univ_tr')] end | |
| 60500 | 44 | \<close> | 
| 24407 | 45 | |
| 48058 | 46 | lemma card_prod [simp]: "CARD('a \<times> 'b) = CARD('a) * CARD('b)"
 | 
| 26153 | 47 | unfolding UNIV_Times_UNIV [symmetric] by (simp only: card_cartesian_product) | 
| 24332 
e3a2b75b1cf9
boolean algebras as locales and numbers as types by Brian Huffman
 kleing parents: diff
changeset | 48 | |
| 48060 | 49 | lemma card_UNIV_sum: "CARD('a + 'b) = (if CARD('a) \<noteq> 0 \<and> CARD('b) \<noteq> 0 then CARD('a) + CARD('b) else 0)"
 | 
| 50 | unfolding UNIV_Plus_UNIV[symmetric] | |
| 51 | by(auto simp add: card_eq_0_iff card_Plus simp del: UNIV_Plus_UNIV) | |
| 52 | ||
| 30001 | 53 | lemma card_sum [simp]: "CARD('a + 'b) = CARD('a::finite) + CARD('b::finite)"
 | 
| 48060 | 54 | by(simp add: card_UNIV_sum) | 
| 55 | ||
| 56 | lemma card_UNIV_option: "CARD('a option) = (if CARD('a) = 0 then 0 else CARD('a) + 1)"
 | |
| 57 | proof - | |
| 58 | have "(None :: 'a option) \<notin> range Some" by clarsimp | |
| 59 | thus ?thesis | |
| 53191 | 60 | by (simp add: UNIV_option_conv card_eq_0_iff finite_range_Some card_image) | 
| 48060 | 61 | qed | 
| 24332 
e3a2b75b1cf9
boolean algebras as locales and numbers as types by Brian Huffman
 kleing parents: diff
changeset | 62 | |
| 30001 | 63 | lemma card_option [simp]: "CARD('a option) = Suc CARD('a::finite)"
 | 
| 48060 | 64 | by(simp add: card_UNIV_option) | 
| 65 | ||
| 66 | lemma card_UNIV_set: "CARD('a set) = (if CARD('a) = 0 then 0 else 2 ^ CARD('a))"
 | |
| 68406 | 67 | by(simp add: card_eq_0_iff card_Pow flip: Pow_UNIV) | 
| 24332 
e3a2b75b1cf9
boolean algebras as locales and numbers as types by Brian Huffman
 kleing parents: diff
changeset | 68 | |
| 30001 | 69 | lemma card_set [simp]: "CARD('a set) = 2 ^ CARD('a::finite)"
 | 
| 48060 | 70 | by(simp add: card_UNIV_set) | 
| 24332 
e3a2b75b1cf9
boolean algebras as locales and numbers as types by Brian Huffman
 kleing parents: diff
changeset | 71 | |
| 30001 | 72 | lemma card_nat [simp]: "CARD(nat) = 0" | 
| 44142 | 73 | by (simp add: card_eq_0_iff) | 
| 30001 | 74 | |
| 48060 | 75 | lemma card_fun: "CARD('a \<Rightarrow> 'b) = (if CARD('a) \<noteq> 0 \<and> CARD('b) \<noteq> 0 \<or> CARD('b) = 1 then CARD('b) ^ CARD('a) else 0)"
 | 
| 76 | proof - | |
| 77 |   {  assume "0 < CARD('a)" and "0 < CARD('b)"
 | |
| 78 | hence fina: "finite (UNIV :: 'a set)" and finb: "finite (UNIV :: 'b set)" | |
| 79 | by(simp_all only: card_ge_0_finite) | |
| 80 | from finite_distinct_list[OF finb] obtain bs | |
| 81 | where bs: "set bs = (UNIV :: 'b set)" and distb: "distinct bs" by blast | |
| 82 | from finite_distinct_list[OF fina] obtain as | |
| 83 | where as: "set as = (UNIV :: 'a set)" and dista: "distinct as" by blast | |
| 84 |     have cb: "CARD('b) = length bs"
 | |
| 85 | unfolding bs[symmetric] distinct_card[OF distb] .. | |
| 86 |     have ca: "CARD('a) = length as"
 | |
| 87 | unfolding as[symmetric] distinct_card[OF dista] .. | |
| 67091 | 88 | let ?xs = "map (\<lambda>ys. the \<circ> map_of (zip as ys)) (List.n_lists (length as) bs)" | 
| 48060 | 89 | have "UNIV = set ?xs" | 
| 90 | proof(rule UNIV_eq_I) | |
| 91 | fix f :: "'a \<Rightarrow> 'b" | |
| 92 | from as have "f = the \<circ> map_of (zip as (map f as))" | |
| 93 | by(auto simp add: map_of_zip_map) | |
| 94 | thus "f \<in> set ?xs" using bs by(auto simp add: set_n_lists) | |
| 95 | qed | |
| 96 | moreover have "distinct ?xs" unfolding distinct_map | |
| 97 | proof(intro conjI distinct_n_lists distb inj_onI) | |
| 98 | fix xs ys :: "'b list" | |
| 49948 
744934b818c7
moved quite generic material from theory Enum to more appropriate places
 haftmann parents: 
49689diff
changeset | 99 | assume xs: "xs \<in> set (List.n_lists (length as) bs)" | 
| 
744934b818c7
moved quite generic material from theory Enum to more appropriate places
 haftmann parents: 
49689diff
changeset | 100 | and ys: "ys \<in> set (List.n_lists (length as) bs)" | 
| 48060 | 101 | and eq: "the \<circ> map_of (zip as xs) = the \<circ> map_of (zip as ys)" | 
| 102 | from xs ys have [simp]: "length xs = length as" "length ys = length as" | |
| 103 | by(simp_all add: length_n_lists_elem) | |
| 104 | have "map_of (zip as xs) = map_of (zip as ys)" | |
| 105 | proof | |
| 106 | fix x | |
| 107 | from as bs have "\<exists>y. map_of (zip as xs) x = Some y" "\<exists>y. map_of (zip as ys) x = Some y" | |
| 108 | by(simp_all add: map_of_zip_is_Some[symmetric]) | |
| 109 | with eq show "map_of (zip as xs) x = map_of (zip as ys) x" | |
| 110 | by(auto dest: fun_cong[where x=x]) | |
| 111 | qed | |
| 112 | with dista show "xs = ys" by(simp add: map_of_zip_inject) | |
| 113 | qed | |
| 114 | hence "card (set ?xs) = length ?xs" by(simp only: distinct_card) | |
| 115 | moreover have "length ?xs = length bs ^ length as" by(simp add: length_n_lists) | |
| 116 |     ultimately have "CARD('a \<Rightarrow> 'b) = CARD('b) ^ CARD('a)" using cb ca by simp }
 | |
| 117 |   moreover {
 | |
| 118 |     assume cb: "CARD('b) = 1"
 | |
| 119 |     then obtain b where b: "UNIV = {b :: 'b}" by(auto simp add: card_Suc_eq)
 | |
| 120 |     have eq: "UNIV = {\<lambda>x :: 'a. b ::'b}"
 | |
| 121 | proof(rule UNIV_eq_I) | |
| 122 | fix x :: "'a \<Rightarrow> 'b" | |
| 123 |       { fix y
 | |
| 124 | have "x y \<in> UNIV" .. | |
| 125 | hence "x y = b" unfolding b by simp } | |
| 126 |       thus "x \<in> {\<lambda>x. b}" by(auto)
 | |
| 127 | qed | |
| 128 |     have "CARD('a \<Rightarrow> 'b) = 1" unfolding eq by simp }
 | |
| 129 | ultimately show ?thesis | |
| 130 | by(auto simp del: One_nat_def)(auto simp add: card_eq_0_iff dest: finite_fun_UNIVD2 finite_fun_UNIVD1) | |
| 131 | qed | |
| 132 | ||
| 48176 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 133 | corollary finite_UNIV_fun: | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 134 |   "finite (UNIV :: ('a \<Rightarrow> 'b) set) \<longleftrightarrow>
 | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 135 |    finite (UNIV :: 'a set) \<and> finite (UNIV :: 'b set) \<or> CARD('b) = 1"
 | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 136 | (is "?lhs \<longleftrightarrow> ?rhs") | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 137 | proof - | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 138 |   have "?lhs \<longleftrightarrow> CARD('a \<Rightarrow> 'b) > 0" by(simp add: card_gt_0_iff)
 | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 139 |   also have "\<dots> \<longleftrightarrow> CARD('a) > 0 \<and> CARD('b) > 0 \<or> CARD('b) = 1"
 | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 140 | by(simp add: card_fun) | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 141 | also have "\<dots> = ?rhs" by(simp add: card_gt_0_iff) | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 142 | finally show ?thesis . | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 143 | qed | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 144 | |
| 48060 | 145 | lemma card_literal: "CARD(String.literal) = 0" | 
| 48176 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 146 | by(simp add: card_eq_0_iff infinite_literal) | 
| 30001 | 147 | |
| 60500 | 148 | subsection \<open>Classes with at least 1 and 2\<close> | 
| 30001 | 149 | |
| 60500 | 150 | text \<open>Class finite already captures "at least 1"\<close> | 
| 30001 | 151 | |
| 152 | lemma zero_less_card_finite [simp]: "0 < CARD('a::finite)"
 | |
| 29997 | 153 | unfolding neq0_conv [symmetric] by simp | 
| 154 | ||
| 30001 | 155 | lemma one_le_card_finite [simp]: "Suc 0 \<le> CARD('a::finite)"
 | 
| 156 | by (simp add: less_Suc_eq_le [symmetric]) | |
| 157 | ||
| 69663 | 158 | |
| 159 | class CARD_1 = | |
| 160 |   assumes CARD_1: "CARD ('a) = 1"
 | |
| 161 | begin | |
| 162 | ||
| 163 | subclass finite | |
| 164 | proof | |
| 165 | from CARD_1 show "finite (UNIV :: 'a set)" | |
| 71258 
d67924987c34
a few new and tidier proofs (mostly about finite sets)
 paulson <lp15@cam.ac.uk> parents: 
71174diff
changeset | 166 | using finite_UNIV_fun by fastforce | 
| 69663 | 167 | qed | 
| 168 | ||
| 169 | end | |
| 170 | ||
| 60500 | 171 | text \<open>Class for cardinality "at least 2"\<close> | 
| 30001 | 172 | |
| 173 | class card2 = finite + | |
| 174 |   assumes two_le_card: "2 \<le> CARD('a)"
 | |
| 175 | ||
| 176 | lemma one_less_card: "Suc 0 < CARD('a::card2)"
 | |
| 177 | using two_le_card [where 'a='a] by simp | |
| 178 | ||
| 179 | lemma one_less_int_card: "1 < int CARD('a::card2)"
 | |
| 180 | using one_less_card [where 'a='a] by simp | |
| 181 | ||
| 48176 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 182 | |
| 60500 | 183 | subsection \<open>A type class for deciding finiteness of types\<close> | 
| 48176 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 184 | |
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 185 | type_synonym 'a finite_UNIV = "('a, bool) phantom"
 | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 186 | |
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 187 | class finite_UNIV = | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 188 |   fixes finite_UNIV :: "('a, bool) phantom"
 | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 189 |   assumes finite_UNIV: "finite_UNIV = Phantom('a) (finite (UNIV :: 'a set))"
 | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 190 | |
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 191 | lemma finite_UNIV_code [code_unfold]: | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 192 | "finite (UNIV :: 'a :: finite_UNIV set) | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 193 | \<longleftrightarrow> of_phantom (finite_UNIV :: 'a finite_UNIV)" | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 194 | by(simp add: finite_UNIV) | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 195 | |
| 60500 | 196 | subsection \<open>A type class for computing the cardinality of types\<close> | 
| 48051 | 197 | |
| 48059 | 198 | definition is_list_UNIV :: "'a list \<Rightarrow> bool" | 
| 51116 
0dac0158b8d4
implement code generation for finite, card, op = and op <= for sets always via finite_UNIV and card_UNIV, as fragile rewrites based on sorts are hard to find and debug
 Andreas Lochbihler parents: 
49948diff
changeset | 199 | where "is_list_UNIV xs = (let c = CARD('a) in if c = 0 then False else size (remdups xs) = c)"
 | 
| 48059 | 200 | |
| 201 | lemma is_list_UNIV_iff: "is_list_UNIV xs \<longleftrightarrow> set xs = UNIV" | |
| 202 | by(auto simp add: is_list_UNIV_def Let_def card_eq_0_iff List.card_set[symmetric] | |
| 203 | dest: subst[where P="finite", OF _ finite_set] card_eq_UNIV_imp_eq_UNIV) | |
| 204 | ||
| 48164 
e97369f20c30
change card_UNIV from itself to phantom type to avoid unnecessary closures in generated code
 Andreas Lochbihler parents: 
48070diff
changeset | 205 | type_synonym 'a card_UNIV = "('a, nat) phantom"
 | 
| 
e97369f20c30
change card_UNIV from itself to phantom type to avoid unnecessary closures in generated code
 Andreas Lochbihler parents: 
48070diff
changeset | 206 | |
| 48176 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 207 | class card_UNIV = finite_UNIV + | 
| 48164 
e97369f20c30
change card_UNIV from itself to phantom type to avoid unnecessary closures in generated code
 Andreas Lochbihler parents: 
48070diff
changeset | 208 | fixes card_UNIV :: "'a card_UNIV" | 
| 
e97369f20c30
change card_UNIV from itself to phantom type to avoid unnecessary closures in generated code
 Andreas Lochbihler parents: 
48070diff
changeset | 209 |   assumes card_UNIV: "card_UNIV = Phantom('a) CARD('a)"
 | 
| 48051 | 210 | |
| 61585 | 211 | subsection \<open>Instantiations for \<open>card_UNIV\<close>\<close> | 
| 48051 | 212 | |
| 213 | instantiation nat :: card_UNIV begin | |
| 48176 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 214 | definition "finite_UNIV = Phantom(nat) False" | 
| 48164 
e97369f20c30
change card_UNIV from itself to phantom type to avoid unnecessary closures in generated code
 Andreas Lochbihler parents: 
48070diff
changeset | 215 | definition "card_UNIV = Phantom(nat) 0" | 
| 48176 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 216 | instance by intro_classes (simp_all add: finite_UNIV_nat_def card_UNIV_nat_def) | 
| 48051 | 217 | end | 
| 218 | ||
| 219 | instantiation int :: card_UNIV begin | |
| 48176 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 220 | definition "finite_UNIV = Phantom(int) False" | 
| 48164 
e97369f20c30
change card_UNIV from itself to phantom type to avoid unnecessary closures in generated code
 Andreas Lochbihler parents: 
48070diff
changeset | 221 | definition "card_UNIV = Phantom(int) 0" | 
| 71942 | 222 | instance by intro_classes (simp_all add: card_UNIV_int_def finite_UNIV_int_def) | 
| 48051 | 223 | end | 
| 224 | ||
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
51139diff
changeset | 225 | instantiation natural :: card_UNIV begin | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
51139diff
changeset | 226 | definition "finite_UNIV = Phantom(natural) False" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
51139diff
changeset | 227 | definition "card_UNIV = Phantom(natural) 0" | 
| 60679 | 228 | instance | 
| 229 | by standard | |
| 230 | (auto simp add: finite_UNIV_natural_def card_UNIV_natural_def card_eq_0_iff | |
| 231 | type_definition.univ [OF type_definition_natural] natural_eq_iff | |
| 232 | dest!: finite_imageD intro: inj_onI) | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
51139diff
changeset | 233 | end | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
51139diff
changeset | 234 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
51139diff
changeset | 235 | instantiation integer :: card_UNIV begin | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
51139diff
changeset | 236 | definition "finite_UNIV = Phantom(integer) False" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
51139diff
changeset | 237 | definition "card_UNIV = Phantom(integer) 0" | 
| 60679 | 238 | instance | 
| 239 | by standard | |
| 240 | (auto simp add: finite_UNIV_integer_def card_UNIV_integer_def card_eq_0_iff | |
| 71174 | 241 | type_definition.univ [OF type_definition_integer] | 
| 60679 | 242 | dest!: finite_imageD intro: inj_onI) | 
| 48165 
d07a0b9601aa
instantiate card_UNIV with nibble and code_numeral
 Andreas Lochbihler parents: 
48164diff
changeset | 243 | end | 
| 
d07a0b9601aa
instantiate card_UNIV with nibble and code_numeral
 Andreas Lochbihler parents: 
48164diff
changeset | 244 | |
| 48051 | 245 | instantiation list :: (type) card_UNIV begin | 
| 48176 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 246 | definition "finite_UNIV = Phantom('a list) False"
 | 
| 48164 
e97369f20c30
change card_UNIV from itself to phantom type to avoid unnecessary closures in generated code
 Andreas Lochbihler parents: 
48070diff
changeset | 247 | definition "card_UNIV = Phantom('a list) 0"
 | 
| 48176 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 248 | instance by intro_classes (simp_all add: card_UNIV_list_def finite_UNIV_list_def infinite_UNIV_listI) | 
| 48051 | 249 | end | 
| 250 | ||
| 251 | instantiation unit :: card_UNIV begin | |
| 48176 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 252 | definition "finite_UNIV = Phantom(unit) True" | 
| 48164 
e97369f20c30
change card_UNIV from itself to phantom type to avoid unnecessary closures in generated code
 Andreas Lochbihler parents: 
48070diff
changeset | 253 | definition "card_UNIV = Phantom(unit) 1" | 
| 48176 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 254 | instance by intro_classes (simp_all add: card_UNIV_unit_def finite_UNIV_unit_def) | 
| 48051 | 255 | end | 
| 256 | ||
| 257 | instantiation bool :: card_UNIV begin | |
| 48176 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 258 | definition "finite_UNIV = Phantom(bool) True" | 
| 48164 
e97369f20c30
change card_UNIV from itself to phantom type to avoid unnecessary closures in generated code
 Andreas Lochbihler parents: 
48070diff
changeset | 259 | definition "card_UNIV = Phantom(bool) 2" | 
| 48176 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 260 | instance by(intro_classes)(simp_all add: card_UNIV_bool_def finite_UNIV_bool_def) | 
| 48051 | 261 | end | 
| 262 | ||
| 263 | instantiation char :: card_UNIV begin | |
| 48176 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 264 | definition "finite_UNIV = Phantom(char) True" | 
| 48164 
e97369f20c30
change card_UNIV from itself to phantom type to avoid unnecessary closures in generated code
 Andreas Lochbihler parents: 
48070diff
changeset | 265 | definition "card_UNIV = Phantom(char) 256" | 
| 48176 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 266 | instance by intro_classes (simp_all add: card_UNIV_char_def card_UNIV_char finite_UNIV_char_def) | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 267 | end | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 268 | |
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 269 | instantiation prod :: (finite_UNIV, finite_UNIV) finite_UNIV begin | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 270 | definition "finite_UNIV = Phantom('a \<times> 'b) 
 | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 271 | (of_phantom (finite_UNIV :: 'a finite_UNIV) \<and> of_phantom (finite_UNIV :: 'b finite_UNIV))" | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 272 | instance by intro_classes (simp add: finite_UNIV_prod_def finite_UNIV finite_prod) | 
| 48051 | 273 | end | 
| 274 | ||
| 275 | instantiation prod :: (card_UNIV, card_UNIV) card_UNIV begin | |
| 48176 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 276 | definition "card_UNIV = Phantom('a \<times> 'b) 
 | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 277 | (of_phantom (card_UNIV :: 'a card_UNIV) * of_phantom (card_UNIV :: 'b card_UNIV))" | 
| 48060 | 278 | instance by intro_classes (simp add: card_UNIV_prod_def card_UNIV) | 
| 48051 | 279 | end | 
| 280 | ||
| 48176 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 281 | instantiation sum :: (finite_UNIV, finite_UNIV) finite_UNIV begin | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 282 | definition "finite_UNIV = Phantom('a + 'b)
 | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 283 | (of_phantom (finite_UNIV :: 'a finite_UNIV) \<and> of_phantom (finite_UNIV :: 'b finite_UNIV))" | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 284 | instance | 
| 68406 | 285 | by intro_classes (simp add: finite_UNIV_sum_def finite_UNIV) | 
| 48176 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 286 | end | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 287 | |
| 48051 | 288 | instantiation sum :: (card_UNIV, card_UNIV) card_UNIV begin | 
| 48164 
e97369f20c30
change card_UNIV from itself to phantom type to avoid unnecessary closures in generated code
 Andreas Lochbihler parents: 
48070diff
changeset | 289 | definition "card_UNIV = Phantom('a + 'b)
 | 
| 
e97369f20c30
change card_UNIV from itself to phantom type to avoid unnecessary closures in generated code
 Andreas Lochbihler parents: 
48070diff
changeset | 290 | (let ca = of_phantom (card_UNIV :: 'a card_UNIV); | 
| 
e97369f20c30
change card_UNIV from itself to phantom type to avoid unnecessary closures in generated code
 Andreas Lochbihler parents: 
48070diff
changeset | 291 | cb = of_phantom (card_UNIV :: 'b card_UNIV) | 
| 
e97369f20c30
change card_UNIV from itself to phantom type to avoid unnecessary closures in generated code
 Andreas Lochbihler parents: 
48070diff
changeset | 292 | in if ca \<noteq> 0 \<and> cb \<noteq> 0 then ca + cb else 0)" | 
| 48060 | 293 | instance by intro_classes (auto simp add: card_UNIV_sum_def card_UNIV card_UNIV_sum) | 
| 48051 | 294 | end | 
| 295 | ||
| 48176 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 296 | instantiation "fun" :: (finite_UNIV, card_UNIV) finite_UNIV begin | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 297 | definition "finite_UNIV = Phantom('a \<Rightarrow> 'b)
 | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 298 | (let cb = of_phantom (card_UNIV :: 'b card_UNIV) | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 299 | in cb = 1 \<or> of_phantom (finite_UNIV :: 'a finite_UNIV) \<and> cb \<noteq> 0)" | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 300 | instance | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 301 | by intro_classes (auto simp add: finite_UNIV_fun_def Let_def card_UNIV finite_UNIV finite_UNIV_fun card_gt_0_iff) | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 302 | end | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 303 | |
| 48051 | 304 | instantiation "fun" :: (card_UNIV, card_UNIV) card_UNIV begin | 
| 48164 
e97369f20c30
change card_UNIV from itself to phantom type to avoid unnecessary closures in generated code
 Andreas Lochbihler parents: 
48070diff
changeset | 305 | definition "card_UNIV = Phantom('a \<Rightarrow> 'b)
 | 
| 
e97369f20c30
change card_UNIV from itself to phantom type to avoid unnecessary closures in generated code
 Andreas Lochbihler parents: 
48070diff
changeset | 306 | (let ca = of_phantom (card_UNIV :: 'a card_UNIV); | 
| 
e97369f20c30
change card_UNIV from itself to phantom type to avoid unnecessary closures in generated code
 Andreas Lochbihler parents: 
48070diff
changeset | 307 | cb = of_phantom (card_UNIV :: 'b card_UNIV) | 
| 
e97369f20c30
change card_UNIV from itself to phantom type to avoid unnecessary closures in generated code
 Andreas Lochbihler parents: 
48070diff
changeset | 308 | in if ca \<noteq> 0 \<and> cb \<noteq> 0 \<or> cb = 1 then cb ^ ca else 0)" | 
| 48060 | 309 | instance by intro_classes (simp add: card_UNIV_fun_def card_UNIV Let_def card_fun) | 
| 310 | end | |
| 48051 | 311 | |
| 48176 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 312 | instantiation option :: (finite_UNIV) finite_UNIV begin | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 313 | definition "finite_UNIV = Phantom('a option) (of_phantom (finite_UNIV :: 'a finite_UNIV))"
 | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 314 | instance by intro_classes (simp add: finite_UNIV_option_def finite_UNIV) | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 315 | end | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 316 | |
| 48060 | 317 | instantiation option :: (card_UNIV) card_UNIV begin | 
| 48164 
e97369f20c30
change card_UNIV from itself to phantom type to avoid unnecessary closures in generated code
 Andreas Lochbihler parents: 
48070diff
changeset | 318 | definition "card_UNIV = Phantom('a option)
 | 
| 
e97369f20c30
change card_UNIV from itself to phantom type to avoid unnecessary closures in generated code
 Andreas Lochbihler parents: 
48070diff
changeset | 319 | (let c = of_phantom (card_UNIV :: 'a card_UNIV) in if c \<noteq> 0 then Suc c else 0)" | 
| 48060 | 320 | instance by intro_classes (simp add: card_UNIV_option_def card_UNIV card_UNIV_option) | 
| 321 | end | |
| 48051 | 322 | |
| 48060 | 323 | instantiation String.literal :: card_UNIV begin | 
| 48176 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 324 | definition "finite_UNIV = Phantom(String.literal) False" | 
| 48164 
e97369f20c30
change card_UNIV from itself to phantom type to avoid unnecessary closures in generated code
 Andreas Lochbihler parents: 
48070diff
changeset | 325 | definition "card_UNIV = Phantom(String.literal) 0" | 
| 48176 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 326 | instance | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 327 | by intro_classes (simp_all add: card_UNIV_literal_def finite_UNIV_literal_def infinite_literal card_literal) | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 328 | end | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 329 | |
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 330 | instantiation set :: (finite_UNIV) finite_UNIV begin | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 331 | definition "finite_UNIV = Phantom('a set) (of_phantom (finite_UNIV :: 'a finite_UNIV))"
 | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 332 | instance by intro_classes (simp add: finite_UNIV_set_def finite_UNIV Finite_Set.finite_set) | 
| 48060 | 333 | end | 
| 334 | ||
| 335 | instantiation set :: (card_UNIV) card_UNIV begin | |
| 48164 
e97369f20c30
change card_UNIV from itself to phantom type to avoid unnecessary closures in generated code
 Andreas Lochbihler parents: 
48070diff
changeset | 336 | definition "card_UNIV = Phantom('a set)
 | 
| 
e97369f20c30
change card_UNIV from itself to phantom type to avoid unnecessary closures in generated code
 Andreas Lochbihler parents: 
48070diff
changeset | 337 | (let c = of_phantom (card_UNIV :: 'a card_UNIV) in if c = 0 then 0 else 2 ^ c)" | 
| 48060 | 338 | instance by intro_classes (simp add: card_UNIV_set_def card_UNIV_set card_UNIV) | 
| 48051 | 339 | end | 
| 340 | ||
| 53015 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 wenzelm parents: 
52147diff
changeset | 341 | lemma UNIV_finite_1: "UNIV = set [finite_1.a\<^sub>1]" | 
| 48060 | 342 | by(auto intro: finite_1.exhaust) | 
| 343 | ||
| 53015 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 wenzelm parents: 
52147diff
changeset | 344 | lemma UNIV_finite_2: "UNIV = set [finite_2.a\<^sub>1, finite_2.a\<^sub>2]" | 
| 48060 | 345 | by(auto intro: finite_2.exhaust) | 
| 48051 | 346 | |
| 53015 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 wenzelm parents: 
52147diff
changeset | 347 | lemma UNIV_finite_3: "UNIV = set [finite_3.a\<^sub>1, finite_3.a\<^sub>2, finite_3.a\<^sub>3]" | 
| 48060 | 348 | by(auto intro: finite_3.exhaust) | 
| 48051 | 349 | |
| 53015 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 wenzelm parents: 
52147diff
changeset | 350 | lemma UNIV_finite_4: "UNIV = set [finite_4.a\<^sub>1, finite_4.a\<^sub>2, finite_4.a\<^sub>3, finite_4.a\<^sub>4]" | 
| 48060 | 351 | by(auto intro: finite_4.exhaust) | 
| 352 | ||
| 353 | lemma UNIV_finite_5: | |
| 53015 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 wenzelm parents: 
52147diff
changeset | 354 | "UNIV = set [finite_5.a\<^sub>1, finite_5.a\<^sub>2, finite_5.a\<^sub>3, finite_5.a\<^sub>4, finite_5.a\<^sub>5]" | 
| 48060 | 355 | by(auto intro: finite_5.exhaust) | 
| 48051 | 356 | |
| 48060 | 357 | instantiation Enum.finite_1 :: card_UNIV begin | 
| 48176 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 358 | definition "finite_UNIV = Phantom(Enum.finite_1) True" | 
| 48164 
e97369f20c30
change card_UNIV from itself to phantom type to avoid unnecessary closures in generated code
 Andreas Lochbihler parents: 
48070diff
changeset | 359 | definition "card_UNIV = Phantom(Enum.finite_1) 1" | 
| 48176 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 360 | instance | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 361 | by intro_classes (simp_all add: UNIV_finite_1 card_UNIV_finite_1_def finite_UNIV_finite_1_def) | 
| 48060 | 362 | end | 
| 363 | ||
| 364 | instantiation Enum.finite_2 :: card_UNIV begin | |
| 48176 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 365 | definition "finite_UNIV = Phantom(Enum.finite_2) True" | 
| 48164 
e97369f20c30
change card_UNIV from itself to phantom type to avoid unnecessary closures in generated code
 Andreas Lochbihler parents: 
48070diff
changeset | 366 | definition "card_UNIV = Phantom(Enum.finite_2) 2" | 
| 48176 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 367 | instance | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 368 | by intro_classes (simp_all add: UNIV_finite_2 card_UNIV_finite_2_def finite_UNIV_finite_2_def) | 
| 48060 | 369 | end | 
| 48051 | 370 | |
| 48060 | 371 | instantiation Enum.finite_3 :: card_UNIV begin | 
| 48176 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 372 | definition "finite_UNIV = Phantom(Enum.finite_3) True" | 
| 48164 
e97369f20c30
change card_UNIV from itself to phantom type to avoid unnecessary closures in generated code
 Andreas Lochbihler parents: 
48070diff
changeset | 373 | definition "card_UNIV = Phantom(Enum.finite_3) 3" | 
| 48176 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 374 | instance | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 375 | by intro_classes (simp_all add: UNIV_finite_3 card_UNIV_finite_3_def finite_UNIV_finite_3_def) | 
| 48060 | 376 | end | 
| 377 | ||
| 378 | instantiation Enum.finite_4 :: card_UNIV begin | |
| 48176 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 379 | definition "finite_UNIV = Phantom(Enum.finite_4) True" | 
| 48164 
e97369f20c30
change card_UNIV from itself to phantom type to avoid unnecessary closures in generated code
 Andreas Lochbihler parents: 
48070diff
changeset | 380 | definition "card_UNIV = Phantom(Enum.finite_4) 4" | 
| 48176 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 381 | instance | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 382 | by intro_classes (simp_all add: UNIV_finite_4 card_UNIV_finite_4_def finite_UNIV_finite_4_def) | 
| 48060 | 383 | end | 
| 384 | ||
| 385 | instantiation Enum.finite_5 :: card_UNIV begin | |
| 48176 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 386 | definition "finite_UNIV = Phantom(Enum.finite_5) True" | 
| 48164 
e97369f20c30
change card_UNIV from itself to phantom type to avoid unnecessary closures in generated code
 Andreas Lochbihler parents: 
48070diff
changeset | 387 | definition "card_UNIV = Phantom(Enum.finite_5) 5" | 
| 48176 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 388 | instance | 
| 
3d9c1ddb9f47
new type class for computing finiteness of types with instantiations
 Andreas Lochbihler parents: 
48165diff
changeset | 389 | by intro_classes (simp_all add: UNIV_finite_5 card_UNIV_finite_5_def finite_UNIV_finite_5_def) | 
| 48051 | 390 | end | 
| 391 | ||
| 61115 
3a4400985780
modernized name space management -- more uniform qualification;
 wenzelm parents: 
61076diff
changeset | 392 | end |