src/HOL/Enum.thy
author bulwahn
Mon Nov 22 11:34:57 2010 +0100 (2010-11-22)
changeset 40651 9752ba7348b5
parent 40650 d40b347d5b0b
child 40652 7bdfc1d6b143
permissions -rw-r--r--
adding code equation for function equality; adding some instantiations for the finite types
haftmann@31596
     1
(* Author: Florian Haftmann, TU Muenchen *)
haftmann@26348
     2
haftmann@26348
     3
header {* Finite types as explicit enumerations *}
haftmann@26348
     4
haftmann@26348
     5
theory Enum
bulwahn@40650
     6
imports Map String
haftmann@26348
     7
begin
haftmann@26348
     8
haftmann@26348
     9
subsection {* Class @{text enum} *}
haftmann@26348
    10
haftmann@29797
    11
class enum =
haftmann@26348
    12
  fixes enum :: "'a list"
haftmann@33635
    13
  assumes UNIV_enum: "UNIV = set enum"
haftmann@26444
    14
    and enum_distinct: "distinct enum"
haftmann@26348
    15
begin
haftmann@26348
    16
haftmann@29797
    17
subclass finite proof
haftmann@29797
    18
qed (simp add: UNIV_enum)
haftmann@26444
    19
haftmann@26444
    20
lemma enum_all: "set enum = UNIV" unfolding UNIV_enum ..
haftmann@26444
    21
haftmann@26348
    22
lemma in_enum [intro]: "x \<in> set enum"
haftmann@26348
    23
  unfolding enum_all by auto
haftmann@26348
    24
haftmann@26348
    25
lemma enum_eq_I:
haftmann@26348
    26
  assumes "\<And>x. x \<in> set xs"
haftmann@26348
    27
  shows "set enum = set xs"
haftmann@26348
    28
proof -
haftmann@26348
    29
  from assms UNIV_eq_I have "UNIV = set xs" by auto
haftmann@26348
    30
  with enum_all show ?thesis by simp
haftmann@26348
    31
qed
haftmann@26348
    32
haftmann@26348
    33
end
haftmann@26348
    34
haftmann@26348
    35
haftmann@26348
    36
subsection {* Equality and order on functions *}
haftmann@26348
    37
haftmann@38857
    38
instantiation "fun" :: (enum, equal) equal
haftmann@26513
    39
begin
haftmann@26348
    40
haftmann@26513
    41
definition
haftmann@38857
    42
  "HOL.equal f g \<longleftrightarrow> (\<forall>x \<in> set enum. f x = g x)"
haftmann@26513
    43
haftmann@31464
    44
instance proof
nipkow@39302
    45
qed (simp_all add: equal_fun_def enum_all fun_eq_iff)
haftmann@26513
    46
haftmann@26513
    47
end
haftmann@26348
    48
haftmann@38857
    49
lemma [code nbe]:
haftmann@38857
    50
  "HOL.equal (f :: _ \<Rightarrow> _) f \<longleftrightarrow> True"
haftmann@38857
    51
  by (fact equal_refl)
haftmann@38857
    52
bulwahn@40651
    53
lemma [code]:
bulwahn@40651
    54
  "HOL.equal f g \<longleftrightarrow>  list_all (%x. f x = g x) enum"
bulwahn@40651
    55
by (auto simp add: list_all_iff enum_all equal fun_eq_iff)
bulwahn@40651
    56
haftmann@28562
    57
lemma order_fun [code]:
haftmann@26348
    58
  fixes f g :: "'a\<Colon>enum \<Rightarrow> 'b\<Colon>order"
haftmann@26968
    59
  shows "f \<le> g \<longleftrightarrow> list_all (\<lambda>x. f x \<le> g x) enum"
haftmann@37601
    60
    and "f < g \<longleftrightarrow> f \<le> g \<and> list_ex (\<lambda>x. f x \<noteq> g x) enum"
nipkow@39302
    61
  by (simp_all add: list_all_iff list_ex_iff enum_all fun_eq_iff le_fun_def order_less_le)
