src/HOL/Enum.thy
author blanchet
Tue, 16 Sep 2014 19:23:37 +0200
changeset 58350 919149921e46
parent 58334 7553a1bcecb7
child 58646 cd63a4b12a33
permissions -rw-r--r--
added 'extraction' plugins -- this might help 'HOL-Proofs'
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
58101
e7ebe5554281 separated listsum material
haftmann
parents: 57922
diff changeset
     6
imports Map Groups_List
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"
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
    13
  fixes enum_all :: "('a \<Rightarrow> bool) \<Rightarrow> bool"
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
    14
  fixes enum_ex :: "('a \<Rightarrow> bool) \<Rightarrow> bool"
33635
dcaada178c6f moved lemma map_of_zip_map to Map.thy
haftmann
parents: 31596
diff changeset
    15
  assumes UNIV_enum: "UNIV = set enum"
26444
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
    16
    and enum_distinct: "distinct enum"
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
    17
  assumes enum_all_UNIV: "enum_all P \<longleftrightarrow> Ball UNIV P"
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
    18
  assumes enum_ex_UNIV: "enum_ex P \<longleftrightarrow> Bex UNIV P" 
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
    19
   -- {* tailored towards simple instantiation *}
26348
0f8e23edd357 added theory Library/Enum.thy
haftmann
parents:
diff changeset
    20
begin
0f8e23edd357 added theory Library/Enum.thy
haftmann
parents:
diff changeset
    21
29797
08ef36ed2f8a handling type classes without parameters
haftmann
parents: 29024
diff changeset
    22
subclass finite proof
08ef36ed2f8a handling type classes without parameters
haftmann
parents: 29024
diff changeset
    23
qed (simp add: UNIV_enum)
26444
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
    24
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
    25
lemma enum_UNIV:
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
    26
  "set enum = UNIV"
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
    27
  by (simp only: UNIV_enum)
26444
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
    28
40683
a3f37b3d303a removing Enum.in_enum from the claset
bulwahn
parents: 40659
diff changeset
    29
lemma in_enum: "x \<in> set enum"
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
    30
  by (simp add: enum_UNIV)
26348
0f8e23edd357 added theory Library/Enum.thy
haftmann
parents:
diff changeset
    31
0f8e23edd357 added theory Library/Enum.thy
haftmann
parents:
diff changeset
    32
lemma enum_eq_I:
0f8e23edd357 added theory Library/Enum.thy
haftmann
parents:
diff changeset
    33
  assumes "\<And>x. x \<in> set xs"
0f8e23edd357 added theory Library/Enum.thy
haftmann
parents:
diff changeset
    34
  shows "set enum = set xs"
0f8e23edd357 added theory Library/Enum.thy
haftmann
parents:
diff changeset
    35
proof -
0f8e23edd357 added theory Library/Enum.thy
haftmann
parents:
diff changeset
    36
  from assms UNIV_eq_I have "UNIV = set xs" by auto
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
    37
  with enum_UNIV show ?thesis by simp
26348
0f8e23edd357 added theory Library/Enum.thy
haftmann
parents:
diff changeset
    38
qed
0f8e23edd357 added theory Library/Enum.thy
haftmann
parents:
diff changeset
    39
49972
f11f8905d9fd incorporated constant chars into instantiation proof for enum;
haftmann
parents: 49950
diff changeset
    40
lemma card_UNIV_length_enum:
f11f8905d9fd incorporated constant chars into instantiation proof for enum;
haftmann
parents: 49950
diff changeset
    41
  "card (UNIV :: 'a set) = length enum"
f11f8905d9fd incorporated constant chars into instantiation proof for enum;
haftmann
parents: 49950
diff changeset
    42
  by (simp add: UNIV_enum distinct_card enum_distinct)
f11f8905d9fd incorporated constant chars into instantiation proof for enum;
haftmann
parents: 49950
diff changeset
    43
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
    44
lemma enum_all [simp]:
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
    45
  "enum_all = HOL.All"
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
    46
  by (simp add: fun_eq_iff enum_all_UNIV)
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
    47
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
    48
lemma enum_ex [simp]:
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
    49
  "enum_ex = HOL.Ex" 
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
    50
  by (simp add: fun_eq_iff enum_ex_UNIV)
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
    51
26348
0f8e23edd357 added theory Library/Enum.thy
haftmann
parents:
diff changeset
    52
end
0f8e23edd357 added theory Library/Enum.thy
haftmann
parents:
diff changeset
    53
0f8e23edd357 added theory Library/Enum.thy
haftmann
parents:
diff changeset
    54
49949
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    55
subsection {* Implementations using @{class enum} *}
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    56
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    57
subsubsection {* Unbounded operations and quantifiers *}
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    58
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    59
lemma Collect_code [code]:
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    60
  "Collect P = set (filter P enum)"
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
    61
  by (simp add: enum_UNIV)
49949
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    62
50567
768a3fbe4149 providing a custom code equation for vimage to overwrite the vimage definition that would be rewritten by set_comprehension_pointfree simproc in the code preprocessor to an non-terminating code equation
bulwahn
parents: 49972
diff changeset
    63
lemma vimage_code [code]:
768a3fbe4149 providing a custom code equation for vimage to overwrite the vimage definition that would be rewritten by set_comprehension_pointfree simproc in the code preprocessor to an non-terminating code equation
bulwahn
parents: 49972
diff changeset
    64
  "f -` B = set (filter (%x. f x : B) enum_class.enum)"
768a3fbe4149 providing a custom code equation for vimage to overwrite the vimage definition that would be rewritten by set_comprehension_pointfree simproc in the code preprocessor to an non-terminating code equation
bulwahn
parents: 49972
diff changeset
    65
  unfolding vimage_def Collect_code ..
768a3fbe4149 providing a custom code equation for vimage to overwrite the vimage definition that would be rewritten by set_comprehension_pointfree simproc in the code preprocessor to an non-terminating code equation
bulwahn
parents: 49972
diff changeset
    66
49949
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    67
definition card_UNIV :: "'a itself \<Rightarrow> nat"
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    68
where
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    69
  [code del]: "card_UNIV TYPE('a) = card (UNIV :: 'a set)"
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    70
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    71
lemma [code]:
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    72
  "card_UNIV TYPE('a :: enum) = card (set (Enum.enum :: 'a list))"
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    73
  by (simp only: card_UNIV_def enum_UNIV)
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    74
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    75
lemma all_code [code]: "(\<forall>x. P x) \<longleftrightarrow> enum_all P"
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
    76
  by simp
49949
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    77
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    78
lemma exists_code [code]: "(\<exists>x. P x) \<longleftrightarrow> enum_ex P"
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
    79
  by simp
49949
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    80
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    81
lemma exists1_code [code]: "(\<exists>!x. P x) \<longleftrightarrow> list_ex1 P enum"
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
    82
  by (auto simp add: list_ex1_iff enum_UNIV)
49949
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    83
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    84
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    85
subsubsection {* An executable choice operator *}
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    86
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    87
definition
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    88
  [code del]: "enum_the = The"
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    89
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    90
lemma [code]:
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    91
  "The P = (case filter P enum of [x] => x | _ => enum_the P)"
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    92
proof -
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    93
  {
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    94
    fix a
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    95
    assume filter_enum: "filter P enum = [a]"
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    96
    have "The P = a"
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    97
    proof (rule the_equality)
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    98
      fix x
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
    99
      assume "P x"
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   100
      show "x = a"
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   101
      proof (rule ccontr)
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   102
        assume "x \<noteq> a"
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   103
        from filter_enum obtain us vs
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   104
          where enum_eq: "enum = us @ [a] @ vs"
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   105
          and "\<forall> x \<in> set us. \<not> P x"
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   106
          and "\<forall> x \<in> set vs. \<not> P x"
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   107
          and "P a"
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   108
          by (auto simp add: filter_eq_Cons_iff) (simp only: filter_empty_conv[symmetric])
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   109
        with `P x` in_enum[of x, unfolded enum_eq] `x \<noteq> a` show "False" by auto
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   110
      qed
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   111
    next
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   112
      from filter_enum show "P a" by (auto simp add: filter_eq_Cons_iff)
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   113
    qed
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   114
  }
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   115
  from this show ?thesis
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   116
    unfolding enum_the_def by (auto split: list.split)
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   117
qed
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   118
54890
cb892d835803 fundamental treatment of undefined vs. universally partial replaces code_abort
haftmann
parents: 54295
diff changeset
   119
declare [[code abort: enum_the]]
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 50567
diff changeset
   120
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 50567
diff changeset
   121
code_printing
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 50567
diff changeset
   122
  constant enum_the \<rightharpoonup> (Eval) "(fn '_ => raise Match)"
49949
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   123
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   124
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   125
subsubsection {* Equality and order on functions *}
26348
0f8e23edd357 added theory Library/Enum.thy
haftmann
parents:
diff changeset
   126
38857
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37765
diff changeset
   127
instantiation "fun" :: (enum, equal) equal
26513
6f306c8c2c54 explicit class "eq" for operational equality
haftmann
parents: 26444
diff changeset
   128
begin
26348
0f8e23edd357 added theory Library/Enum.thy
haftmann
parents:
diff changeset
   129
26513
6f306c8c2c54 explicit class "eq" for operational equality
haftmann
parents: 26444
diff changeset
   130
