author | bulwahn |
Tue, 03 Nov 2009 10:36:20 +0100 | |
changeset 33405 | 5c1928d5db38 |
parent 33186 | 607b702feace |
child 34022 | bb37c95f0b8e |
permissions | -rw-r--r-- |
23854 | 1 |
(* Title: HOL/Library/Executable_Set.thy |
2 |
Author: Stefan Berghofer, TU Muenchen |
|
3 |
*) |
|
4 |
||
5 |
header {* Implementation of finite sets by lists *} |
|
6 |
||
7 |
theory Executable_Set |
|
33186 | 8 |
imports Main Fset SML_Quickcheck |
23854 | 9 |
begin |
10 |
||
32587
caa5ada96a00
Inter and Union are mere abbreviations for Inf and Sup
haftmann
parents:
32139
diff
changeset
|
11 |
subsection {* Preprocessor setup *} |
31847 | 12 |
|
13 |
declare member [code] |
|
23854 | 14 |
|
32683
7c1fe854ca6a
inter and union are mere abbreviations for inf and sup
haftmann
parents:
32606
diff
changeset
|
15 |
definition empty :: "'a set" where |
7c1fe854ca6a
inter and union are mere abbreviations for inf and sup
haftmann
parents:
32606
diff
changeset
|
16 |
"empty = {}" |
7c1fe854ca6a
inter and union are mere abbreviations for inf and sup
haftmann
parents:
32606
diff
changeset
|
17 |
|
7c1fe854ca6a
inter and union are mere abbreviations for inf and sup
haftmann
parents:
32606
diff
changeset
|
18 |
declare empty_def [symmetric, code_unfold] |
7c1fe854ca6a
inter and union are mere abbreviations for inf and sup
haftmann
parents:
32606
diff
changeset
|
19 |
|
7c1fe854ca6a
inter and union are mere abbreviations for inf and sup
haftmann
parents:
32606
diff
changeset
|
20 |
definition inter :: "'a set \<Rightarrow> 'a set \<Rightarrow> 'a set" where |
7c1fe854ca6a
inter and union are mere abbreviations for inf and sup
haftmann
parents:
32606
diff
changeset
|
21 |
"inter = op \<inter>" |
7c1fe854ca6a
inter and union are mere abbreviations for inf and sup
haftmann
parents:
32606
diff
changeset
|
22 |
|
7c1fe854ca6a
inter and union are mere abbreviations for inf and sup
haftmann
parents:
32606
diff
changeset
|
23 |
declare inter_def [symmetric, code_unfold] |
7c1fe854ca6a
inter and union are mere abbreviations for inf and sup
haftmann
parents:
32606
diff
changeset
|
24 |
|
7c1fe854ca6a
inter and union are mere abbreviations for inf and sup
haftmann
parents:
32606
diff
changeset
|
25 |
definition union :: "'a set \<Rightarrow> 'a set \<Rightarrow> 'a set" where |
7c1fe854ca6a
inter and union are mere abbreviations for inf and sup
haftmann
parents:
32606
diff
changeset
|
26 |
"union = op \<union>" |
7c1fe854ca6a
inter and union are mere abbreviations for inf and sup
haftmann
parents:
32606
diff
changeset
|
27 |
|
7c1fe854ca6a
inter and union are mere abbreviations for inf and sup
haftmann
parents:
32606
diff
changeset
|
28 |
declare union_def [symmetric, code_unfold] |
7c1fe854ca6a
inter and union are mere abbreviations for inf and sup
haftmann
parents:
32606
diff
changeset
|
29 |
|
28522 | 30 |
definition subset :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where |
31 |
"subset = op \<le>" |
|
32 |
||
31998
2c7a24f74db9
code attributes use common underscore convention
haftmann
parents:
31850
diff
changeset
|
33 |
declare subset_def [symmetric, code_unfold] |
28522 | 34 |
|
31847 | 35 |
lemma [code]: |
36 |
"subset A B \<longleftrightarrow> (\<forall>x\<in>A. x \<in> B)" |
|
37 |
by (simp add: subset_def subset_eq) |
|
28522 | 38 |
|
39 |
definition eq_set :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where |
|
40 |
[code del]: "eq_set = op =" |
|
41 |
||
32587
caa5ada96a00
Inter and Union are mere abbreviations for Inf and Sup
haftmann
parents:
32139
diff
changeset
|
42 |
(*declare eq_set_def [symmetric, code_unfold]*) |
29107 | 43 |
|
23854 | 44 |
lemma [code]: |
31847 | 45 |
"eq_set A B \<longleftrightarrow> A \<subseteq> B \<and> B \<subseteq> A" |
46 |
by (simp add: eq_set_def set_eq) |
|
23854 | 47 |
|
31847 | 48 |
declare inter [code] |
23854 | 49 |
|
31998
2c7a24f74db9
code attributes use common underscore convention
haftmann
parents:
31850
diff
changeset
|
50 |
declare List_Set.project_def [symmetric, code_unfold] |
23854 | 51 |
|
32587
caa5ada96a00
Inter and Union are mere abbreviations for Inf and Sup
haftmann
parents:
32139
diff
changeset
|
52 |
definition Inter :: "'a set set \<Rightarrow> 'a set" where |
caa5ada96a00
Inter and Union are mere abbreviations for Inf and Sup
haftmann
parents:
32139
diff
changeset
|
53 |
"Inter = Complete_Lattice.Inter" |
23854 | 54 |
|
32587
caa5ada96a00
Inter and Union are mere abbreviations for Inf and Sup
haftmann
parents:
32139
diff
changeset
|
55 |
declare Inter_def [symmetric, code_unfold] |
caa5ada96a00
Inter and Union are mere abbreviations for Inf and Sup
haftmann
parents:
32139
diff
changeset
|
56 |
|
caa5ada96a00
Inter and Union are mere abbreviations for Inf and Sup
haftmann
parents:
32139
diff
changeset
|
57 |
definition Union :: "'a set set \<Rightarrow> 'a set" where |
caa5ada96a00
Inter and Union are mere abbreviations for Inf and Sup
haftmann
parents:
32139
diff
changeset
|
58 |
"Union = Complete_Lattice.Union" |
caa5ada96a00
Inter and Union are mere abbreviations for Inf and Sup
haftmann
parents:
32139
diff
changeset
|
59 |
|
caa5ada96a00
Inter and Union are mere abbreviations for Inf and Sup
haftmann
parents:
32139
diff
changeset
|
60 |
declare Union_def [symmetric, code_unfold] |
caa5ada96a00
Inter and Union are mere abbreviations for Inf and Sup
haftmann
parents:
32139
diff
changeset
|
61 |
|
caa5ada96a00
Inter and Union are mere abbreviations for Inf and Sup
haftmann
parents:
32139
diff
changeset
|
62 |
|
caa5ada96a00
Inter and Union are mere abbreviations for Inf and Sup
haftmann
parents:
32139
diff
changeset
|
63 |
subsection {* Code generator setup *} |
23854 | 64 |
|
65 |
ML {* |
|
66 |
nonfix inter; |
|
67 |
nonfix union; |
|
68 |
nonfix subset; |
|
69 |
*} |
|
70 |
||
31847 | 71 |
definition flip :: "('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> 'b \<Rightarrow> 'a \<Rightarrow> 'c" where |
72 |
"flip f a b = f b a" |
|
23854 | 73 |
|
31850
e81d0f04ffdf
Executable_Set is now a simple wrapper around Fset
haftmann
parents:
31847
diff
changeset
|
74 |
types_code |
e81d0f04ffdf
Executable_Set is now a simple wrapper around Fset
haftmann
parents:
31847
diff
changeset
|
75 |
fset ("(_/ \<module>fset)") |
e81d0f04ffdf
Executable_Set is now a simple wrapper around Fset
haftmann
parents:
31847
diff
changeset
|
76 |
attach {* |
32881 | 77 |
datatype 'a fset = Set of 'a list | Coset of 'a list; |
31850
e81d0f04ffdf
Executable_Set is now a simple wrapper around Fset
haftmann
parents:
31847
diff
changeset
|
78 |
*} |
e81d0f04ffdf
Executable_Set is now a simple wrapper around Fset
haftmann
parents:
31847
diff
changeset
|
79 |
|
23854 | 80 |
consts_code |
31850
e81d0f04ffdf
Executable_Set is now a simple wrapper around Fset
haftmann
parents:
31847
diff
changeset
|
81 |
Set ("\<module>Set") |
32881 | 82 |
Coset ("\<module>Coset") |
31850
e81d0f04ffdf
Executable_Set is now a simple wrapper around Fset
haftmann
parents:
31847
diff
changeset
|
83 |
|
e81d0f04ffdf
Executable_Set is now a simple wrapper around Fset
haftmann
parents:
31847
diff
changeset
|
84 |
consts_code |
32683
7c1fe854ca6a
inter and union are mere abbreviations for inf and sup
haftmann
parents:
32606
diff
changeset
|
85 |
"empty" ("{*Fset.empty*}") |
31850
e81d0f04ffdf
Executable_Set is now a simple wrapper around Fset
haftmann
parents:
31847
diff
changeset
|
86 |
"List_Set.is_empty" ("{*Fset.is_empty*}") |
e81d0f04ffdf
Executable_Set is now a simple wrapper around Fset
haftmann
parents:
31847
diff
changeset
|
87 |
"Set.insert" ("{*Fset.insert*}") |
e81d0f04ffdf
Executable_Set is now a simple wrapper around Fset
haftmann
parents:
31847
diff
changeset
|
88 |
"List_Set.remove" ("{*Fset.remove*}") |
e81d0f04ffdf
Executable_Set is now a simple wrapper around Fset
haftmann
parents:
31847
diff
changeset
|
89 |
"Set.image" ("{*Fset.map*}") |
e81d0f04ffdf
Executable_Set is now a simple wrapper around Fset
haftmann
parents:
31847
diff
changeset
|
90 |
"List_Set.project" ("{*Fset.filter*}") |
e81d0f04ffdf
Executable_Set is now a simple wrapper around Fset
haftmann
parents:
31847
diff
changeset
|
91 |
"Ball" ("{*flip Fset.forall*}") |
e81d0f04ffdf
Executable_Set is now a simple wrapper around Fset
haftmann
parents:
31847
diff
changeset
|
92 |
"Bex" ("{*flip Fset.exists*}") |
32683
7c1fe854ca6a
inter and union are mere abbreviations for inf and sup
haftmann
parents:
32606
diff
changeset
|
93 |
"union" ("{*Fset.union*}") |
7c1fe854ca6a
inter and union are mere abbreviations for inf and sup
haftmann
parents:
32606
diff
changeset
|
94 |
"inter" ("{*Fset.inter*}") |
31850
e81d0f04ffdf
Executable_Set is now a simple wrapper around Fset
haftmann
parents:
31847
diff
changeset
|
95 |
"op - \<Colon> 'a set \<Rightarrow> 'a set \<Rightarrow> 'a set" ("{*flip Fset.subtract*}") |
32587
caa5ada96a00
Inter and Union are mere abbreviations for Inf and Sup
haftmann
parents:
32139
diff
changeset
|
96 |
"Union" ("{*Fset.Union*}") |
caa5ada96a00
Inter and Union are mere abbreviations for Inf and Sup
haftmann
parents:
32139
diff
changeset
|
97 |
"Inter" ("{*Fset.Inter*}") |
31850
e81d0f04ffdf
Executable_Set is now a simple wrapper around Fset
haftmann
parents:
31847
diff
changeset
|
98 |
card ("{*Fset.card*}") |
31847 | 99 |
fold ("{*foldl o flip*}") |
23854 | 100 |
|
32702 | 101 |
hide (open) const empty inter union subset eq_set Inter Union flip |
32647 | 102 |
|
31847 | 103 |
end |