src/HOL/Library/Enum.thy
author haftmann
Fri Jun 05 13:35:11 2009 +0200 (2009-06-05)
changeset 31464 b2aca38301c4
parent 31193 f8d4ac84334f
child 31482 7288382fd549
permissions -rw-r--r--
tuned proofs
haftmann@26348
     1
(*  Title:      HOL/Library/Enum.thy
haftmann@26348
     2
    Author:     Florian Haftmann, TU Muenchen
haftmann@26348
     3
*)
haftmann@26348
     4
haftmann@26348
     5
header {* Finite types as explicit enumerations *}
haftmann@26348
     6
haftmann@26348
     7
theory Enum
haftmann@30663
     8
imports Map Main
haftmann@26348
     9
begin
haftmann@26348
    10
haftmann@26348
    11
subsection {* Class @{text enum} *}
haftmann@26348
    12
haftmann@29797
    13
class enum =
haftmann@26348
    14
  fixes enum :: "'a list"
haftmann@28562
    15
  assumes UNIV_enum [code]: "UNIV = set enum"
haftmann@26444
    16
    and enum_distinct: "distinct enum"
haftmann@26348
    17
begin
haftmann@26348
    18
haftmann@29797
    19
subclass finite proof
haftmann@29797
    20
qed (simp add: UNIV_enum)
haftmann@26444
    21
haftmann@26444
    22
lemma enum_all: "set enum = UNIV" unfolding UNIV_enum ..
haftmann@26444
    23
haftmann@26348
    24
lemma in_enum [intro]: "x \<in> set enum"
haftmann@26348
    25
  unfolding enum_all by auto
haftmann@26348
    26
haftmann@26348
    27
lemma enum_eq_I:
haftmann@26348
    28
  assumes "\<And>x. x \<in> set xs"
haftmann@26348
    29
  shows "set enum = set xs"
haftmann@26348
    30
proof -
haftmann@26348
    31
  from assms UNIV_eq_I have "UNIV = set xs" by auto
haftmann@26348
    32
  with enum_all show ?thesis by simp
haftmann@26348
    33
qed
haftmann@26348
    34
haftmann@26348
    35
end
haftmann@26348
    36
haftmann@26348
    37
haftmann@26348
    38
subsection {* Equality and order on functions *}
haftmann@26348
    39
haftmann@26513
    40
instantiation "fun" :: (enum, eq) eq
haftmann@26513
    41
begin
haftmann@26348
    42
haftmann@26513
    43
definition
haftmann@26732
    44
  "eq_class.eq f g \<longleftrightarrow> (\<forall>x \<in> set enum. f x = g x)"
haftmann@26513
    45
haftmann@31464
    46
instance proof
haftmann@31464
    47
qed (simp_all add: eq_fun_def enum_all expand_fun_eq)
haftmann@26513
    48
haftmann@26513
    49
end
haftmann@26348
    50
haftmann@28562
    51
lemma order_fun [code]:
haftmann@26348
    52
  fixes f g :: "'a\<Colon>enum \<Rightarrow> 'b\<Colon>order"
haftmann@26968
    53
  shows "f \<le> g \<longleftrightarrow> list_all (\<lambda>x. f x \<le> g x) enum"
haftmann@26968
    54
    and "f < g \<longleftrightarrow> f \<le> g \<and> \<not> list_all (\<lambda>x. f x = g x) enum"
haftmann@28684
    55
  by (simp_all add: list_all_iff enum_all expand_fun_eq le_fun_def order_less_le)
haftmann@26968
    56
haftmann@26968
    57
haftmann@26968
    58
subsection {* Quantifiers *}
haftmann@26968
    59
haftmann@28562
    60
lemma all_code [code]: "(\<forall>x. P x) \<longleftrightarrow> list_all P enum"
haftmann@26968
    61
  by (simp add: list_all_iff enum_all)
haftmann@26968
    62
haftmann@28562
    63
lemma exists_code [code]: "(\<exists>x. P x) \<longleftrightarrow> \<not> list_all (Not o P) enum"
haftmann@26968
    64
  by (simp add: list_all_iff enum_all)
haftmann@26348
    65
haftmann@26348
    66
haftmann@26348
    67
subsection {* Default instances *}
haftmann@26348
    68
haftmann@26444
    69
primrec n_lists :: "nat \<Rightarrow> 'a list \<Rightarrow> 'a list list" where
haftmann@26444
    70
  "n_lists 0 xs = [[]]"