definition
38857
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37765
diff changeset
   131
  "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
   132
31464
b2aca38301c4 tuned proofs
haftmann
parents: 31193
diff changeset
   133
instance proof
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   134
qed (simp_all add: equal_fun_def fun_eq_iff enum_UNIV)
26513
6f306c8c2c54 explicit class "eq" for operational equality
haftmann
parents: 26444
diff changeset
   135
6f306c8c2c54 explicit class "eq" for operational equality
haftmann
parents: 26444
diff changeset
   136
end
26348
0f8e23edd357 added theory Library/Enum.thy
haftmann
parents:
diff changeset
   137
40898
882e860a1e83 changed order of lemmas to overwrite the general code equation with the nbe-specific one
bulwahn
parents: 40683
diff changeset
   138
lemma [code]:
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   139
  "HOL.equal f g \<longleftrightarrow> enum_all (%x. f x = g x)"
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   140
  by (auto simp add: equal fun_eq_iff)
40898
882e860a1e83 changed order of lemmas to overwrite the general code equation with the nbe-specific one
bulwahn
parents: 40683
diff changeset
   141
38857
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37765
diff changeset
   142
lemma [code nbe]:
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37765
diff changeset
   143
  "HOL.equal (f :: _ \<Rightarrow> _) f \<longleftrightarrow> True"
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37765
diff changeset
   144
  by (fact equal_refl)
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37765
diff changeset
   145
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28245
diff changeset
   146
lemma order_fun [code]:
26348
0f8e23edd357 added theory Library/Enum.thy
haftmann
parents:
diff changeset
   147
  fixes f g :: "'a\<Colon>enum \<Rightarrow> 'b\<Colon>order"
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   148
  shows "f \<le> g \<longleftrightarrow> enum_all (\<lambda>x. f x \<le> g x)"
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   149
    and "f < g \<longleftrightarrow> f \<le> g \<and> enum_ex (\<lambda>x. f x \<noteq> g x)"
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   150
  by (simp_all add: fun_eq_iff le_fun_def order_less_le)
26968
bb0a56a66180 added code for quantifiers
haftmann
parents: 26815
diff changeset
   151
bb0a56a66180 added code for quantifiers
haftmann
parents: 26815
diff changeset
   152
49949
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   153
subsubsection {* Operations on relations *}
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   154
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   155
lemma [code]:
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   156
  "Id = image (\<lambda>x. (x, x)) (set Enum.enum)"
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   157
  by (auto intro: imageI in_enum)
26968
bb0a56a66180 added code for quantifiers
haftmann
parents: 26815
diff changeset
   158
54148
c8cc5ab4a863 killed more "no_atp"s
blanchet
parents: 53015
diff changeset
   159
lemma tranclp_unfold [code]:
49949
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   160
  "tranclp r a b \<longleftrightarrow> (a, b) \<in> trancl {(x, y). r x y}"
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   161
  by (simp add: trancl_def)
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   162
54148
c8cc5ab4a863 killed more "no_atp"s
blanchet
parents: 53015
diff changeset
   163
lemma rtranclp_rtrancl_eq [code]:
49949
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   164
  "rtranclp r x y \<longleftrightarrow> (x, y) \<in> rtrancl {(x, y). r x y}"
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   165
  by (simp add: rtrancl_def)
26968
bb0a56a66180 added code for quantifiers
haftmann
parents: 26815
diff changeset
   166
49949
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   167
lemma max_ext_eq [code]:
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   168
  "max_ext R = {(X, Y). finite X \<and> finite Y \<and> Y \<noteq> {} \<and> (\<forall>x. x \<in> X \<longrightarrow> (\<exists>xa \<in> Y. (x, xa) \<in> R))}"
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   169
  by (auto simp add: max_ext.simps)
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   170
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   171
lemma max_extp_eq [code]:
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   172
  "max_extp r x y \<longleftrightarrow> (x, y) \<in> max_ext {(x, y). r x y}"
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   173
  by (simp add: max_ext_def)
26348
0f8e23edd357 added theory Library/Enum.thy
haftmann
parents:
diff changeset
   174
49949
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   175
lemma mlex_eq [code]:
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   176
  "f <*mlex*> R = {(x, y). f x < f y \<or> (f x \<le> f y \<and> (x, y) \<in> R)}"
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   177
  by (auto simp add: mlex_prod_def)
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   178
55088
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   179
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   180
subsubsection {* Bounded accessible part *}
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   181
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   182
primrec bacc :: "('a \<times> 'a) set \<Rightarrow> nat \<Rightarrow> 'a set" 
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   183
where
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   184
  "bacc r 0 = {x. \<forall> y. (y, x) \<notin> r}"
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   185
| "bacc r (Suc n) = (bacc r n \<union> {x. \<forall>y. (y, x) \<in> r \<longrightarrow> y \<in> bacc r n})"
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   186
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   187
lemma bacc_subseteq_acc:
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   188
  "bacc r n \<subseteq> Wellfounded.acc r"
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   189
  by (induct n) (auto intro: acc.intros)
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   190
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   191
lemma bacc_mono:
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   192
  "n \<le> m \<Longrightarrow> bacc r n \<subseteq> bacc r m"
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   193
  by (induct rule: dec_induct) auto
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   194
  
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   195
lemma bacc_upper_bound:
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   196
  "bacc (r :: ('a \<times> 'a) set)  (card (UNIV :: 'a::finite set)) = (\<Union>n. bacc r n)"
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   197
proof -
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   198
  have "mono (bacc r)" unfolding mono_def by (simp add: bacc_mono)
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   199
  moreover have "\<forall>n. bacc r n = bacc r (Suc n) \<longrightarrow> bacc r (Suc n) = bacc r (Suc (Suc n))" by auto
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   200
  moreover have "finite (range (bacc r))" by auto
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   201
  ultimately show ?thesis
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   202
   by (intro finite_mono_strict_prefix_implies_finite_fixpoint)
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   203
     (auto intro: finite_mono_remains_stable_implies_strict_prefix)
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   204
qed
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   205
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   206
lemma acc_subseteq_bacc:
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   207
  assumes "finite r"
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   208
  shows "Wellfounded.acc r \<subseteq> (\<Union>n. bacc r n)"
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   209
proof
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   210
  fix x
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   211
  assume "x : Wellfounded.acc r"
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   212
  then have "\<exists> n. x : bacc r n"
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   213
  proof (induct x arbitrary: rule: acc.induct)
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   214
    case (accI x)
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   215
    then have "\<forall>y. \<exists> n. (y, x) \<in> r --> y : bacc r n" by simp
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   216
    from choice[OF this] obtain n where n: "\<forall>y. (y, x) \<in> r \<longrightarrow> y \<in> bacc r (n y)" ..
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   217
    obtain n where "\<And>y. (y, x) : r \<Longrightarrow> y : bacc r n"
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   218
    proof
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   219
      fix y assume y: "(y, x) : r"
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   220
      with n have "y : bacc r (n y)" by auto
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   221
      moreover have "n y <= Max ((%(y, x). n y) ` r)"
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   222
        using y `finite r` by (auto intro!: Max_ge)
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   223
      note bacc_mono[OF this, of r]
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   224
      ultimately show "y : bacc r (Max ((%(y, x). n y) ` r))" by auto
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   225
    qed
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   226
    then show ?case
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   227
      by (auto simp add: Let_def intro!: exI[of _ "Suc n"])
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   228
  qed
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   229
  then show "x : (UN n. bacc r n)" by auto
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   230
qed
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   231
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   232
lemma acc_bacc_eq:
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   233
  fixes A :: "('a :: finite \<times> 'a) set"
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   234
  assumes "finite A"
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   235
  shows "Wellfounded.acc A = bacc A (card (UNIV :: 'a set))"
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   236
  using assms by (metis acc_subseteq_bacc bacc_subseteq_acc bacc_upper_bound order_eq_iff)
57c82e01022b moved 'bacc' back to 'Enum' (cf. 744934b818c7) -- reduces baggage loaded by 'Hilbert_Choice'
blanchet
parents: 54890
diff changeset
   237
49949
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   238
lemma [code]:
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   239
  fixes xs :: "('a::finite \<times> 'a) list"
54295
45a5523d4a63 qualifed popular user space names
haftmann
parents: 54148
diff changeset
   240
  shows "Wellfounded.acc (set xs) = bacc (set xs) (card_UNIV TYPE('a))"
49949
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   241
  by (simp add: card_UNIV_def acc_bacc_eq)
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   242
26348
0f8e23edd357 added theory Library/Enum.thy
haftmann
parents:
diff changeset
   243
49949
be3dd2e602e8 refined internal structure of Enum.thy
haftmann
parents: 49948
diff changeset
   244
subsection {* Default instances for @{class enum} *}
26348
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 map_of_zip_enum_is_Some:
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   247
  assumes "length ys = length (enum \<Colon> 'a\<Colon>enum list)"
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   248
  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
   249