haftmann@26968
    62
haftmann@26968
    63
haftmann@26968
    64
subsection {* Quantifiers *}
haftmann@26968
    65
haftmann@28562
    66
lemma all_code [code]: "(\<forall>x. P x) \<longleftrightarrow> list_all P enum"
haftmann@26968
    67
  by (simp add: list_all_iff enum_all)
haftmann@26968
    68
haftmann@37601
    69
lemma exists_code [code]: "(\<exists>x. P x) \<longleftrightarrow> list_ex P enum"
haftmann@37601
    70
  by (simp add: list_ex_iff enum_all)
haftmann@26348
    71
haftmann@26348
    72
haftmann@26348
    73
subsection {* Default instances *}
haftmann@26348
    74
haftmann@26444
    75
primrec n_lists :: "nat \<Rightarrow> 'a list \<Rightarrow> 'a list list" where
haftmann@26444
    76
  "n_lists 0 xs = [[]]"
haftmann@26444
    77
  | "n_lists (Suc n) xs = concat (map (\<lambda>ys. map (\<lambda>y. y # ys) xs) (n_lists n xs))"
haftmann@26444
    78
haftmann@26444
    79
lemma n_lists_Nil [simp]: "n_lists n [] = (if n = 0 then [[]] else [])"
haftmann@26444
    80
  by (induct n) simp_all
haftmann@26444
    81
haftmann@26444
    82
lemma length_n_lists: "length (n_lists n xs) = length xs ^ n"
hoelzl@33639
    83
  by (induct n) (auto simp add: length_concat o_def listsum_triv)
haftmann@26444
    84
haftmann@26444
    85
lemma length_n_lists_elem: "ys \<in> set (n_lists n xs) \<Longrightarrow> length ys = n"
haftmann@26444
    86
  by (induct n arbitrary: ys) auto
haftmann@26444
    87
haftmann@26444
    88
lemma set_n_lists: "set (n_lists n xs) = {ys. length ys = n \<and> set ys \<subseteq> set xs}"
nipkow@39302
    89
proof (rule set_eqI)
haftmann@26444
    90
  fix ys :: "'a list"
haftmann@26444
    91
  show "ys \<in> set (n_lists n xs) \<longleftrightarrow> ys \<in> {ys. length ys = n \<and> set ys \<subseteq> set xs}"
haftmann@26444
    92
  proof -
haftmann@26444
    93
    have "ys \<in> set (n_lists n xs) \<Longrightarrow> length ys = n"
haftmann@26444
    94
      by (induct n arbitrary: ys) auto
haftmann@26444
    95
    moreover have "\<And>x. ys \<in> set (n_lists n xs) \<Longrightarrow> x \<in> set ys \<Longrightarrow> x \<in> set xs"
haftmann@26444
    96
      by (induct n arbitrary: ys) auto
haftmann@26444
    97
    moreover have "set ys \<subseteq> set xs \<Longrightarrow> ys \<in> set (n_lists (length ys) xs)"
haftmann@26444
    98
      by (induct ys) auto
haftmann@26444
    99
    ultimately show ?thesis by auto
haftmann@26444
   100
  qed
haftmann@26444
   101
qed
haftmann@26444
   102
haftmann@26444
   103
lemma distinct_n_lists:
haftmann@26444
   104
  assumes "distinct xs"
haftmann@26444
   105
  shows "distinct (n_lists n xs)"
haftmann@26444
   106
proof (rule card_distinct)
haftmann@26444
   107
  from assms have card_length: "card (set xs) = length xs" by (rule distinct_card)
haftmann@26444
   108
  have "card (set (n_lists n xs)) = card (set xs) ^ n"
haftmann@26444
   109
  proof (induct n)
haftmann@26444
   110
    case 0 then show ?case by simp
haftmann@26444
   111
  next
haftmann@26444
   112
    case (Suc n)
haftmann@26444
   113
    moreover have "card (\<Union>ys\<in>set (n_lists n xs). (\<lambda>y. y # ys) ` set xs)