haftmann@26444
    71
  | "n_lists (Suc n) xs = concat (map (\<lambda>ys. map (\<lambda>y. y # ys) xs) (n_lists n xs))"
haftmann@26444
    72
haftmann@26444
    73
lemma n_lists_Nil [simp]: "n_lists n [] = (if n = 0 then [[]] else [])"
haftmann@26444
    74
  by (induct n) simp_all
haftmann@26444
    75
haftmann@26444
    76
lemma length_n_lists: "length (n_lists n xs) = length xs ^ n"
haftmann@26444
    77
  by (induct n) (auto simp add: length_concat map_compose [symmetric] o_def listsum_triv)
haftmann@26444
    78
haftmann@26444
    79
lemma length_n_lists_elem: "ys \<in> set (n_lists n xs) \<Longrightarrow> length ys = n"
haftmann@26444
    80
  by (induct n arbitrary: ys) auto
haftmann@26444
    81
haftmann@26444
    82
lemma set_n_lists: "set (n_lists n xs) = {ys. length ys = n \<and> set ys \<subseteq> set xs}"
haftmann@26444
    83
proof (rule set_ext)
haftmann@26444
    84
  fix ys :: "'a list"
haftmann@26444
    85
  show "ys \<in> set (n_lists n xs) \<longleftrightarrow> ys \<in> {ys. length ys = n \<and> set ys \<subseteq> set xs}"
haftmann@26444
    86
  proof -
haftmann@26444
    87
    have "ys \<in> set (n_lists n xs) \<Longrightarrow> length ys = n"
haftmann@26444
    88
      by (induct n arbitrary: ys) auto
haftmann@26444
    89
    moreover have "\<And>x. ys \<in> set (n_lists n xs) \<Longrightarrow> x \<in> set ys \<Longrightarrow> x \<in> set xs"
haftmann@26444
    90
      by (induct n arbitrary: ys) auto
haftmann@26444
    91
    moreover have "set ys \<subseteq> set xs \<Longrightarrow> ys \<in> set (n_lists (length ys) xs)"
haftmann@26444
    92
      by (induct ys) auto
haftmann@26444
    93
    ultimately show ?thesis by auto
haftmann@26444
    94
  qed
haftmann@26444
    95
qed
haftmann@26444
    96
haftmann@26444
    97
lemma distinct_n_lists:
haftmann@26444
    98
  assumes "distinct xs"
haftmann@26444
    99
  shows "distinct (n_lists n xs)"
haftmann@26444
   100
proof (rule card_distinct)
haftmann@26444
   101
  from assms have card_length: "card (set xs) = length xs" by (rule distinct_card)
haftmann@26444
   102
  have "card (set (n_lists n xs)) = card (set xs) ^ n"
haftmann@26444
   103
  proof (induct n)
haftmann@26444
   104
    case 0 then show ?case by simp
haftmann@26444
   105
  next
haftmann@26444
   106
    case (Suc n)
haftmann@26444
   107
    moreover have "card (\<Union>ys\<in>set (n_lists n xs). (\<lambda>y. y # ys) ` set xs)