proof -
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   250
  from assms have "x \<in> set (enum \<Colon> 'a\<Colon>enum list) \<longleftrightarrow>
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   251
    (\<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
   252
    by (auto intro!: map_of_zip_is_Some)
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   253
  then show ?thesis using enum_UNIV by auto
26444
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   254
qed
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   255
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   256
lemma map_of_zip_enum_inject:
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   257
  fixes xs ys :: "'b\<Colon>enum list"
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   258
  assumes length: "length xs = length (enum \<Colon> 'a\<Colon>enum list)"
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   259
      "length ys = length (enum \<Colon> 'a\<Colon>enum list)"
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   260
    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
   261
  shows "xs = ys"
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   262
proof -
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   263
  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
   264
  proof
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   265
    fix x :: 'a
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   266
    from length map_of_zip_enum_is_Some obtain y1 y2
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   267
      where "map_of (zip (enum \<Colon> 'a list) xs) x = Some y1"
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   268
        and "map_of (zip (enum \<Colon> 'a list) ys) x = Some y2" by blast
47230
6584098d5378 tuned proofs, less guesswork;
wenzelm
parents: 46361
diff changeset
   269
    moreover from map_of
6584098d5378 tuned proofs, less guesswork;
wenzelm
parents: 46361
diff changeset
   270
      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)"
26444
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   271
      by (auto dest: fun_cong)
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   272
    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
   273
      by simp
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   274
  qed
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   275
  with length enum_distinct show "xs = ys" by (rule map_of_zip_inject)
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   276
qed
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   277
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   278
definition all_n_lists :: "(('a :: enum) list \<Rightarrow> bool) \<Rightarrow> nat \<Rightarrow> bool"
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   279
where
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   280
  "all_n_lists P n \<longleftrightarrow> (\<forall>xs \<in> set (List.n_lists n enum). P xs)"
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   281
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   282
lemma [code]:
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   283
  "all_n_lists P n \<longleftrightarrow> (if n = 0 then P [] else enum_all (%x. all_n_lists (%xs. P (x # xs)) (n - 1)))"
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   284
  unfolding all_n_lists_def enum_all
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   285
  by (cases n) (auto simp add: enum_UNIV)
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   286
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   287
definition ex_n_lists :: "(('a :: enum) list \<Rightarrow> bool) \<Rightarrow> nat \<Rightarrow> bool"
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   288
where
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   289
  "ex_n_lists P n \<longleftrightarrow> (\<exists>xs \<in> set (List.n_lists n enum). P xs)"
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   290
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   291
lemma [code]:
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   292
  "ex_n_lists P n \<longleftrightarrow> (if n = 0 then P [] else enum_ex (%x. ex_n_lists (%xs. P (x # xs)) (n - 1)))"
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   293
  unfolding ex_n_lists_def enum_ex
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   294
  by (cases n) (auto simp add: enum_UNIV)
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   295
26444
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   296
instantiation "fun" :: (enum, enum) enum
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   297
begin
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   298
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   299
definition
49948
744934b818c7 moved quite generic material from theory Enum to more appropriate places
haftmann
parents: 48123
diff changeset
   300
  "enum = map (\<lambda>ys. the o map_of (zip (enum\<Colon>'a list) ys)) (List.n_lists (length (enum\<Colon>'a\<Colon>enum list)) enum)"
26444
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   301
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   302
definition
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   303
  "enum_all P = all_n_lists (\<lambda>bs. P (the o map_of (zip enum bs))) (length (enum :: 'a list))"
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   304
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   305
definition
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   306
  "enum_ex P = ex_n_lists (\<lambda>bs. P (the o map_of (zip enum bs))) (length (enum :: 'a list))"
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   307
26444
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   308
instance proof
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   309
  show "UNIV = set (enum \<Colon> ('a \<Rightarrow> 'b) list)"
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   310
  proof (rule UNIV_eq_I)
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   311
    fix f :: "'a \<Rightarrow> 'b"
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   312
    have "f = the \<circ> map_of (zip (enum \<Colon> 'a\<Colon>enum list) (map f enum))"
40683
a3f37b3d303a removing Enum.in_enum from the claset
bulwahn
parents: 40659
diff changeset
   313
      by (auto simp add: map_of_zip_map fun_eq_iff intro: in_enum)
26444
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   314
    then show "f \<in> set enum"
40683
a3f37b3d303a removing Enum.in_enum from the claset
bulwahn
parents: 40659
diff changeset
   315
      by (auto simp add: enum_fun_def set_n_lists intro: in_enum)
26444
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   316
  qed
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   317
next
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   318
  from map_of_zip_enum_inject
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   319
  show "distinct (enum \<Colon> ('a \<Rightarrow> 'b) list)"
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   320
    by (auto intro!: inj_onI simp add: enum_fun_def
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   321
      distinct_map distinct_n_lists enum_distinct set_n_lists)
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   322
next
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   323
  fix P
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   324
  show "enum_all (P :: ('a \<Rightarrow> 'b) \<Rightarrow> bool) = Ball UNIV P"
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   325
  proof
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   326
    assume "enum_all P"
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   327
    show "Ball UNIV P"
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   328
    proof
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   329
      fix f :: "'a \<Rightarrow> 'b"
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   330
      have f: "f = the \<circ> map_of (zip (enum \<Colon> 'a\<Colon>enum list) (map f enum))"
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   331
        by (auto simp add: map_of_zip_map fun_eq_iff intro: in_enum)
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   332
      from `enum_all P` have "P (the \<circ> map_of (zip enum (map f enum)))"
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   333
        unfolding enum_all_fun_def all_n_lists_def
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   334
        apply (simp add: set_n_lists)
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   335
        apply (erule_tac x="map f enum" in allE)
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   336
        apply (auto intro!: in_enum)
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   337
        done
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   338
      from this f show "P f" by auto
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   339
    qed
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   340
  next
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   341
    assume "Ball UNIV P"
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   342
    from this show "enum_all P"
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   343
      unfolding enum_all_fun_def all_n_lists_def by auto
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   344
  qed
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   345
next
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   346
  fix P
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   347
  show "enum_ex (P :: ('a \<Rightarrow> 'b) \<Rightarrow> bool) = Bex UNIV P"
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   348
  proof
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   349
    assume "enum_ex P"
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   350
    from this show "Bex UNIV P"
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   351
      unfolding enum_ex_fun_def ex_n_lists_def by auto
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   352
  next
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   353
    assume "Bex UNIV P"
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   354
    from this obtain f where "P f" ..
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   355
    have f: "f = the \<circ> map_of (zip (enum \<Colon> 'a\<Colon>enum list) (map f enum))"
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   356
      by (auto simp add: map_of_zip_map fun_eq_iff intro: in_enum) 
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   357
    from `P f` this have "P (the \<circ> map_of (zip (enum \<Colon> 'a\<Colon>enum list) (map f enum)))"
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   358
      by auto
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   359
    from  this show "enum_ex P"
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   360
      unfolding enum_ex_fun_def ex_n_lists_def
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   361
      apply (auto simp add: set_n_lists)
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   362
      apply (rule_tac x="map f enum" in exI)
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   363
      apply (auto intro!: in_enum)
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   364
      done
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   365
  qed
26444
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   366
qed
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   367
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   368
end
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   369
38857
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37765
diff changeset
   370
lemma enum_fun_code [code]: "enum = (let enum_a = (enum \<Colon> 'a\<Colon>{enum, equal} list)
49948
744934b818c7 moved quite generic material from theory Enum to more appropriate places
haftmann
parents: 48123
diff changeset
   371
  in map (\<lambda>ys. the o map_of (zip enum_a ys)) (List.n_lists (length enum_a) enum))"
28245
9767dd8e1e54 celver code lemma avoid type ambiguity problem with Haskell
haftmann
parents: 27487
diff changeset
   372
  by (simp add: enum_fun_def Let_def)
26444
6a5faa5bcf19 instance for functions, explicit characters
haftmann
parents: 26348
diff changeset
   373
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   374
lemma enum_all_fun_code [code]:
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   375
  "enum_all P = (let enum_a = (enum :: 'a::{enum, equal} list)
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   376
   in all_n_lists (\<lambda>bs. P (the o map_of (zip enum_a bs))) (length enum_a))"
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   377
  by (simp only: enum_all_fun_def Let_def)
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   378
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   379
lemma enum_ex_fun_code [code]:
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   380
  "enum_ex P = (let enum_a = (enum :: 'a::{enum, equal} list)
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   381
   in ex_n_lists (\<lambda>bs. P (the o map_of (zip enum_a bs))) (length enum_a))"
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   382
  by (simp only: enum_ex_fun_def Let_def)
45963
1c7e6454883e enum type class instance for `set`; dropped misfitting code lemma for trancl
haftmann
parents: 45144
diff changeset
   383
1c7e6454883e enum type class instance for `set`; dropped misfitting code lemma for trancl
haftmann
parents: 45144
diff changeset
   384
instantiation set :: (enum) enum
1c7e6454883e enum type class instance for `set`; dropped misfitting code lemma for trancl
haftmann
parents: 45144
diff changeset
   385
begin
1c7e6454883e enum type class instance for `set`; dropped misfitting code lemma for trancl
haftmann
parents: 45144
diff changeset
   386
1c7e6454883e enum type class instance for `set`; dropped misfitting code lemma for trancl
haftmann
parents: 45144
diff changeset
   387
definition
1c7e6454883e enum type class instance for `set`; dropped misfitting code lemma for trancl
haftmann
parents: 45144
diff changeset
   388
  "enum = map set (sublists enum)"