haftmann@26444
   114
      = (\<Sum>ys\<in>set (n_lists n xs). card ((\<lambda>y. y # ys) ` set xs))"
haftmann@26444
   115
      by (rule card_UN_disjoint) auto
haftmann@26444
   116
    moreover have "\<And>ys. card ((\<lambda>y. y # ys) ` set xs) = card (set xs)"
haftmann@26444
   117
      by (rule card_image) (simp add: inj_on_def)
haftmann@26444
   118
    ultimately show ?case by auto
haftmann@26444
   119
  qed
haftmann@26444
   120
  also have "\<dots> = length xs ^ n" by (simp add: card_length)
haftmann@26444
   121
  finally show "card (set (n_lists n xs)) = length (n_lists n xs)"
haftmann@26444
   122
    by (simp add: length_n_lists)
haftmann@26444
   123
qed
haftmann@26444
   124
haftmann@26444
   125
lemma map_of_zip_enum_is_Some:
haftmann@26444
   126
  assumes "length ys = length (enum \<Colon> 'a\<Colon>enum list)"
haftmann@26444
   127
  shows "\<exists>y. map_of (zip (enum \<Colon> 'a\<Colon>enum list) ys) x = Some y"
haftmann@26444
   128
proof -
haftmann@26444
   129
  from assms have "x \<in> set (enum \<Colon> 'a\<Colon>enum list) \<longleftrightarrow>
haftmann@26444
   130
    (\<exists>y. map_of (zip (enum \<Colon> 'a\<Colon>enum list) ys) x = Some y)"
haftmann@26444
   131
    by (auto intro!: map_of_zip_is_Some)
haftmann@26444
   132
  then show ?thesis using enum_all by auto
haftmann@26444
   133
qed
haftmann@26444
   134
haftmann@26444
   135
lemma map_of_zip_enum_inject:
haftmann@26444
   136
  fixes xs ys :: "'b\<Colon>enum list"
haftmann@26444
   137
  assumes length: "length xs = length (enum \<Colon> 'a\<Colon>enum list)"
haftmann@26444
   138
      "length ys = length (enum \<Colon> 'a\<Colon>enum list)"
haftmann@26444
   139
    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
   140
  shows "xs = ys"
haftmann@26444
   141
proof -
haftmann@26444
   142
  have "map_of (zip (enum \<Colon> 'a list) xs) = map_of (zip (enum \<Colon> 'a list) ys)"
haftmann@26444
   143
  proof
haftmann@26444
   144
    fix x :: 'a
haftmann@26444
   145
    from length map_of_zip_enum_is_Some obtain y1 y2
haftmann@26444
   146
      where "map_of (zip (enum \<Colon> 'a list) xs) x = Some y1"
haftmann@26444
   147
        and "map_of (zip (enum \<Colon> 'a list) ys) x = Some y2" by blast
haftmann@26444
   148
    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
   149
      by (auto dest: fun_cong)
haftmann@26444
   150
    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
   151
      by simp
haftmann@26444
   152
  qed
haftmann@26444
   153
  with length enum_distinct show "xs = ys" by (rule map_of_zip_inject)
haftmann@26444
   154
qed
haftmann@26444
   155
haftmann@26444
   156
instantiation "fun" :: (enum, enum) enum
haftmann@26444
   157
begin
haftmann@26444
   158
haftmann@26444
   159
definition
haftmann@37765
   160
  "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
   161
haftmann@26444
   162
instance proof
haftmann@26444
   163
  show "UNIV = set (enum \<Colon> ('a \<Rightarrow> 'b) list)"
haftmann@26444
   164
  proof (rule UNIV_eq_I)
haftmann@26444
   165
    fix f :: "'a \<Rightarrow> 'b"
haftmann@26444
   166
    have "f = the \<circ> map_of (zip (enum \<Colon> 'a\<Colon>enum list) (map f enum))"
nipkow@39302
   167
      by (auto simp add: map_of_zip_map fun_eq_iff)
haftmann@26444
   168
    then show "f \<in> set enum"
haftmann@26444
   169
      by (auto simp add: enum_fun_def set_n_lists)
haftmann@26444
   170
  qed
haftmann@26444
   171
next
haftmann@26444
   172
  from map_of_zip_enum_inject
haftmann@26444
   173
  show "distinct (enum \<Colon> ('a \<Rightarrow> 'b) list)"
haftmann@26444
   174
    by (auto intro!: inj_onI simp add: enum_fun_def
haftmann@26444
   175
      distinct_map distinct_n_lists enum_distinct set_n_lists enum_all)
haftmann@26444
   176
qed
haftmann@26444
   177
haftmann@26444
   178
end
haftmann@26444
   179
haftmann@38857
   180
lemma enum_fun_code [code]: "enum = (let enum_a = (enum \<Colon> 'a\<Colon>{enum, equal} list)
haftmann@28245
   181
  in map (\<lambda>ys. the o map_of (zip enum_a ys)) (n_lists (length enum_a) enum))"
haftmann@28245
   182
  by (simp add: enum_fun_def Let_def)
haftmann@26444
   183
haftmann@26348
   184
instantiation unit :: enum
haftmann@26348
   185
begin
haftmann@26348
   186
haftmann@26348
   187
definition
haftmann@26348
   188
  "enum = [()]"
haftmann@26348
   189
haftmann@31464
   190
instance proof
haftmann@31464
   191
qed (simp_all add: enum_unit_def UNIV_unit)
haftmann@26348
   192
haftmann@26348
   193
end
haftmann@26348
   194
haftmann@26348
   195
instantiation bool :: enum
haftmann@26348
   196
begin
haftmann@26348
   197
haftmann@26348
   198
definition
haftmann@26348
   199
  "enum = [False, True]"
haftmann@26348
   200
haftmann@31464
   201
instance proof
haftmann@31464
   202
qed (simp_all add: enum_bool_def UNIV_bool)
haftmann@26348
   203
haftmann@26348
   204
end
haftmann@26348
   205
haftmann@26348
   206
primrec product :: "'a list \<Rightarrow> 'b list \<Rightarrow> ('a \<times> 'b) list" where
haftmann@26348
   207
  "product [] _ = []"
haftmann@26348
   208
  | "product (x#xs) ys = map (Pair x) ys @ product xs ys"
haftmann@26348
   209
haftmann@26348
   210
lemma product_list_set:
haftmann@26348
   211
  "set (product xs ys) = set xs \<times> set ys"
haftmann@26348
   212
  by (induct xs) auto
haftmann@26348
   213
haftmann@26444
   214
lemma distinct_product:
haftmann@26444
   215
  assumes "distinct xs" and "distinct ys"
haftmann@26444
   216
  shows "distinct (product xs ys)"
haftmann@26444
   217
  using assms by (induct xs)
haftmann@26444
   218
    (auto intro: inj_onI simp add: product_list_set distinct_map)
haftmann@26444
   219
haftmann@37678
   220
instantiation prod :: (enum, enum) enum
haftmann@26348
   221
begin
haftmann@26348
   222
haftmann@26348
   223
definition
haftmann@26348
   224
  "enum = product enum enum"
haftmann@26348
   225
haftmann@26348
   226
instance by default
haftmann@26444
   227
  (simp_all add: enum_prod_def product_list_set distinct_product enum_all enum_distinct)
haftmann@26348
   228
haftmann@26348
   229
end
haftmann@26348
   230
haftmann@37678
   231
instantiation sum :: (enum, enum) enum
haftmann@26348
   232
begin
haftmann@26348
   233
haftmann@26348
   234
definition
haftmann@26348
   235
  "enum = map Inl enum @ map Inr enum"
haftmann@26348
   236
haftmann@26348
   237
instance by default
haftmann@26444
   238
  (auto simp add: enum_all enum_sum_def, case_tac x, auto intro: inj_onI simp add: distinct_map enum_distinct)
haftmann@26348
   239
haftmann@26348
   240
end
haftmann@26348
   241
haftmann@26348
   242
primrec sublists :: "'a list \<Rightarrow> 'a list list" where
haftmann@26348
   243
  "sublists [] = [[]]"
haftmann@26348
   244
  | "sublists (x#xs) = (let xss = sublists xs in map (Cons x) xss @ xss)"
haftmann@26348
   245
haftmann@26444
   246
lemma length_sublists:
haftmann@26444
   247
  "length (sublists xs) = Suc (Suc (0\<Colon>nat)) ^ length xs"
haftmann@26444
   248
  by (induct xs) (simp_all add: Let_def)
haftmann@26444
   249
haftmann@26348
   250
lemma sublists_powset:
haftmann@26444
   251
  "set ` set (sublists xs) = Pow (set xs)"
haftmann@26348
   252
proof -
haftmann@26348
   253
  have aux: "\<And>x A. set ` Cons x ` A = insert x ` set ` A"
haftmann@26348
   254
    by (auto simp add: image_def)
haftmann@26444
   255
  have "set (map set (sublists xs)) = Pow (set xs)"
haftmann@26348
   256
    by (induct xs)
hoelzl@33639
   257
      (simp_all add: aux Let_def Pow_insert Un_commute comp_def del: map_map)
haftmann@26444
   258
  then show ?thesis by simp
haftmann@26444
   259
qed
haftmann@26444
   260
haftmann@26444
   261
lemma distinct_set_sublists:
haftmann@26444
   262
  assumes "distinct xs"
haftmann@26444
   263
  shows "distinct (map set (sublists xs))"
haftmann@26444
   264
proof (rule card_distinct)
haftmann@26444
   265
  have "finite (set xs)" by rule
haftmann@26444
   266
  then have "card (Pow (set xs)) = Suc (Suc 0) ^ card (set xs)" by (rule card_Pow)
haftmann@26444
   267
  with assms distinct_card [of xs]
haftmann@26444
   268
    have "card (Pow (set xs)) = Suc (Suc 0) ^ length xs" by simp
haftmann@26444
   269
  then show "card (set (map set (sublists xs))) = length (map set (sublists xs))"
haftmann@26444
   270
    by (simp add: sublists_powset length_sublists)
haftmann@26348
   271
qed
haftmann@26348
   272
haftmann@26348
   273
instantiation nibble :: enum
haftmann@26348
   274
begin
haftmann@26348
   275
haftmann@26348
   276
definition
haftmann@26348
   277
  "enum = [Nibble0, Nibble1, Nibble2, Nibble3, Nibble4, Nibble5, Nibble6, Nibble7,
haftmann@26348
   278
    Nibble8, Nibble9, NibbleA, NibbleB, NibbleC, NibbleD, NibbleE, NibbleF]"
haftmann@26348
   279
haftmann@31464
   280
instance proof
haftmann@31464
   281
qed (simp_all add: enum_nibble_def UNIV_nibble)
haftmann@26348
   282
haftmann@26348
   283
end
haftmann@26348
   284
haftmann@26348
   285
instantiation char :: enum
haftmann@26348
   286
begin
haftmann@26348
   287
haftmann@26348
   288
definition
haftmann@37765
   289
  "enum = map (split Char) (product enum enum)"
haftmann@26444
   290
haftmann@31482
   291
lemma enum_chars [code]:
haftmann@31482
   292
  "enum = chars"
haftmann@31482
   293
  unfolding enum_char_def chars_def enum_nibble_def by simp
haftmann@26348
   294
haftmann@31464
   295
instance proof
haftmann@31464
   296
qed (auto intro: char.exhaust injI simp add: enum_char_def product_list_set enum_all full_SetCompr_eq [symmetric]
haftmann@31464
   297
  distinct_map distinct_product enum_distinct)
haftmann@26348
   298
haftmann@26348
   299
end
haftmann@26348
   300
huffman@29024
   301
instantiation option :: (enum) enum
huffman@29024
   302
begin
huffman@29024
   303
huffman@29024
   304
definition
huffman@29024
   305
  "enum = None # map Some enum"
huffman@29024
   306
haftmann@31464
   307
instance proof
haftmann@31464
   308
qed (auto simp add: enum_all enum_option_def, rule option.exhaust, auto intro: simp add: distinct_map enum_distinct)
huffman@29024
   309
huffman@29024
   310
end
huffman@29024
   311
bulwahn@40647
   312
subsection {* Small finite types *}
bulwahn@40647
   313
bulwahn@40647
   314
text {* We define small finite types for the use in Quickcheck *}
bulwahn@40647
   315
bulwahn@40647
   316
datatype finite_1 = a\<^isub>1
bulwahn@40647
   317
bulwahn@40647
   318
instantiation finite_1 :: enum
bulwahn@40647
   319
begin
bulwahn@40647
   320
bulwahn@40647
   321
definition
bulwahn@40647
   322
  "enum = [a\<^isub>1]"
bulwahn@40647
   323
bulwahn@40647
   324
instance proof
bulwahn@40647
   325
qed (auto simp add: enum_finite_1_def intro: finite_1.exhaust)
bulwahn@40647
   326
huffman@29024
   327
end
bulwahn@40647
   328
bulwahn@40651
   329
instantiation finite_1 :: linorder
bulwahn@40651
   330
begin
bulwahn@40651
   331
bulwahn@40651
   332
definition less_eq_finite_1 :: "finite_1 \<Rightarrow> finite_1 \<Rightarrow> bool"
bulwahn@40651
   333
where
bulwahn@40651
   334
  "less_eq_finite_1 x y = True"
bulwahn@40651
   335
bulwahn@40651
   336
definition less_finite_1 :: "finite_1 \<Rightarrow> finite_1 \<Rightarrow> bool"
bulwahn@40651
   337
where
bulwahn@40651
   338
  "less_finite_1 x y = False"
bulwahn@40651
   339
bulwahn@40651
   340
instance
bulwahn@40651
   341
apply (intro_classes)
bulwahn@40651
   342
apply (auto simp add: less_finite_1_def less_eq_finite_1_def)
bulwahn@40651
   343
apply (metis finite_1.exhaust)
bulwahn@40651
   344
done
bulwahn@40651
   345
bulwahn@40651
   346
end
bulwahn@40651
   347
bulwahn@40647
   348
datatype finite_2 = a\<^isub>1 | a\<^isub>2
bulwahn@40647
   349
bulwahn@40647
   350
instantiation finite_2 :: enum
bulwahn@40647
   351
begin
bulwahn@40647
   352
bulwahn@40647
   353
definition
bulwahn@40647
   354
  "enum = [a\<^isub>1, a\<^isub>2]"
bulwahn@40647
   355
bulwahn@40647
   356
instance proof
bulwahn@40647
   357
qed (auto simp add: enum_finite_2_def intro: finite_2.exhaust)
bulwahn@40647
   358
bulwahn@40647
   359
end
bulwahn@40647
   360
bulwahn@40651
   361
instantiation finite_2 :: linorder
bulwahn@40651
   362
begin
bulwahn@40651
   363
bulwahn@40651
   364
definition less_finite_2 :: "finite_2 \<Rightarrow> finite_2 \<Rightarrow> bool"
bulwahn@40651
   365
where
bulwahn@40651
   366
  "less_finite_2 x y = ((x = a\<^isub>1) & (y = a\<^isub>2))"
bulwahn@40651
   367
bulwahn@40651
   368
definition less_eq_finite_2 :: "finite_2 \<Rightarrow> finite_2 \<Rightarrow> bool"
bulwahn@40651
   369
where
bulwahn@40651
   370
  "less_eq_finite_2 x y = ((x = y) \<or> (x < y))"
bulwahn@40651
   371
bulwahn@40651
   372
bulwahn@40651
   373
instance
bulwahn@40651
   374
apply (intro_classes)
bulwahn@40651
   375
apply (auto simp add: less_finite_2_def less_eq_finite_2_def)
bulwahn@40651
   376
apply (metis finite_2.distinct finite_2.nchotomy)+
bulwahn@40651
   377
done
bulwahn@40651
   378
bulwahn@40651
   379
end
bulwahn@40651
   380
bulwahn@40651
   381
bulwahn@40647
   382
datatype finite_3 = a\<^isub>1 | a\<^isub>2 | a\<^isub>3
bulwahn@40647
   383
bulwahn@40647
   384
instantiation finite_3 :: enum
bulwahn@40647
   385
begin
bulwahn@40647
   386
bulwahn@40647
   387
definition
bulwahn@40647
   388
  "enum = [a\<^isub>1, a\<^isub>2, a\<^isub>3]"
bulwahn@40647
   389
bulwahn@40647
   390
instance proof
bulwahn@40647
   391
qed (auto simp add: enum_finite_3_def intro: finite_3.exhaust)
bulwahn@40647
   392
bulwahn@40647
   393
end
bulwahn@40647
   394
bulwahn@40651
   395
instantiation finite_3 :: linorder
bulwahn@40651
   396
begin
bulwahn@40651
   397
bulwahn@40651
   398
definition less_finite_3 :: "finite_3 \<Rightarrow> finite_3 \<Rightarrow> bool"
bulwahn@40651
   399
where
bulwahn@40651
   400
  "less_finite_3 x y = (case x of a\<^isub>1 => (y \<noteq> a\<^isub>1)
bulwahn@40651
   401
     | a\<^isub>2 => (y = a\<^isub>3)| a\<^isub>3 => False)"
bulwahn@40651
   402
bulwahn@40651
   403
definition less_eq_finite_3 :: "finite_3 \<Rightarrow> finite_3 \<Rightarrow> bool"
bulwahn@40651
   404
where
bulwahn@40651
   405
  "less_eq_finite_3 x y = ((x = y) \<or> (x < y))"
bulwahn@40651
   406
bulwahn@40651
   407
bulwahn@40651
   408
instance proof (intro_classes)
bulwahn@40651
   409
qed (auto simp add: less_finite_3_def less_eq_finite_3_def split: finite_3.split_asm)
bulwahn@40651
   410
bulwahn@40651
   411
end
bulwahn@40651
   412
bulwahn@40651
   413
bulwahn@40647
   414
datatype finite_4 = a\<^isub>1 | a\<^isub>2 | a\<^isub>3 | a\<^isub>4
bulwahn@40647
   415
bulwahn@40647
   416
instantiation finite_4 :: enum
bulwahn@40647
   417
begin
bulwahn@40647
   418
bulwahn@40647
   419
definition
bulwahn@40647
   420
  "enum = [a\<^isub>1, a\<^isub>2, a\<^isub>3, a\<^isub>4]"
bulwahn@40647
   421
bulwahn@40647
   422
instance proof
bulwahn@40647
   423
qed (auto simp add: enum_finite_4_def intro: finite_4.exhaust)
bulwahn@40647
   424
bulwahn@40647
   425
end
bulwahn@40647
   426
bulwahn@40651
   427
bulwahn@40651
   428
bulwahn@40647
   429
datatype finite_5 = a\<^isub>1 | a\<^isub>2 | a\<^isub>3 | a\<^isub>4 | a\<^isub>5
bulwahn@40647
   430
bulwahn@40647
   431
instantiation finite_5 :: enum
bulwahn@40647
   432
begin
bulwahn@40647
   433
bulwahn@40647
   434
definition
bulwahn@40647
   435
  "enum = [a\<^isub>1, a\<^isub>2, a\<^isub>3, a\<^isub>4, a\<^isub>5]"
bulwahn@40647
   436
bulwahn@40647
   437
instance proof
bulwahn@40647
   438
qed (auto simp add: enum_finite_5_def intro: finite_5.exhaust)
bulwahn@40647
   439
bulwahn@40647
   440
end
bulwahn@40647
   441
bulwahn@40647
   442
hide_type finite_1 finite_2 finite_3 finite_4 finite_5
bulwahn@40651
   443
hide_const (open) n_lists product
bulwahn@40647
   444
bulwahn@40647
   445
end