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