1c7e6454883e enum type class instance for `set`; dropped misfitting code lemma for trancl
haftmann
parents: 45144
diff changeset
   389
1c7e6454883e enum type class instance for `set`; dropped misfitting code lemma for trancl
haftmann
parents: 45144
diff changeset
   390
definition
1c7e6454883e enum type class instance for `set`; dropped misfitting code lemma for trancl
haftmann
parents: 45144
diff changeset
   391
  "enum_all P \<longleftrightarrow> (\<forall>A\<in>set enum. P (A::'a set))"
1c7e6454883e enum type class instance for `set`; dropped misfitting code lemma for trancl
haftmann
parents: 45144
diff changeset
   392
1c7e6454883e enum type class instance for `set`; dropped misfitting code lemma for trancl
haftmann
parents: 45144
diff changeset
   393
definition
1c7e6454883e enum type class instance for `set`; dropped misfitting code lemma for trancl
haftmann
parents: 45144
diff changeset
   394
  "enum_ex P \<longleftrightarrow> (\<exists>A\<in>set enum. P (A::'a set))"
1c7e6454883e enum type class instance for `set`; dropped misfitting code lemma for trancl
haftmann
parents: 45144
diff changeset
   395
1c7e6454883e enum type class instance for `set`; dropped misfitting code lemma for trancl
haftmann
parents: 45144
diff changeset
   396
instance proof
1c7e6454883e enum type class instance for `set`; dropped misfitting code lemma for trancl
haftmann
parents: 45144
diff changeset
   397
qed (simp_all add: enum_set_def enum_all_set_def enum_ex_set_def sublists_powset distinct_set_sublists
1c7e6454883e enum type class instance for `set`; dropped misfitting code lemma for trancl
haftmann
parents: 45144
diff changeset
   398
  enum_distinct enum_UNIV)
29024
6cfa380af73b instantiation option :: (enum) enum
huffman
parents: 28684
diff changeset
   399
6cfa380af73b instantiation option :: (enum) enum
huffman
parents: 28684
diff changeset
   400
end
6cfa380af73b instantiation option :: (enum) enum
huffman
parents: 28684
diff changeset
   401
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   402
instantiation unit :: enum
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   403
begin
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   404
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   405
definition
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   406
  "enum = [()]"
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   407
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   408
definition
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   409
  "enum_all P = P ()"
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   410
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   411
definition
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   412
  "enum_ex P = P ()"
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   413
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   414
instance proof
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   415
qed (auto simp add: enum_unit_def enum_all_unit_def enum_ex_unit_def)
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   416
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   417
end
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   418
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   419
instantiation bool :: enum
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   420
begin
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   421
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   422
definition
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   423
  "enum = [False, True]"
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   424
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   425
definition
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   426
  "enum_all P \<longleftrightarrow> P False \<and> P True"
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   427
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   428
definition
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   429
  "enum_ex P \<longleftrightarrow> P False \<or> P True"
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   430
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   431
instance proof
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   432
qed (simp_all only: enum_bool_def enum_all_bool_def enum_ex_bool_def UNIV_bool, simp_all)
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   433
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   434
end
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   435
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   436
instantiation prod :: (enum, enum) enum
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   437
begin
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   438
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   439
definition
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   440
  "enum = List.product enum enum"
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   441
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   442
definition
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   443
  "enum_all P = enum_all (%x. enum_all (%y. P (x, y)))"
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   444
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   445
definition
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   446
  "enum_ex P = enum_ex (%x. enum_ex (%y. P (x, y)))"
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   447
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   448
 
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   449
instance by default
57247
8191ccf6a1bd added [simp]
nipkow
parents: 55088
diff changeset
   450
  (simp_all add: enum_prod_def distinct_product
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   451
    enum_UNIV enum_distinct enum_all_prod_def enum_ex_prod_def)
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   452
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   453
end
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   454
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   455
instantiation sum :: (enum, enum) enum
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   456
begin
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   457
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   458
definition
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   459
  "enum = map Inl enum @ map Inr enum"
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   460
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   461
definition
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   462
  "enum_all P \<longleftrightarrow> enum_all (\<lambda>x. P (Inl x)) \<and> enum_all (\<lambda>x. P (Inr x))"
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   463
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   464
definition
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   465
  "enum_ex P \<longleftrightarrow> enum_ex (\<lambda>x. P (Inl x)) \<or> enum_ex (\<lambda>x. P (Inr x))"
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   466
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   467
instance proof
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   468
qed (simp_all only: enum_sum_def enum_all_sum_def enum_ex_sum_def UNIV_sum,
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   469
  auto simp add: enum_UNIV distinct_map enum_distinct)
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   470
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   471
end
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   472
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   473
instantiation option :: (enum) enum
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   474
begin
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   475
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   476
definition
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   477
  "enum = None # map Some enum"
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   478
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   479
definition
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   480
  "enum_all P \<longleftrightarrow> P None \<and> enum_all (\<lambda>x. P (Some x))"
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   481
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   482
definition
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   483
  "enum_ex P \<longleftrightarrow> P None \<or> enum_ex (\<lambda>x. P (Some x))"
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   484
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   485
instance proof
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   486
qed (simp_all only: enum_option_def enum_all_option_def enum_ex_option_def UNIV_option_conv,
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   487
  auto simp add: distinct_map enum_UNIV enum_distinct)
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   488
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   489
end
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   490
45963
1c7e6454883e enum type class instance for `set`; dropped misfitting code lemma for trancl
haftmann
parents: 45144
diff changeset
   491
40647
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   492
subsection {* Small finite types *}
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   493
58334
7553a1bcecb7 disable datatype 'plugins' for internal types
blanchet
parents: 58310
diff changeset
   494
text {* We define small finite types for use in Quickcheck *}
40647
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   495
58350
919149921e46 added 'extraction' plugins -- this might help 'HOL-Proofs'
blanchet
parents: 58334
diff changeset
   496
datatype (plugins only: code "quickcheck*" extraction) finite_1 =
919149921e46 added 'extraction' plugins -- this might help 'HOL-Proofs'
blanchet
parents: 58334
diff changeset
   497
  a\<^sub>1
40647
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   498
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   499
notation (output) a\<^sub>1  ("a\<^sub>1")
40900
1d5f76d79856 adding shorter output syntax for the finite types of quickcheck
bulwahn
parents: 40898
diff changeset
   500
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   501
lemma UNIV_finite_1:
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   502
  "UNIV = {a\<^sub>1}"
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   503
  by (auto intro: finite_1.exhaust)
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   504
40647
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   505
instantiation finite_1 :: enum
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   506
begin
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   507
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   508
definition
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   509
  "enum = [a\<^sub>1]"
40647
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   510
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   511
definition
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   512
  "enum_all P = P a\<^sub>1"
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   513
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   514
definition
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   515
  "enum_ex P = P a\<^sub>1"
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   516
40647
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   517
instance proof
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   518
qed (simp_all only: enum_finite_1_def enum_all_finite_1_def enum_ex_finite_1_def UNIV_finite_1, simp_all)
40647
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   519
29024
6cfa380af73b instantiation option :: (enum) enum
huffman
parents: 28684
diff changeset
   520
end
40647
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   521
40651
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   522
instantiation finite_1 :: linorder
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   523
begin
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   524
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   525
definition less_finite_1 :: "finite_1 \<Rightarrow> finite_1 \<Rightarrow> bool"
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   526
where
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   527
  "x < (y :: finite_1) \<longleftrightarrow> False"
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   528
40651
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   529
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
   530
where
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   531
  "x \<le> (y :: finite_1) \<longleftrightarrow> True"
40651
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   532
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   533
instance
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   534
apply (intro_classes)
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   535
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
   536
apply (metis finite_1.exhaust)
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   537
done
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   538
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   539
end
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   540
57922
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   541
instance finite_1 :: "{dense_linorder, wellorder}"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   542
by intro_classes (simp_all add: less_finite_1_def)
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   543
57818
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   544
instantiation finite_1 :: complete_lattice
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   545
begin
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   546
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   547
definition [simp]: "Inf = (\<lambda>_. a\<^sub>1)"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   548
definition [simp]: "Sup = (\<lambda>_. a\<^sub>1)"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   549
definition [simp]: "bot = a\<^sub>1"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   550
definition [simp]: "top = a\<^sub>1"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   551
definition [simp]: "inf = (\<lambda>_ _. a\<^sub>1)"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   552
definition [simp]: "sup = (\<lambda>_ _. a\<^sub>1)"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   553
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   554
instance by intro_classes(simp_all add: less_eq_finite_1_def)
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   555
end
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   556
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   557
instance finite_1 :: complete_distrib_lattice
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   558
by intro_classes(simp_all add: INF_def SUP_def)
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   559
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   560
instance finite_1 :: complete_linorder ..
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   561
57922
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   562
lemma finite_1_eq: "x = a\<^sub>1"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   563
by(cases x) simp
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   564
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   565
simproc_setup finite_1_eq ("x::finite_1") = {*
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   566
  fn _ => fn _ => fn ct => case term_of ct of
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   567
    Const (@{const_name a\<^sub>1}, _) => NONE
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   568
  | _ => SOME (mk_meta_eq @{thm finite_1_eq})
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   569
*}
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   570
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   571
instantiation finite_1 :: complete_boolean_algebra begin
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   572
definition [simp]: "op - = (\<lambda>_ _. a\<^sub>1)"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   573
definition [simp]: "uminus = (\<lambda>_. a\<^sub>1)"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   574
instance by intro_classes simp_all
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   575
end
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   576
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   577
instantiation finite_1 :: 
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   578
  "{linordered_ring_strict, linordered_comm_semiring_strict, ordered_comm_ring,
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   579
    ordered_cancel_comm_monoid_diff, comm_monoid_mult, ordered_ring_abs,
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   580
    one, Divides.div, sgn_if, inverse}"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   581