haftmann@26444
   108
      = (\<Sum>ys\<in>set (n_lists n xs). card ((\<lambda>y. y # ys) ` set xs))"
haftmann@26444
   109
      by (rule card_UN_disjoint) auto
haftmann@26444
   110
    moreover have "\<And>ys. card ((\<lambda>y. y # ys) ` set xs) = card (set xs)"
haftmann@26444
   111
      by (rule card_image) (simp add: inj_on_def)
haftmann@26444
   112
    ultimately show ?case by auto
haftmann@26444
   113
  qed
haftmann@26444
   114
  also have "\<dots> = length xs ^ n" by (simp add: card_length)
haftmann@26444
   115
  finally show "card (set (n_lists n xs)) = length (n_lists n xs)"
haftmann@26444
   116
    by (simp add: length_n_lists)
haftmann@26444
   117
qed
haftmann@26444
   118
haftmann@31193
   119
lemma map_of_zip_map: (*FIXME move to Map.thy*)
haftmann@31193
   120
  "map_of (zip xs (map f xs)) = (\<lambda>x. if x \<in> set xs then Some (f x) else None)"
haftmann@26444
   121
  by (induct xs) (simp_all add: expand_fun_eq)
haftmann@26444
   122
haftmann@26444
   123
lemma map_of_zip_enum_is_Some:
haftmann@26444
   124
  assumes "length ys = length (enum \<Colon> 'a\<Colon>enum list)"
haftmann@26444
   125
  shows "\<exists>y. map_of (zip (enum \<Colon> 'a\<Colon>enum list) ys) x = Some y"
haftmann@26444
   126
proof -
haftmann@26444
   127
  from assms have "x \<in> set (enum \<Colon> 'a\<Colon>enum list) \<longleftrightarrow>
haftmann@26444
   128
    (\<exists>y. map_of (zip (enum \<Colon> 'a\<Colon>enum list) ys) x = Some y)"
haftmann@26444
   129
    by (auto intro!: map_of_zip_is_Some)
haftmann@26444
   130
  then show ?thesis using enum_all by auto
haftmann@26444
   131
qed
haftmann@26444
   132
haftmann@26444
   133
lemma map_of_zip_enum_inject:
haftmann@26444
   134
  fixes xs ys :: "'b\<Colon>enum list"
haftmann@26444
   135
  assumes length: "length xs = length (enum \<Colon> 'a\<Colon>enum list)"
haftmann@26444
   136
      "length ys = length (enum \<Colon> 'a\<Colon>enum list)"
haftmann@26444
   137
    and map_of: "the \<circ> map_of (zip (enum \<Colon> 'a\<Colon>enum list) xs) = the \<circ> map_of (zip (enum \<Colon> 'a\<Colon>enum list) ys)"
haftmann@26444
   138
  shows "xs = ys"
haftmann@26444
   139
proof -
haftmann@26444
   140
  have "map_of (zip (enum \<Colon> 'a list) xs) = map_of (zip (enum \<Colon> 'a list) ys)"
haftmann@26444
   141
  proof
haftmann@26444
   142
    fix x :: 'a
haftmann@26444
   143
    from length map_of_zip_enum_is_Some obtain y1 y2
haftmann@26444
   144
      where "map_of (zip (enum \<Colon> 'a list) xs) x = Some y1"
haftmann@26444
   145
        and "map_of (zip (enum \<Colon> 'a list) ys) x = Some y2" by blast
haftmann@26444
   146
    moreover from map_of have "the (map_of (zip (enum \<Colon> 'a\<Colon>enum list) xs) x) = the (map_of (zip (enum \<Colon> 'a\<Colon>enum list) ys) x)"
haftmann@26444
   147
      by (auto dest: fun_cong)
haftmann@26444
   148
    ultimately show "map_of (zip (enum \<Colon> 'a\<Colon>enum list) xs) x = map_of (zip (enum \<Colon> 'a\<Colon>enum list) ys) x"
haftmann@26444
   149
      by simp
haftmann@26444
   150
  qed
haftmann@26444
   151
  with length enum_distinct show "xs = ys" by (rule map_of_zip_inject)
haftmann@26444
   152
qed
haftmann@26444
   153
haftmann@26444
   154
instantiation "fun" :: (enum, enum) enum
haftmann@26444
   155
begin
haftmann@26444
   156
haftmann@26444
   157
definition
haftmann@28562
   158
  [code del]: "enum = map (\<lambda>ys. the o map_of (zip (enum\<Colon>'a list) ys)) (n_lists (length (enum\<Colon>'a\<Colon>enum list)) enum)"
haftmann@26444
   159
haftmann@26444
   160
instance proof
haftmann@26444
   161
  show "UNIV = set (enum \<Colon> ('a \<Rightarrow> 'b) list)"
haftmann@26444
   162
  proof (rule UNIV_eq_I)
haftmann@26444
   163
    fix f :: "'a \<Rightarrow> 'b"
haftmann@26444
   164
    have "f = the \<circ> map_of (zip (enum \<Colon> 'a\<Colon>enum list) (map f enum))"
haftmann@26444
   165
      by (auto simp add: map_of_zip_map expand_fun_eq)
haftmann@26444
   166
    then show "f \<in> set enum"
haftmann@26444
   167
      by (auto simp add: enum_fun_def set_n_lists)
haftmann@26444
   168
  qed
haftmann@26444
   169
next
haftmann@26444
   170
  from map_of_zip_enum_inject
haftmann@26444
   171
  show "distinct (enum \<Colon> ('a \<Rightarrow> 'b) list)"
haftmann@26444
   172
    by (auto intro!: inj_onI simp add: enum_fun_def
haftmann@26444
   173
      distinct_map distinct_n_lists enum_distinct set_n_lists enum_all)
haftmann@26444
   174
qed
haftmann@26444
   175
haftmann@26444
   176
end
haftmann@26444
   177
haftmann@28562
   178
lemma enum_fun_code [code]: "enum = (let enum_a = (enum \<Colon> 'a\<Colon>{enum, eq} list)
haftmann@28245
   179
  in map (\<lambda>ys. the o map_of (zip enum_a ys)) (n_lists (length enum_a) enum))"
haftmann@28245
   180
  by (simp add: enum_fun_def Let_def)
haftmann@26444
   181
haftmann@26348
   182
instantiation unit :: enum
haftmann@26348
   183
begin
haftmann@26348
   184
haftmann@26348
   185
definition
haftmann@26348
   186
  "enum = [()]"
haftmann@26348
   187
haftmann@31464
   188
instance proof
haftmann@31464
   189
qed (simp_all add: enum_unit_def UNIV_unit)
haftmann@26348
   190
haftmann@26348
   191
end
haftmann@26348
   192
haftmann@26348
   193
instantiation bool :: enum
haftmann@26348
   194
begin
haftmann@26348
   195
haftmann@26348
   196
definition
haftmann@26348
   197
  "enum = [False, True]"
haftmann@26348
   198
haftmann@31464
   199
instance proof
haftmann@31464
   200
qed (simp_all add: enum_bool_def UNIV_bool)
haftmann@26348
   201
haftmann@26348
   202
end
haftmann@26348
   203
haftmann@26348
   204
primrec product :: "'a list \<Rightarrow> 'b list \<Rightarrow> ('a \<times> 'b) list" where
haftmann@26348
   205
  "product [] _ = []"
haftmann@26348
   206
  | "product (x#xs) ys = map (Pair x) ys @ product xs ys"
haftmann@26348
   207
haftmann@26348
   208
lemma product_list_set:
haftmann@26348
   209
  "set (product xs ys) = set xs \<times> set ys"
haftmann@26348
   210
  by (induct xs) auto
haftmann@26348
   211
haftmann@26444
   212
lemma distinct_product:
haftmann@26444
   213
  assumes "distinct xs" and "distinct ys"
haftmann@26444
   214
  shows "distinct (product xs ys)"
haftmann@26444
   215
  using assms by (induct xs)
haftmann@26444
   216
    (auto intro: inj_onI simp add: product_list_set distinct_map)
haftmann@26444
   217
haftmann@26348
   218
instantiation * :: (enum, enum) enum
haftmann@26348
   219
begin
haftmann@26348
   220
haftmann@26348
   221
definition
haftmann@26348
   222
  "enum = product enum enum"
haftmann@26348
   223
haftmann@26348
   224
instance by default
haftmann@26444
   225
  (simp_all add: enum_prod_def product_list_set distinct_product enum_all enum_distinct)
haftmann@26348
   226
haftmann@26348
   227
end
haftmann@26348
   228
haftmann@26348
   229
instantiation "+" :: (enum, enum) enum
haftmann@26348
   230
begin
haftmann@26348
   231
haftmann@26348
   232
definition
haftmann@26348
   233
  "enum = map Inl enum @ map Inr enum"
haftmann@26348
   234
haftmann@26348
   235
instance by default
haftmann@26444
   236
  (auto simp add: enum_all enum_sum_def, case_tac x, auto intro: inj_onI simp add: distinct_map enum_distinct)
haftmann@26348
   237
haftmann@26348
   238
end
haftmann@26348
   239
haftmann@26348
   240
primrec sublists :: "'a list \<Rightarrow> 'a list list" where
haftmann@26348
   241
  "sublists [] = [[]]"
haftmann@26348
   242
  | "sublists (x#xs) = (let xss = sublists xs in map (Cons x) xss @ xss)"
haftmann@26348
   243
haftmann@26444
   244
lemma length_sublists:
haftmann@26444
   245
  "length (sublists xs) = Suc (Suc (0\<Colon>nat)) ^ length xs"
haftmann@26444
   246
  by (induct xs) (simp_all add: Let_def)
haftmann@26444
   247
haftmann@26348
   248
lemma sublists_powset:
haftmann@26444
   249
  "set ` set (sublists xs) = Pow (set xs)"
haftmann@26348
   250
proof -
haftmann@26348
   251
  have aux: "\<And>x A. set ` Cons x ` A = insert x ` set ` A"
haftmann@26348
   252
    by (auto simp add: image_def)
haftmann@26444
   253
  have "set (map set (sublists xs)) = Pow (set xs)"
haftmann@26348
   254
    by (induct xs)
haftmann@26444
   255
      (simp_all add: aux Let_def Pow_insert Un_commute)
haftmann@26444
   256
  then show ?thesis by simp
haftmann@26444
   257
qed
haftmann@26444
   258
haftmann@26444
   259
lemma distinct_set_sublists:
haftmann@26444
   260
  assumes "distinct xs"
haftmann@26444
   261
  shows "distinct (map set (sublists xs))"
haftmann@26444
   262
proof (rule card_distinct)
haftmann@26444
   263
  have "finite (set xs)" by rule
haftmann@26444
   264
  then have "card (Pow (set xs)) = Suc (Suc 0) ^ card (set xs)" by (rule card_Pow)
haftmann@26444
   265
  with assms distinct_card [of xs]
haftmann@26444
   266
    have "card (Pow (set xs)) = Suc (Suc 0) ^ length xs" by simp
haftmann@26444
   267
  then show "card (set (map set (sublists xs))) = length (map set (sublists xs))"
haftmann@26444
   268
    by (simp add: sublists_powset length_sublists)
haftmann@26348
   269
qed
haftmann@26348
   270
haftmann@26348
   271
instantiation nibble :: enum
haftmann@26348
   272
begin
haftmann@26348
   273
haftmann@26348
   274
definition
haftmann@26348
   275
  "enum = [Nibble0, Nibble1, Nibble2, Nibble3, Nibble4, Nibble5, Nibble6, Nibble7,
haftmann@26348
   276
    Nibble8, Nibble9, NibbleA, NibbleB, NibbleC, NibbleD, NibbleE, NibbleF]"
haftmann@26348
   277
haftmann@31464
   278
instance proof
haftmann@31464
   279
qed (simp_all add: enum_nibble_def UNIV_nibble)
haftmann@26348
   280
haftmann@26348
   281
end
haftmann@26348
   282
haftmann@26348
   283
instantiation char :: enum
haftmann@26348
   284
begin
haftmann@26348
   285
haftmann@26348
   286
definition
haftmann@28562
   287
  [code del]: "enum = map (split Char) (product enum enum)"
haftmann@26444
   288
haftmann@28562
   289
lemma enum_char [code]:
haftmann@26444
   290
  "enum = [Char Nibble0 Nibble0, Char Nibble0 Nibble1, Char Nibble0 Nibble2,
haftmann@26444
   291
  Char Nibble0 Nibble3, Char Nibble0 Nibble4, Char Nibble0 Nibble5,
haftmann@26444
   292
  Char Nibble0 Nibble6, Char Nibble0 Nibble7, Char Nibble0 Nibble8,
haftmann@26444
   293
  Char Nibble0 Nibble9, Char Nibble0 NibbleA, Char Nibble0 NibbleB,
haftmann@26444
   294
  Char Nibble0 NibbleC, Char Nibble0 NibbleD, Char Nibble0 NibbleE,
haftmann@26444
   295
  Char Nibble0 NibbleF, Char Nibble1 Nibble0, Char Nibble1 Nibble1,
haftmann@26444
   296
  Char Nibble1 Nibble2, Char Nibble1 Nibble3, Char Nibble1 Nibble4,
haftmann@26444
   297
  Char Nibble1 Nibble5, Char Nibble1 Nibble6, Char Nibble1 Nibble7,
haftmann@26444
   298
  Char Nibble1 Nibble8, Char Nibble1 Nibble9, Char Nibble1 NibbleA,
haftmann@26444
   299
  Char Nibble1 NibbleB, Char Nibble1 NibbleC, Char Nibble1 NibbleD,
haftmann@26444
   300
  Char Nibble1 NibbleE, Char Nibble1 NibbleF, CHR '' '', CHR ''!'',
haftmann@26444
   301
  Char Nibble2 Nibble2, CHR ''#'', CHR ''$'', CHR ''%'', CHR ''&'',
haftmann@26444
   302
  Char Nibble2 Nibble7, CHR ''('', CHR '')'', CHR ''*'', CHR ''+'', CHR '','',
haftmann@26444
   303
  CHR ''-'', CHR ''.'', CHR ''/'', CHR ''0'', CHR ''1'', CHR ''2'', CHR ''3'',
haftmann@26444
   304
  CHR ''4'', CHR ''5'', CHR ''6'', CHR ''7'', CHR ''8'', CHR ''9'', CHR '':'',
haftmann@26444
   305
  CHR '';'', CHR ''<'', CHR ''='', CHR ''>'', CHR ''?'', CHR ''@'', CHR ''A'',
haftmann@26444
   306
  CHR ''B'', CHR ''C'', CHR ''D'', CHR ''E'', CHR ''F'', CHR ''G'', CHR ''H'',
haftmann@26444
   307
  CHR ''I'', CHR ''J'', CHR ''K'', CHR ''L'', CHR ''M'', CHR ''N'', CHR ''O'',
haftmann@26444
   308
  CHR ''P'', CHR ''Q'', CHR ''R'', CHR ''S'', CHR ''T'', CHR ''U'', CHR ''V'',
haftmann@26444
   309
  CHR ''W'', CHR ''X'', CHR ''Y'', CHR ''Z'', CHR ''['', Char Nibble5 NibbleC,
haftmann@26444
   310
  CHR '']'', CHR ''^'', CHR ''_'', Char Nibble6 Nibble0, CHR ''a'', CHR ''b'',
haftmann@26444
   311
  CHR ''c'', CHR ''d'', CHR ''e'', CHR ''f'', CHR ''g'', CHR ''h'', CHR ''i'',
haftmann@26444
   312
  CHR ''j'', CHR ''k'', CHR ''l'', CHR ''m'', CHR ''n'', CHR ''o'', CHR ''p'',
haftmann@26444
   313
  CHR ''q'', CHR ''r'', CHR ''s'', CHR ''t'', CHR ''u'', CHR ''v'', CHR ''w'',
haftmann@26444
   314
  CHR ''x'', CHR ''y'', CHR ''z'', CHR ''{'', CHR ''|'', CHR ''}'', CHR ''~'',
haftmann@26444
   315
  Char Nibble7 NibbleF, Char Nibble8 Nibble0, Char Nibble8 Nibble1,
haftmann@26444
   316
  Char Nibble8 Nibble2, Char Nibble8 Nibble3, Char Nibble8 Nibble4,
haftmann@26444
   317
  Char Nibble8 Nibble5, Char Nibble8 Nibble6, Char Nibble8 Nibble7,
haftmann@26444
   318
  Char Nibble8 Nibble8, Char Nibble8 Nibble9, Char Nibble8 NibbleA,
haftmann@26444
   319
  Char Nibble8 NibbleB, Char Nibble8 NibbleC, Char Nibble8 NibbleD,
haftmann@26444
   320
  Char Nibble8 NibbleE, Char Nibble8 NibbleF, Char Nibble9 Nibble0,
haftmann@26444
   321
  Char Nibble9 Nibble1, Char Nibble9 Nibble2, Char Nibble9 Nibble3,
haftmann@26444
   322
  Char Nibble9 Nibble4, Char Nibble9 Nibble5, Char Nibble9 Nibble6,
haftmann@26444
   323
  Char Nibble9 Nibble7, Char Nibble9 Nibble8, Char Nibble9 Nibble9,
haftmann@26444
   324
  Char Nibble9 NibbleA, Char Nibble9 NibbleB, Char Nibble9 NibbleC,
haftmann@26444
   325
  Char Nibble9 NibbleD, Char Nibble9 NibbleE, Char Nibble9 NibbleF,
haftmann@26444
   326
  Char NibbleA Nibble0, Char NibbleA Nibble1, Char NibbleA Nibble2,
haftmann@26444
   327
  Char NibbleA Nibble3, Char NibbleA Nibble4, Char NibbleA Nibble5,
haftmann@26444
   328
  Char NibbleA Nibble6, Char NibbleA Nibble7, Char NibbleA Nibble8,
haftmann@26444
   329
  Char NibbleA Nibble9, Char NibbleA NibbleA, Char NibbleA NibbleB,
haftmann@26444
   330
  Char NibbleA NibbleC, Char NibbleA NibbleD, Char NibbleA NibbleE,
haftmann@26444
   331
  Char NibbleA NibbleF, Char NibbleB Nibble0, Char NibbleB Nibble1,
haftmann@26444
   332
  Char NibbleB Nibble2, Char NibbleB Nibble3, Char NibbleB Nibble4,
haftmann@26444
   333
  Char NibbleB Nibble5, Char NibbleB Nibble6, Char NibbleB Nibble7,
haftmann@26444
   334
  Char NibbleB Nibble8, Char NibbleB Nibble9, Char NibbleB NibbleA,
haftmann@26444
   335
  Char NibbleB NibbleB, Char NibbleB NibbleC, Char NibbleB NibbleD,
haftmann@26444
   336
  Char NibbleB NibbleE, Char NibbleB NibbleF, Char NibbleC Nibble0,
haftmann@26444
   337
  Char NibbleC Nibble1, Char NibbleC Nibble2, Char NibbleC Nibble3,
haftmann@26444
   338
  Char NibbleC Nibble4, Char NibbleC Nibble5, Char NibbleC Nibble6,
haftmann@26444
   339
  Char NibbleC Nibble7, Char NibbleC Nibble8, Char NibbleC Nibble9,
haftmann@26444
   340
  Char NibbleC NibbleA, Char NibbleC NibbleB, Char NibbleC NibbleC,
haftmann@26444
   341
  Char NibbleC NibbleD, Char NibbleC NibbleE, Char NibbleC NibbleF,
haftmann@26444
   342
  Char NibbleD Nibble0, Char NibbleD Nibble1, Char NibbleD Nibble2,
haftmann@26444
   343
  Char NibbleD Nibble3, Char NibbleD Nibble4, Char NibbleD Nibble5,
haftmann@26444
   344
  Char NibbleD Nibble6, Char NibbleD Nibble7, Char NibbleD Nibble8,
haftmann@26444
   345
  Char NibbleD Nibble9, Char NibbleD NibbleA, Char NibbleD NibbleB,
haftmann@26444
   346
  Char NibbleD NibbleC, Char NibbleD NibbleD, Char NibbleD NibbleE,
haftmann@26444
   347
  Char NibbleD NibbleF, Char NibbleE Nibble0, Char NibbleE Nibble1,
haftmann@26444
   348
  Char NibbleE Nibble2, Char NibbleE Nibble3, Char NibbleE Nibble4,
haftmann@26444
   349
  Char NibbleE Nibble5, Char NibbleE Nibble6, Char NibbleE Nibble7,
haftmann@26444
   350
  Char NibbleE Nibble8, Char NibbleE Nibble9, Char NibbleE NibbleA,
haftmann@26444
   351
  Char NibbleE NibbleB, Char NibbleE NibbleC, Char NibbleE NibbleD,
haftmann@26444
   352
  Char NibbleE NibbleE, Char NibbleE NibbleF, Char NibbleF Nibble0,
haftmann@26444
   353
  Char NibbleF Nibble1, Char NibbleF Nibble2, Char NibbleF Nibble3,
haftmann@26444
   354
  Char NibbleF Nibble4, Char NibbleF Nibble5, Char NibbleF Nibble6,
haftmann@26444
   355
  Char NibbleF Nibble7, Char NibbleF Nibble8, Char NibbleF Nibble9,
haftmann@26444
   356
  Char NibbleF NibbleA, Char NibbleF NibbleB, Char NibbleF NibbleC,
haftmann@26444
   357
  Char NibbleF NibbleD, Char NibbleF NibbleE, Char NibbleF NibbleF]"
haftmann@26444
   358
  unfolding enum_char_def enum_nibble_def by simp
haftmann@26348
   359
haftmann@31464
   360
instance proof
haftmann@31464
   361
qed (auto intro: char.exhaust injI simp add: enum_char_def product_list_set enum_all full_SetCompr_eq [symmetric]
haftmann@31464
   362
  distinct_map distinct_product enum_distinct)
haftmann@26348
   363
haftmann@26348
   364
end
haftmann@26348
   365
huffman@29024
   366
instantiation option :: (enum) enum
huffman@29024
   367
begin
huffman@29024
   368
huffman@29024
   369
definition
huffman@29024
   370
  "enum = None # map Some enum"
huffman@29024
   371
haftmann@31464
   372
instance proof
haftmann@31464
   373
qed (auto simp add: enum_all enum_option_def, rule option.exhaust, auto intro: simp add: distinct_map enum_distinct)
huffman@29024
   374
huffman@29024
   375
end
huffman@29024
   376
huffman@29024
   377
end