begin
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   582
definition [simp]: "Groups.zero = a\<^sub>1"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   583
definition [simp]: "Groups.one = a\<^sub>1"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   584
definition [simp]: "op + = (\<lambda>_ _. a\<^sub>1)"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   585
definition [simp]: "op * = (\<lambda>_ _. a\<^sub>1)"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   586
definition [simp]: "op div = (\<lambda>_ _. a\<^sub>1)" 
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   587
definition [simp]: "op mod = (\<lambda>_ _. a\<^sub>1)" 
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   588
definition [simp]: "abs = (\<lambda>_. a\<^sub>1)"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   589
definition [simp]: "sgn = (\<lambda>_. a\<^sub>1)"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   590
definition [simp]: "inverse = (\<lambda>_. a\<^sub>1)"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   591
definition [simp]: "op / = (\<lambda>_ _. a\<^sub>1)"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   592
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   593
instance by intro_classes(simp_all add: less_finite_1_def)
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   594
end
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   595
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   596
declare [[simproc del: finite_1_eq]]
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   597
hide_const (open) a\<^sub>1
40657
58a6ba7ccfc5 hiding the constants
bulwahn
parents: 40652
diff changeset
   598
58350
919149921e46 added 'extraction' plugins -- this might help 'HOL-Proofs'
blanchet
parents: 58334
diff changeset
   599
datatype (plugins only: code "quickcheck*" extraction) finite_2 =
919149921e46 added 'extraction' plugins -- this might help 'HOL-Proofs'
blanchet
parents: 58334
diff changeset
   600
  a\<^sub>1 | a\<^sub>2
40647
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   601
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   602
notation (output) a\<^sub>1  ("a\<^sub>1")
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   603
notation (output) a\<^sub>2  ("a\<^sub>2")
40900
1d5f76d79856 adding shorter output syntax for the finite types of quickcheck
bulwahn
parents: 40898
diff changeset
   604
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   605
lemma UNIV_finite_2:
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   606
  "UNIV = {a\<^sub>1, a\<^sub>2}"
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   607
  by (auto intro: finite_2.exhaust)
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   608
40647
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   609
instantiation finite_2 :: enum
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   610
begin
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   611
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   612
definition
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   613
  "enum = [a\<^sub>1, a\<^sub>2]"
40647
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   614
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   615
definition
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   616
  "enum_all P \<longleftrightarrow> P a\<^sub>1 \<and> P a\<^sub>2"
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   617
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   618
definition
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   619
  "enum_ex P \<longleftrightarrow> P a\<^sub>1 \<or> P a\<^sub>2"
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   620
40647
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   621
instance proof
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   622
qed (simp_all only: enum_finite_2_def enum_all_finite_2_def enum_ex_finite_2_def UNIV_finite_2, simp_all)
40647
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   623
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   624
end
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   625
40651
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   626
instantiation finite_2 :: linorder
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   627
begin
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   628
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   629
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
   630
where
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   631
  "x < y \<longleftrightarrow> x = a\<^sub>1 \<and> y = a\<^sub>2"
40651
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   632
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   633
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
   634
where
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   635
  "x \<le> y \<longleftrightarrow> x = y \<or> x < (y :: finite_2)"
40651
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   636
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   637
instance
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   638
apply (intro_classes)
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   639
apply (auto simp add: less_finite_2_def less_eq_finite_2_def)
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   640
apply (metis finite_2.nchotomy)+
40651
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   641
done
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   642
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   643
end
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   644
57922
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   645
instance finite_2 :: wellorder
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   646
by(rule wf_wellorderI)(simp add: less_finite_2_def, intro_classes)
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   647
57818
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   648
instantiation finite_2 :: complete_lattice
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   649
begin
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   650
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   651
definition "\<Sqinter>A = (if a\<^sub>1 \<in> A then a\<^sub>1 else a\<^sub>2)"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   652
definition "\<Squnion>A = (if a\<^sub>2 \<in> A then a\<^sub>2 else a\<^sub>1)"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   653
definition [simp]: "bot = a\<^sub>1"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   654
definition [simp]: "top = a\<^sub>2"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   655
definition "x \<sqinter> y = (if x = a\<^sub>1 \<or> y = a\<^sub>1 then a\<^sub>1 else a\<^sub>2)"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   656
definition "x \<squnion> y = (if x = a\<^sub>2 \<or> y = a\<^sub>2 then a\<^sub>2 else a\<^sub>1)"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   657
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   658
lemma neq_finite_2_a\<^sub>1_iff [simp]: "x \<noteq> a\<^sub>1 \<longleftrightarrow> x = a\<^sub>2"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   659
by(cases x) simp_all
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   660
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   661
lemma neq_finite_2_a\<^sub>1_iff' [simp]: "a\<^sub>1 \<noteq> x \<longleftrightarrow> x = a\<^sub>2"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   662
by(cases x) simp_all
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   663
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   664
lemma neq_finite_2_a\<^sub>2_iff [simp]: "x \<noteq> a\<^sub>2 \<longleftrightarrow> x = a\<^sub>1"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   665
by(cases x) simp_all
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   666
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   667
lemma neq_finite_2_a\<^sub>2_iff' [simp]: "a\<^sub>2 \<noteq> x \<longleftrightarrow> x = a\<^sub>1"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   668
by(cases x) simp_all
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   669
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   670
instance
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   671
proof
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   672
  fix x :: finite_2 and A
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   673
  assume "x \<in> A"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   674
  then show "\<Sqinter>A \<le> x" "x \<le> \<Squnion>A"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   675
    by(case_tac [!] x)(auto simp add: less_eq_finite_2_def less_finite_2_def Inf_finite_2_def Sup_finite_2_def)
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   676
qed(auto simp add: less_eq_finite_2_def less_finite_2_def inf_finite_2_def sup_finite_2_def Inf_finite_2_def Sup_finite_2_def)
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   677
end
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   678
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   679
instance finite_2 :: complete_distrib_lattice
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   680
by(intro_classes)(auto simp add: INF_def SUP_def sup_finite_2_def inf_finite_2_def Inf_finite_2_def Sup_finite_2_def)
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   681
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   682
instance finite_2 :: complete_linorder ..
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   683
57922
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   684
instantiation finite_2 :: "{field_inverse_zero, abs_if, ring_div, semiring_div_parity, sgn_if}" begin
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   685
definition [simp]: "0 = a\<^sub>1"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   686
definition [simp]: "1 = a\<^sub>2"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   687
definition "x + y = (case (x, y) of (a\<^sub>1, a\<^sub>1) \<Rightarrow> a\<^sub>1 | (a\<^sub>2, a\<^sub>2) \<Rightarrow> a\<^sub>1 | _ \<Rightarrow> a\<^sub>2)"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   688
definition "uminus = (\<lambda>x :: finite_2. x)"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   689
definition "op - = (op + :: finite_2 \<Rightarrow> _)"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   690
definition "x * y = (case (x, y) of (a\<^sub>2, a\<^sub>2) \<Rightarrow> a\<^sub>2 | _ \<Rightarrow> a\<^sub>1)"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   691
definition "inverse = (\<lambda>x :: finite_2. x)"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   692
definition "op / = (op * :: finite_2 \<Rightarrow> _)"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   693
definition "abs = (\<lambda>x :: finite_2. x)"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   694
definition "op div = (op / :: finite_2 \<Rightarrow> _)"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   695
definition "x mod y = (case (x, y) of (a\<^sub>2, a\<^sub>1) \<Rightarrow> a\<^sub>2 | _ \<Rightarrow> a\<^sub>1)"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   696
definition "sgn = (\<lambda>x :: finite_2. x)"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   697
instance
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   698
by intro_classes
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   699
  (simp_all add: plus_finite_2_def uminus_finite_2_def minus_finite_2_def times_finite_2_def
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   700
       inverse_finite_2_def divide_finite_2_def abs_finite_2_def div_finite_2_def mod_finite_2_def sgn_finite_2_def
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   701
     split: finite_2.splits)
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   702
end
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   703
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   704
hide_const (open) a\<^sub>1 a\<^sub>2
40657
58a6ba7ccfc5 hiding the constants
bulwahn
parents: 40652
diff changeset
   705
58350
919149921e46 added 'extraction' plugins -- this might help 'HOL-Proofs'
blanchet
parents: 58334
diff changeset
   706
datatype (plugins only: code "quickcheck*" extraction) finite_3 =
919149921e46 added 'extraction' plugins -- this might help 'HOL-Proofs'
blanchet
parents: 58334
diff changeset
   707
  a\<^sub>1 | a\<^sub>2 | a\<^sub>3
40647
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   708
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   709
notation (output) a\<^sub>1  ("a\<^sub>1")
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   710
notation (output) a\<^sub>2  ("a\<^sub>2")
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   711
notation (output) a\<^sub>3  ("a\<^sub>3")
40900
1d5f76d79856 adding shorter output syntax for the finite types of quickcheck
bulwahn
parents: 40898
diff changeset
   712
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   713
lemma UNIV_finite_3:
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   714
  "UNIV = {a\<^sub>1, a\<^sub>2, a\<^sub>3}"
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   715
  by (auto intro: finite_3.exhaust)
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   716
40647
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   717
instantiation finite_3 :: enum
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   718
begin
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   719
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   720
definition
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   721
  "enum = [a\<^sub>1, a\<^sub>2, a\<^sub>3]"
40647
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   722
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   723
definition
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   724
  "enum_all P \<longleftrightarrow> P a\<^sub>1 \<and> P a\<^sub>2 \<and> P a\<^sub>3"
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   725
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   726
definition
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   727
  "enum_ex P \<longleftrightarrow> P a\<^sub>1 \<or> P a\<^sub>2 \<or> P a\<^sub>3"
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   728
40647
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   729
instance proof
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   730
qed (simp_all only: enum_finite_3_def enum_all_finite_3_def enum_ex_finite_3_def UNIV_finite_3, simp_all)
40647
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   731
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   732
end
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   733
40651
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   734
instantiation finite_3 :: linorder
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   735
begin
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   736
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   737
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
   738
where
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   739
  "x < y = (case x of a\<^sub>1 \<Rightarrow> y \<noteq> a\<^sub>1 | a\<^sub>2 \<Rightarrow> y = a\<^sub>3 | a\<^sub>3 \<Rightarrow> False)"
40651
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   740
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   741
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
   742
where
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   743
  "x \<le> y \<longleftrightarrow> x = y \<or> x < (y :: finite_3)"
40651
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   744
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   745
instance proof (intro_classes)
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   746
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
   747
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   748
end
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   749
57922
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   750
instance finite_3 :: wellorder
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   751
proof(rule wf_wellorderI)
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   752
  have "inv_image less_than (case_finite_3 0 1 2) = {(x, y). x < y}"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   753
    by(auto simp add: less_finite_3_def split: finite_3.splits)
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   754
  from this[symmetric] show "wf \<dots>" by simp
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   755
qed intro_classes
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   756
57818
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   757
instantiation finite_3 :: complete_lattice
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   758
begin
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   759
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   760
definition "\<Sqinter>A = (if a\<^sub>1 \<in> A then a\<^sub>1 else if a\<^sub>2 \<in> A then a\<^sub>2 else a\<^sub>3)"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   761
definition "\<Squnion>A = (if a\<^sub>3 \<in> A then a\<^sub>3 else if a\<^sub>2 \<in> A then a\<^sub>2 else a\<^sub>1)"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   762
definition [simp]: "bot = a\<^sub>1"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   763
definition [simp]: "top = a\<^sub>3"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   764
definition [simp]: "inf = (min :: finite_3 \<Rightarrow> _)"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   765
definition [simp]: "sup = (max :: finite_3 \<Rightarrow> _)"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   766
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   767
instance
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   768
proof
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   769
  fix x :: finite_3 and A
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   770
  assume "x \<in> A"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   771
  then show "\<Sqinter>A \<le> x" "x \<le> \<Squnion>A"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   772
    by(case_tac [!] x)(auto simp add: Inf_finite_3_def Sup_finite_3_def less_eq_finite_3_def less_finite_3_def)
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   773
next
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   774
  fix A and z :: finite_3
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   775
  assume "\<And>x. x \<in> A \<Longrightarrow> z \<le> x"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   776
  then show "z \<le> \<Sqinter>A"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   777
    by(cases z)(auto simp add: Inf_finite_3_def less_eq_finite_3_def less_finite_3_def)
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   778
next
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   779
  fix A and z :: finite_3
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   780
  assume *: "\<And>x. x \<in> A \<Longrightarrow> x \<le> z"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   781
  show "\<Squnion>A \<le> z"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   782
    by(auto simp add: Sup_finite_3_def less_eq_finite_3_def less_finite_3_def dest: *)
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   783
qed(auto simp add: Inf_finite_3_def Sup_finite_3_def)
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   784
end
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   785
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   786
instance finite_3 :: complete_distrib_lattice
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   787
proof
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   788
  fix a :: finite_3 and B
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   789
  show "a \<squnion> \<Sqinter>B = (\<Sqinter>b\<in>B. a \<squnion> b)"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   790
  proof(cases a "\<Sqinter>B" rule: finite_3.exhaust[case_product finite_3.exhaust])
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   791
    case a\<^sub>2_a\<^sub>3
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   792
    then have "\<And>x. x \<in> B \<Longrightarrow> x = a\<^sub>3"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   793
      by(case_tac x)(auto simp add: Inf_finite_3_def split: split_if_asm)
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   794
    then show ?thesis using a\<^sub>2_a\<^sub>3
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   795
      by(auto simp add: INF_def Inf_finite_3_def max_def less_eq_finite_3_def less_finite_3_def split: split_if_asm)
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   796
  qed(auto simp add: INF_def Inf_finite_3_def max_def less_finite_3_def less_eq_finite_3_def split: split_if_asm)
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   797
  show "a \<sqinter> \<Squnion>B = (\<Squnion>b\<in>B. a \<sqinter> b)"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   798
    by(cases a "\<Squnion>B" rule: finite_3.exhaust[case_product finite_3.exhaust])
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   799
      (auto simp add: SUP_def Sup_finite_3_def min_def less_finite_3_def less_eq_finite_3_def split: split_if_asm)
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   800
qed
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   801
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   802
instance finite_3 :: complete_linorder ..
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   803
57922
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   804
instantiation finite_3 :: "{field_inverse_zero, abs_if, ring_div, semiring_div, sgn_if}" begin
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   805
definition [simp]: "0 = a\<^sub>1"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   806
definition [simp]: "1 = a\<^sub>2"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   807
definition
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   808
  "x + y = (case (x, y) of
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   809
     (a\<^sub>1, a\<^sub>1) \<Rightarrow> a\<^sub>1 | (a\<^sub>2, a\<^sub>3) \<Rightarrow> a\<^sub>1 | (a\<^sub>3, a\<^sub>2) \<Rightarrow> a\<^sub>1
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   810
   | (a\<^sub>1, a\<^sub>2) \<Rightarrow> a\<^sub>2 | (a\<^sub>2, a\<^sub>1) \<Rightarrow> a\<^sub>2 | (a\<^sub>3, a\<^sub>3) \<Rightarrow> a\<^sub>2
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   811
   | _ \<Rightarrow> a\<^sub>3)"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   812
definition "- x = (case x of a\<^sub>1 \<Rightarrow> a\<^sub>1 | a\<^sub>2 \<Rightarrow> a\<^sub>3 | a\<^sub>3 \<Rightarrow> a\<^sub>2)"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   813
definition "x - y = x + (- y :: finite_3)"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   814
definition "x * y = (case (x, y) of (a\<^sub>2, a\<^sub>2) \<Rightarrow> a\<^sub>2 | (a\<^sub>3, a\<^sub>3) \<Rightarrow> a\<^sub>2 | (a\<^sub>2, a\<^sub>3) \<Rightarrow> a\<^sub>3 | (a\<^sub>3, a\<^sub>2) \<Rightarrow> a\<^sub>3 | _ \<Rightarrow> a\<^sub>1)"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   815
definition "inverse = (\<lambda>x :: finite_3. x)" 
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   816
definition "x / y = x * inverse (y :: finite_3)"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   817
definition "abs = (\<lambda>x :: finite_3. x)"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   818
definition "op div = (op / :: finite_3 \<Rightarrow> _)"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   819
definition "x mod y = (case (x, y) of (a\<^sub>2, a\<^sub>1) \<Rightarrow> a\<^sub>2 | (a\<^sub>3, a\<^sub>1) \<Rightarrow> a\<^sub>3 | _ \<Rightarrow> a\<^sub>1)"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   820
definition "sgn = (\<lambda>x. case x of a\<^sub>1 \<Rightarrow> a\<^sub>1 | _ \<Rightarrow> a\<^sub>2)"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   821
instance
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   822
by intro_classes
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   823
  (simp_all add: plus_finite_3_def uminus_finite_3_def minus_finite_3_def times_finite_3_def
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   824
       inverse_finite_3_def divide_finite_3_def abs_finite_3_def div_finite_3_def mod_finite_3_def sgn_finite_3_def
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   825
       less_finite_3_def
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   826
     split: finite_3.splits)
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   827
end
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   828
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   829
hide_const (open) a\<^sub>1 a\<^sub>2 a\<^sub>3
40657
58a6ba7ccfc5 hiding the constants
bulwahn
parents: 40652
diff changeset
   830
58350
919149921e46 added 'extraction' plugins -- this might help 'HOL-Proofs'
blanchet
parents: 58334
diff changeset
   831
datatype (plugins only: code "quickcheck*" extraction) finite_4 =
919149921e46 added 'extraction' plugins -- this might help 'HOL-Proofs'
blanchet
parents: 58334
diff changeset
   832
  a\<^sub>1 | a\<^sub>2 | a\<^sub>3 | a\<^sub>4
40647
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   833
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   834
notation (output) a\<^sub>1  ("a\<^sub>1")
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   835
notation (output) a\<^sub>2  ("a\<^sub>2")
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   836
notation (output) a\<^sub>3  ("a\<^sub>3")
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   837
notation (output) a\<^sub>4  ("a\<^sub>4")
40900
1d5f76d79856 adding shorter output syntax for the finite types of quickcheck
bulwahn
parents: 40898
diff changeset
   838
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   839
lemma UNIV_finite_4:
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   840
  "UNIV = {a\<^sub>1, a\<^sub>2, a\<^sub>3, a\<^sub>4}"
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   841
  by (auto intro: finite_4.exhaust)
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   842
40647
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   843
instantiation finite_4 :: enum
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   844
begin
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   845
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   846
definition
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   847
  "enum = [a\<^sub>1, a\<^sub>2, a\<^sub>3, a\<^sub>4]"
40647
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   848
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   849
definition
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   850
  "enum_all P \<longleftrightarrow> P a\<^sub>1 \<and> P a\<^sub>2 \<and> P a\<^sub>3 \<and> P a\<^sub>4"
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   851
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   852
definition
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   853
  "enum_ex P \<longleftrightarrow> P a\<^sub>1 \<or> P a\<^sub>2 \<or> P a\<^sub>3 \<or> P a\<^sub>4"
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   854
40647
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   855
instance proof
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   856
qed (simp_all only: enum_finite_4_def enum_all_finite_4_def enum_ex_finite_4_def UNIV_finite_4, simp_all)
40647
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   857
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   858
end
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   859
57818
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   860
instantiation finite_4 :: complete_lattice begin
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   861
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   862
text {* @{term a\<^sub>1} $<$ @{term a\<^sub>2},@{term a\<^sub>3} $<$ @{term a\<^sub>4},
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   863
  but @{term a\<^sub>2} and @{term a\<^sub>3} are incomparable. *}
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   864
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   865
definition
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   866
  "x < y \<longleftrightarrow> (case (x, y) of
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   867
     (a\<^sub>1, a\<^sub>1) \<Rightarrow> False | (a\<^sub>1, _) \<Rightarrow> True
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   868
   |  (a\<^sub>2, a\<^sub>4) \<Rightarrow> True
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   869
   |  (a\<^sub>3, a\<^sub>4) \<Rightarrow> True  | _ \<Rightarrow> False)"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   870
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   871
definition 
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   872
  "x \<le> y \<longleftrightarrow> (case (x, y) of
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   873
     (a\<^sub>1, _) \<Rightarrow> True
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   874
   | (a\<^sub>2, a\<^sub>2) \<Rightarrow> True | (a\<^sub>2, a\<^sub>4) \<Rightarrow> True
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   875
   | (a\<^sub>3, a\<^sub>3) \<Rightarrow> True | (a\<^sub>3, a\<^sub>4) \<Rightarrow> True
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   876
   | (a\<^sub>4, a\<^sub>4) \<Rightarrow> True | _ \<Rightarrow> False)"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   877
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   878
definition
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   879
  "\<Sqinter>A = (if a\<^sub>1 \<in> A \<or> a\<^sub>2 \<in> A \<and> a\<^sub>3 \<in> A then a\<^sub>1 else if a\<^sub>2 \<in> A then a\<^sub>2 else if a\<^sub>3 \<in> A then a\<^sub>3 else a\<^sub>4)"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   880
definition
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   881
  "\<Squnion>A = (if a\<^sub>4 \<in> A \<or> a\<^sub>2 \<in> A \<and> a\<^sub>3 \<in> A then a\<^sub>4 else if a\<^sub>2 \<in> A then a\<^sub>2 else if a\<^sub>3 \<in> A then a\<^sub>3 else a\<^sub>1)"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   882
definition [simp]: "bot = a\<^sub>1"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   883
definition [simp]: "top = a\<^sub>4"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   884
definition
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   885
  "x \<sqinter> y = (case (x, y) of
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   886
     (a\<^sub>1, _) \<Rightarrow> a\<^sub>1 | (_, a\<^sub>1) \<Rightarrow> a\<^sub>1 | (a\<^sub>2, a\<^sub>3) \<Rightarrow> a\<^sub>1 | (a\<^sub>3, a\<^sub>2) \<Rightarrow> a\<^sub>1
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   887
   | (a\<^sub>2, _) \<Rightarrow> a\<^sub>2 | (_, a\<^sub>2) \<Rightarrow> a\<^sub>2
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   888
   | (a\<^sub>3, _) \<Rightarrow> a\<^sub>3 | (_, a\<^sub>3) \<Rightarrow> a\<^sub>3
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   889
   | _ \<Rightarrow> a\<^sub>4)"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   890
definition
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   891
  "x \<squnion> y = (case (x, y) of
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   892
     (a\<^sub>4, _) \<Rightarrow> a\<^sub>4 | (_, a\<^sub>4) \<Rightarrow> a\<^sub>4 | (a\<^sub>2, a\<^sub>3) \<Rightarrow> a\<^sub>4 | (a\<^sub>3, a\<^sub>2) \<Rightarrow> a\<^sub>4
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   893
  | (a\<^sub>2, _) \<Rightarrow> a\<^sub>2 | (_, a\<^sub>2) \<Rightarrow> a\<^sub>2
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   894
  | (a\<^sub>3, _) \<Rightarrow> a\<^sub>3 | (_, a\<^sub>3) \<Rightarrow> a\<^sub>3
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   895
  | _ \<Rightarrow> a\<^sub>1)"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   896
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   897
instance
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   898
proof
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   899
  fix A and z :: finite_4
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   900
  assume *: "\<And>x. x \<in> A \<Longrightarrow> x \<le> z"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   901
  show "\<Squnion>A \<le> z"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   902
    by(auto simp add: Sup_finite_4_def less_eq_finite_4_def dest!: * split: finite_4.splits)
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   903
next
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   904
  fix A and z :: finite_4
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   905
  assume *: "\<And>x. x \<in> A \<Longrightarrow> z \<le> x"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   906
  show "z \<le> \<Sqinter>A"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   907
    by(auto simp add: Inf_finite_4_def less_eq_finite_4_def dest!: * split: finite_4.splits)
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   908
qed(auto simp add: less_finite_4_def less_eq_finite_4_def Inf_finite_4_def Sup_finite_4_def inf_finite_4_def sup_finite_4_def split: finite_4.splits)
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   909
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   910
end
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   911
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   912
instance finite_4 :: complete_distrib_lattice
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   913
proof
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   914
  fix a :: finite_4 and B
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   915
  show "a \<squnion> \<Sqinter>B = (\<Sqinter>b\<in>B. a \<squnion> b)"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   916
    by(cases a "\<Sqinter>B" rule: finite_4.exhaust[case_product finite_4.exhaust])
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   917
      (auto simp add: sup_finite_4_def Inf_finite_4_def INF_def split: finite_4.splits split_if_asm)
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   918
  show "a \<sqinter> \<Squnion>B = (\<Squnion>b\<in>B. a \<sqinter> b)"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   919
    by(cases a "\<Squnion>B" rule: finite_4.exhaust[case_product finite_4.exhaust])
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   920
      (auto simp add: inf_finite_4_def Sup_finite_4_def SUP_def split: finite_4.splits split_if_asm)
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   921
qed
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   922
57922
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   923
instantiation finite_4 :: complete_boolean_algebra begin
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   924
definition "- x = (case x of a\<^sub>1 \<Rightarrow> a\<^sub>4 | a\<^sub>2 \<Rightarrow> a\<^sub>3 | a\<^sub>3 \<Rightarrow> a\<^sub>2 | a\<^sub>4 \<Rightarrow> a\<^sub>1)"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   925
definition "x - y = x \<sqinter> - (y :: finite_4)"
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   926
instance
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   927
by intro_classes
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   928
  (simp_all add: inf_finite_4_def sup_finite_4_def uminus_finite_4_def minus_finite_4_def split: finite_4.splits)
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   929
end
dc78785427d0 add algebraic type class instances for Enum.finite* types
Andreas Lochbihler
parents: 57818
diff changeset
   930
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   931
hide_const (open) a\<^sub>1 a\<^sub>2 a\<^sub>3 a\<^sub>4
40651
9752ba7348b5 adding code equation for function equality; adding some instantiations for the finite types
bulwahn
parents: 40650
diff changeset
   932
58350
919149921e46 added 'extraction' plugins -- this might help 'HOL-Proofs'
blanchet
parents: 58334
diff changeset
   933
datatype (plugins only: code "quickcheck*" extraction) finite_5 =
919149921e46 added 'extraction' plugins -- this might help 'HOL-Proofs'
blanchet
parents: 58334
diff changeset
   934
  a\<^sub>1 | a\<^sub>2 | a\<^sub>3 | a\<^sub>4 | a\<^sub>5
40647
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   935
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   936
notation (output) a\<^sub>1  ("a\<^sub>1")
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   937
notation (output) a\<^sub>2  ("a\<^sub>2")
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   938
notation (output) a\<^sub>3  ("a\<^sub>3")
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   939
notation (output) a\<^sub>4  ("a\<^sub>4")
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   940
notation (output) a\<^sub>5  ("a\<^sub>5")
40900
1d5f76d79856 adding shorter output syntax for the finite types of quickcheck
bulwahn
parents: 40898
diff changeset
   941
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   942
lemma UNIV_finite_5:
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   943
  "UNIV = {a\<^sub>1, a\<^sub>2, a\<^sub>3, a\<^sub>4, a\<^sub>5}"
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   944
  by (auto intro: finite_5.exhaust)
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   945
40647
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   946
instantiation finite_5 :: enum
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   947
begin
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   948
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   949
definition
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   950
  "enum = [a\<^sub>1, a\<^sub>2, a\<^sub>3, a\<^sub>4, a\<^sub>5]"
40647
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   951
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   952
definition
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   953
  "enum_all P \<longleftrightarrow> P a\<^sub>1 \<and> P a\<^sub>2 \<and> P a\<^sub>3 \<and> P a\<^sub>4 \<and> P a\<^sub>5"
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   954
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   955
definition
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
   956
  "enum_ex P \<longleftrightarrow> P a\<^sub>1 \<or> P a\<^sub>2 \<or> P a\<^sub>3 \<or> P a\<^sub>4 \<or> P a\<^sub>5"
41078
051251fde456 adding more efficient implementations for quantifiers in Enum
bulwahn
parents: 40900
diff changeset
   957
40647
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   958
instance proof
49950
cd882d53ba6b tailored enum specification towards simple instantiation;
haftmann
parents: 49949
diff changeset
   959
qed (simp_all only: enum_finite_5_def enum_all_finite_5_def enum_ex_finite_5_def UNIV_finite_5, simp_all)
40647
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   960
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   961
end
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
   962
57818
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   963
instantiation finite_5 :: complete_lattice
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   964
begin
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   965
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   966
text {* The non-distributive pentagon lattice $N_5$ *}
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   967
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   968
definition
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   969
  "x < y \<longleftrightarrow> (case (x, y) of
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   970
     (a\<^sub>1, a\<^sub>1) \<Rightarrow> False | (a\<^sub>1, _) \<Rightarrow> True
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   971
   | (a\<^sub>2, a\<^sub>3) \<Rightarrow> True  | (a\<^sub>2, a\<^sub>5) \<Rightarrow> True
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   972
   | (a\<^sub>3, a\<^sub>5) \<Rightarrow> True
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   973
   | (a\<^sub>4, a\<^sub>5) \<Rightarrow> True  | _ \<Rightarrow> False)"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   974
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   975
definition
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   976
  "x \<le> y \<longleftrightarrow> (case (x, y) of
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   977
     (a\<^sub>1, _) \<Rightarrow> True
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   978
   | (a\<^sub>2, a\<^sub>2) \<Rightarrow> True | (a\<^sub>2, a\<^sub>3) \<Rightarrow> True | (a\<^sub>2, a\<^sub>5) \<Rightarrow> True
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   979
   | (a\<^sub>3, a\<^sub>3) \<Rightarrow> True | (a\<^sub>3, a\<^sub>5) \<Rightarrow> True
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   980
   | (a\<^sub>4, a\<^sub>4) \<Rightarrow> True | (a\<^sub>4, a\<^sub>5) \<Rightarrow> True
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   981
   | (a\<^sub>5, a\<^sub>5) \<Rightarrow> True | _ \<Rightarrow> False)"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   982
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   983
definition
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   984
  "\<Sqinter>A = 
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   985
  (if a\<^sub>1 \<in> A \<or> a\<^sub>4 \<in> A \<and> (a\<^sub>2 \<in> A \<or> a\<^sub>3 \<in> A) then a\<^sub>1
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   986
   else if a\<^sub>2 \<in> A then a\<^sub>2
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   987
   else if a\<^sub>3 \<in> A then a\<^sub>3
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   988
   else if a\<^sub>4 \<in> A then a\<^sub>4
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   989
   else a\<^sub>5)"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   990
definition
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   991
  "\<Squnion>A = 
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   992
  (if a\<^sub>5 \<in> A \<or> a\<^sub>4 \<in> A \<and> (a\<^sub>2 \<in> A \<or> a\<^sub>3 \<in> A) then a\<^sub>5
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   993
   else if a\<^sub>3 \<in> A then a\<^sub>3
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   994
   else if a\<^sub>2 \<in> A then a\<^sub>2
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   995
   else if a\<^sub>4 \<in> A then a\<^sub>4
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   996
   else a\<^sub>1)"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   997
definition [simp]: "bot = a\<^sub>1"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   998
definition [simp]: "top = a\<^sub>5"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
   999
definition
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
  1000
  "x \<sqinter> y = (case (x, y) of
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
  1001
     (a\<^sub>1, _) \<Rightarrow> a\<^sub>1 | (_, a\<^sub>1) \<Rightarrow> a\<^sub>1 | (a\<^sub>2, a\<^sub>4) \<Rightarrow> a\<^sub>1 | (a\<^sub>4, a\<^sub>2) \<Rightarrow> a\<^sub>1 | (a\<^sub>3, a\<^sub>4) \<Rightarrow> a\<^sub>1 | (a\<^sub>4, a\<^sub>3) \<Rightarrow> a\<^sub>1
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
  1002
   | (a\<^sub>2, _) \<Rightarrow> a\<^sub>2 | (_, a\<^sub>2) \<Rightarrow> a\<^sub>2
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
  1003
   | (a\<^sub>3, _) \<Rightarrow> a\<^sub>3 | (_, a\<^sub>3) \<Rightarrow> a\<^sub>3
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
  1004
   | (a\<^sub>4, _) \<Rightarrow> a\<^sub>4 | (_, a\<^sub>4) \<Rightarrow> a\<^sub>4
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
  1005
   | _ \<Rightarrow> a\<^sub>5)"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
  1006
definition
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
  1007
  "x \<squnion> y = (case (x, y) of
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
  1008
     (a\<^sub>5, _) \<Rightarrow> a\<^sub>5 | (_, a\<^sub>5) \<Rightarrow> a\<^sub>5 | (a\<^sub>2, a\<^sub>4) \<Rightarrow> a\<^sub>5 | (a\<^sub>4, a\<^sub>2) \<Rightarrow> a\<^sub>5 | (a\<^sub>3, a\<^sub>4) \<Rightarrow> a\<^sub>5 | (a\<^sub>4, a\<^sub>3) \<Rightarrow> a\<^sub>5
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
  1009
   | (a\<^sub>3, _) \<Rightarrow> a\<^sub>3 | (_, a\<^sub>3) \<Rightarrow> a\<^sub>3
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
  1010
   | (a\<^sub>2, _) \<Rightarrow> a\<^sub>2 | (_, a\<^sub>2) \<Rightarrow> a\<^sub>2
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
  1011
   | (a\<^sub>4, _) \<Rightarrow> a\<^sub>4 | (_, a\<^sub>4) \<Rightarrow> a\<^sub>4
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
  1012
   | _ \<Rightarrow> a\<^sub>1)"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
  1013
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
  1014
instance 
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
  1015
proof intro_classes
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
  1016
  fix A and z :: finite_5
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
  1017
  assume *: "\<And>x. x \<in> A \<Longrightarrow> z \<le> x"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
  1018
  show "z \<le> \<Sqinter>A"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
  1019
    by(auto simp add: less_eq_finite_5_def Inf_finite_5_def split: finite_5.splits split_if_asm dest!: *)
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
  1020
next
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
  1021
  fix A and z :: finite_5
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
  1022
  assume *: "\<And>x. x \<in> A \<Longrightarrow> x \<le> z"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
  1023
  show "\<Squnion>A \<le> z"
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
  1024
    by(auto simp add: less_eq_finite_5_def Sup_finite_5_def split: finite_5.splits split_if_asm dest!: *)
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
  1025
qed(auto simp add: less_eq_finite_5_def less_finite_5_def inf_finite_5_def sup_finite_5_def Inf_finite_5_def Sup_finite_5_def split: finite_5.splits split_if_asm)
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
  1026
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
  1027
end
51aa30c9ee4e add complete_lattice instances for Enum.finite_* types such that quickcheck deals with lattice class operations
Andreas Lochbihler
parents: 57247
diff changeset
  1028
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52435
diff changeset
  1029
hide_const (open) a\<^sub>1 a\<^sub>2 a\<^sub>3 a\<^sub>4 a\<^sub>5
46352
73b03235799a an executable version of accessible part (only for finite types yet)
bulwahn
parents: 46336
diff changeset
  1030
49948
744934b818c7 moved quite generic material from theory Enum to more appropriate places
haftmann
parents: 48123
diff changeset
  1031
46352
73b03235799a an executable version of accessible part (only for finite types yet)
bulwahn
parents: 46336
diff changeset
  1032
subsection {* Closing up *}
40657
58a6ba7ccfc5 hiding the constants
bulwahn
parents: 40652
diff changeset
  1033
41085
a549ff1d4070 adding a smarter enumeration scheme for finite functions
bulwahn
parents: 41078
diff changeset
  1034
hide_type (open) finite_1 finite_2 finite_3 finite_4 finite_5
49948
744934b818c7 moved quite generic material from theory Enum to more appropriate places
haftmann
parents: 48123
diff changeset
  1035
hide_const (open) enum enum_all enum_ex all_n_lists ex_n_lists ntrancl
40647
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
  1036
6e92ca8e981b adding prototype for finite_type instantiations
bulwahn
parents: 39302
diff changeset
  1037
end