| author | wenzelm |
| Sun, 26 Nov 2006 18:07:16 +0100 | |
| changeset 21524 | 7843e2fd14a9 |
| parent 21511 | 16c62deb1adf |
| child 21572 | 7442833ea2b6 |
| permissions | -rw-r--r-- |
| 17632 | 1 |
(* Title: HOL/Library/ExecutableSet.thy |
2 |
ID: $Id$ |
|
3 |
Author: Stefan Berghofer, TU Muenchen |
|
4 |
*) |
|
5 |
||
6 |
header {* Implementation of finite sets by lists *}
|
|
7 |
||
8 |
theory ExecutableSet |
|
9 |
imports Main |
|
10 |
begin |
|
11 |
||
| 21323 | 12 |
section {* Definitional rewrites *}
|
| 20597 | 13 |
|
14 |
instance set :: (eq) eq .. |
|
| 19791 | 15 |
|
|
21385
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
16 |
definition |
|
21404
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
wenzelm
parents:
21385
diff
changeset
|
17 |
minus_set :: "'a set \<Rightarrow> 'a set \<Rightarrow> 'a set" where |
|
21385
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
18 |
"minus_set xs ys = ys - xs" |
|
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
19 |
|
|
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
20 |
lemma [code inline]: |
|
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
21 |
"op - = (\<lambda>xs ys. minus_set ys xs)" |
|
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
22 |
unfolding minus_set_def .. |
|
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
23 |
|
|
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
24 |
definition |
|
21404
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
wenzelm
parents:
21385
diff
changeset
|
25 |
subset :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where |
|
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
wenzelm
parents:
21385
diff
changeset
|
26 |
"subset = op \<subseteq>" |
|
21385
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
27 |
|
|
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
28 |
lemmas [symmetric, code inline] = subset_def |
|
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
29 |
|
| 21153 | 30 |
lemma [code target: Set]: |
|
21385
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
31 |
"A = B \<longleftrightarrow> A \<subseteq> B \<and> B \<subseteq> A" |
| 17632 | 32 |
by blast |
33 |
||
| 20597 | 34 |
lemma [code func]: |
|
21385
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
35 |
"subset A B \<longleftrightarrow> (\<forall>x\<in>A. x \<in> B)" |
|
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
36 |
unfolding subset_def Set.subset_def .. |
| 20597 | 37 |
|
| 21323 | 38 |
lemma [code]: |
39 |
"a \<in> A \<longleftrightarrow> (\<exists>x\<in>A. x = a)" |
|
40 |
unfolding bex_triv_one_point1 .. |
|
| 17632 | 41 |
|
|
21385
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
42 |
definition |
|
21404
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
wenzelm
parents:
21385
diff
changeset
|
43 |
filter_set :: "('a \<Rightarrow> bool) \<Rightarrow> 'a set \<Rightarrow> 'a set" where
|
|
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
wenzelm
parents:
21385
diff
changeset
|
44 |
"filter_set P xs = {x\<in>xs. P x}"
|
| 20597 | 45 |
|
|
21385
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
46 |
lemmas [symmetric, code inline] = filter_set_def |
|
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
47 |
|
|
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
48 |
|
|
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
49 |
section {* Operations on lists *}
|
| 19791 | 50 |
|
51 |
subsection {* Basic definitions *}
|
|
52 |
||
53 |
definition |
|
|
21404
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
wenzelm
parents:
21385
diff
changeset
|
54 |
flip :: "('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> 'b \<Rightarrow> 'a \<Rightarrow> 'c" where
|
| 19791 | 55 |
"flip f a b = f b a" |
|
21404
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
wenzelm
parents:
21385
diff
changeset
|
56 |
|
|
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
wenzelm
parents:
21385
diff
changeset
|
57 |
definition |
|
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
wenzelm
parents:
21385
diff
changeset
|
58 |
member :: "'a list \<Rightarrow> 'a \<Rightarrow> bool" where |
| 19791 | 59 |
"member xs x = (x \<in> set xs)" |
|
21404
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
wenzelm
parents:
21385
diff
changeset
|
60 |
|
|
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
wenzelm
parents:
21385
diff
changeset
|
61 |
definition |
|
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
wenzelm
parents:
21385
diff
changeset
|
62 |
insertl :: "'a \<Rightarrow> 'a list \<Rightarrow> 'a list" where |
| 19791 | 63 |
"insertl x xs = (if member xs x then xs else x#xs)" |
64 |
||
65 |
lemma |
|
66 |
[code target: List]: "member [] y = False" |
|
67 |
and [code target: List]: "member (x#xs) y = (y = x \<or> member xs y)" |
|
68 |
unfolding member_def by (induct xs) simp_all |
|
69 |
||
70 |
consts |
|
71 |
drop_first :: "('a \<Rightarrow> bool) \<Rightarrow> 'a list \<Rightarrow> 'a list"
|
|
72 |
||
73 |
primrec |
|
74 |
"drop_first f [] = []" |
|
75 |
"drop_first f (x#xs) = (if f x then xs else x # drop_first f xs)" |
|
76 |
declare drop_first.simps [code del] |
|
77 |
declare drop_first.simps [code target: List] |
|
78 |
||
79 |
declare remove1.simps [code del] |
|
80 |
lemma [code target: List]: |
|
81 |
"remove1 x xs = (if member xs x then drop_first (\<lambda>y. y = x) xs else xs)" |
|
82 |
proof (cases "member xs x") |
|
83 |
case False thus ?thesis unfolding member_def by (induct xs) auto |
|
84 |
next |
|
85 |
case True |
|
86 |
have "remove1 x xs = drop_first (\<lambda>y. y = x) xs" by (induct xs) simp_all |
|
87 |
with True show ?thesis by simp |
|
88 |
qed |
|
89 |
||
90 |
lemma member_nil [simp]: |
|
91 |
"member [] = (\<lambda>x. False)" |
|
92 |
proof |
|
93 |
fix x |
|
94 |
show "member [] x = False" unfolding member_def by simp |
|
95 |
qed |
|
96 |
||
97 |
lemma member_insertl [simp]: |
|
98 |
"x \<in> set (insertl x xs)" |
|
99 |
unfolding insertl_def member_def mem_iff by simp |
|
100 |
||
101 |
lemma insertl_member [simp]: |
|
102 |
fixes xs x |
|
103 |
assumes member: "member xs x" |
|
104 |
shows "insertl x xs = xs" |
|
105 |
using member unfolding insertl_def by simp |
|
106 |
||
107 |
lemma insertl_not_member [simp]: |
|
108 |
fixes xs x |
|
109 |
assumes member: "\<not> (member xs x)" |
|
110 |
shows "insertl x xs = x # xs" |
|
111 |
using member unfolding insertl_def by simp |
|
112 |
||
113 |
lemma foldr_remove1_empty [simp]: |
|
114 |
"foldr remove1 xs [] = []" |
|
115 |
by (induct xs) simp_all |
|
116 |
||
117 |
||
118 |
subsection {* Derived definitions *}
|
|
119 |
||
| 20934 | 120 |
function unionl :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list" |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20503
diff
changeset
|
121 |
where |
| 19791 | 122 |
"unionl [] ys = ys" |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20503
diff
changeset
|
123 |
| "unionl xs ys = foldr insertl xs ys" |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20503
diff
changeset
|
124 |
by pat_completeness auto |
| 21321 | 125 |
termination by lexicographic_order |
126 |
||
| 19791 | 127 |
lemmas unionl_def = unionl.simps(2) |
128 |
||
| 20934 | 129 |
function intersect :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list" |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20503
diff
changeset
|
130 |
where |
| 19791 | 131 |
"intersect [] ys = []" |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20503
diff
changeset
|
132 |
| "intersect xs [] = []" |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20503
diff
changeset
|
133 |
| "intersect xs ys = filter (member xs) ys" |
| 21321 | 134 |
by pat_completeness auto |
135 |
termination by lexicographic_order |
|
136 |
||
| 19791 | 137 |
lemmas intersect_def = intersect.simps(3) |
138 |
||
| 20934 | 139 |
function subtract :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list" |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20503
diff
changeset
|
140 |
where |
| 19791 | 141 |
"subtract [] ys = ys" |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20503
diff
changeset
|
142 |
| "subtract xs [] = []" |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20503
diff
changeset
|
143 |
| "subtract xs ys = foldr remove1 xs ys" |
| 21321 | 144 |
by pat_completeness auto |
145 |
termination by lexicographic_order |
|
146 |
||
| 19791 | 147 |
lemmas subtract_def = subtract.simps(3) |
148 |
||
| 20934 | 149 |
function map_distinct :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a list \<Rightarrow> 'b list"
|
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20503
diff
changeset
|
150 |
where |
| 19791 | 151 |
"map_distinct f [] = []" |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20503
diff
changeset
|
152 |
| "map_distinct f xs = foldr (insertl o f) xs []" |
| 21321 | 153 |
by pat_completeness auto |
154 |
termination by lexicographic_order |
|
155 |
||
| 19791 | 156 |
lemmas map_distinct_def = map_distinct.simps(2) |
157 |
||
| 20934 | 158 |
function unions :: "'a list list \<Rightarrow> 'a list" |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20503
diff
changeset
|
159 |
where |
| 19791 | 160 |
"unions [] = []" |
161 |
"unions xs = foldr unionl xs []" |
|
| 21321 | 162 |
by pat_completeness auto |
163 |
termination by lexicographic_order |
|
164 |
||
| 19791 | 165 |
lemmas unions_def = unions.simps(2) |
166 |
||
| 20934 | 167 |
consts intersects :: "'a list list \<Rightarrow> 'a list" |
| 19791 | 168 |
primrec |
169 |
"intersects (x#xs) = foldr intersect xs x" |
|
170 |
||
171 |
definition |
|
|
21404
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
wenzelm
parents:
21385
diff
changeset
|
172 |
map_union :: "'a list \<Rightarrow> ('a \<Rightarrow> 'b list) \<Rightarrow> 'b list" where
|
| 19791 | 173 |
"map_union xs f = unions (map f xs)" |
|
21404
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
wenzelm
parents:
21385
diff
changeset
|
174 |
|
|
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
wenzelm
parents:
21385
diff
changeset
|
175 |
definition |
|
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
wenzelm
parents:
21385
diff
changeset
|
176 |
map_inter :: "'a list \<Rightarrow> ('a \<Rightarrow> 'b list) \<Rightarrow> 'b list" where
|
| 19791 | 177 |
"map_inter xs f = intersects (map f xs)" |
178 |
||
179 |
||
180 |
section {* Isomorphism proofs *}
|
|
181 |
||
182 |
lemma iso_member: |
|
183 |
"member xs x = (x \<in> set xs)" |
|
184 |
unfolding member_def mem_iff .. |
|
185 |
||
186 |
lemma iso_insert: |
|
187 |
"set (insertl x xs) = insert x (set xs)" |
|
188 |
unfolding insertl_def iso_member by (simp add: Set.insert_absorb) |
|
189 |
||
190 |
lemma iso_remove1: |
|
191 |
assumes distnct: "distinct xs" |
|
192 |
shows "set (remove1 x xs) = set xs - {x}"
|
|
|
21385
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
193 |
using distnct set_remove1_eq by auto |
| 19791 | 194 |
|
195 |
lemma iso_union: |
|
196 |
"set (unionl xs ys) = set xs \<union> set ys" |
|
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20503
diff
changeset
|
197 |
unfolding unionl_def |
|
21385
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
198 |
by (induct xs arbitrary: ys) (simp_all add: iso_insert) |
| 19791 | 199 |
|
200 |
lemma iso_intersect: |
|
201 |
"set (intersect xs ys) = set xs \<inter> set ys" |
|
202 |
unfolding intersect_def Int_def by (simp add: Int_def iso_member) auto |
|
203 |
||
204 |
lemma iso_subtract: |
|
205 |
fixes ys |
|
206 |
assumes distnct: "distinct ys" |
|
|
21385
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
207 |
shows "set (subtract xs ys) = minus_set (set xs) (set ys)" |
| 19791 | 208 |
and "distinct (subtract xs ys)" |
|
21385
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
209 |
unfolding subtract_def minus_set_def |
|
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
210 |
using distnct by (induct xs arbitrary: ys) auto |
| 19791 | 211 |
|
212 |
lemma iso_map_distinct: |
|
213 |
"set (map_distinct f xs) = image f (set xs)" |
|
214 |
unfolding map_distinct_def by (induct xs) (simp_all add: iso_insert) |
|
215 |
||
216 |
lemma iso_unions: |
|
217 |
"set (unions xss) = \<Union> set (map set xss)" |
|
218 |
unfolding unions_def proof (induct xss) |
|
219 |
case Nil show ?case by simp |
|
220 |
next |
|
221 |
case (Cons xs xss) thus ?case by (induct xs) (simp_all add: iso_insert) |
|
222 |
qed |
|
223 |
||
224 |
lemma iso_intersects: |
|
225 |
"set (intersects (xs#xss)) = \<Inter> set (map set (xs#xss))" |
|
226 |
by (induct xss) (simp_all add: Int_def iso_member, auto) |
|
227 |
||
228 |
lemma iso_UNION: |
|
229 |
"set (map_union xs f) = UNION (set xs) (set o f)" |
|
230 |
unfolding map_union_def iso_unions by simp |
|
231 |
||
232 |
lemma iso_INTER: |
|
233 |
"set (map_inter (x#xs) f) = INTER (set (x#xs)) (set o f)" |
|
234 |
unfolding map_inter_def iso_intersects by (induct xs) (simp_all add: iso_member, auto) |
|
235 |
||
236 |
definition |
|
|
21404
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
wenzelm
parents:
21385
diff
changeset
|
237 |
Blall :: "'a list \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> bool" where
|
| 19791 | 238 |
"Blall = flip list_all" |
|
21404
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
wenzelm
parents:
21385
diff
changeset
|
239 |
definition |
|
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
wenzelm
parents:
21385
diff
changeset
|
240 |
Blex :: "'a list \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> bool" where
|
| 19791 | 241 |
"Blex = flip list_ex" |
242 |
||
243 |
lemma iso_Ball: |
|
244 |
"Blall xs f = Ball (set xs) f" |
|
245 |
unfolding Blall_def flip_def by (induct xs) simp_all |
|
246 |
||
247 |
lemma iso_Bex: |
|
248 |
"Blex xs f = Bex (set xs) f" |
|
249 |
unfolding Blex_def flip_def by (induct xs) simp_all |
|
250 |
||
|
21385
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
251 |
lemma iso_filter: |
|
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
252 |
"set (filter P xs) = filter_set P (set xs)" |
|
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
253 |
unfolding filter_set_def by (induct xs) auto |
| 19791 | 254 |
|
255 |
section {* code generator setup *}
|
|
256 |
||
| 21008 | 257 |
ML {*
|
258 |
nonfix inter; |
|
259 |
nonfix union; |
|
260 |
*} |
|
261 |
||
| 21191 | 262 |
code_modulename SML |
263 |
ExecutableSet List |
|
|
21385
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
264 |
Set List |
|
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
265 |
|
|
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
266 |
code_modulename Haskell |
|
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
267 |
ExecutableSet List |
|
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
268 |
Set List |
| 20934 | 269 |
|
| 21063 | 270 |
definition [code inline]: |
| 20934 | 271 |
"empty_list = []" |
272 |
||
273 |
lemma [code func]: |
|
274 |
"insert (x \<Colon> 'a\<Colon>eq) = insert x" .. |
|
275 |
||
276 |
lemma [code func]: |
|
277 |
"(xs \<Colon> 'a\<Colon>eq set) \<union> ys = xs \<union> ys" .. |
|
278 |
||
279 |
lemma [code func]: |
|
280 |
"(xs \<Colon> 'a\<Colon>eq set) \<inter> ys = xs \<inter> ys" .. |
|
281 |
||
|
21385
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
282 |
lemma [code func]: |
|
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
283 |
"minus_set xs = minus_set (xs \<Colon> 'a\<Colon>eq set)" .. |
| 20934 | 284 |
|
285 |
lemma [code func]: |
|
286 |
"image (f \<Colon> 'a \<Rightarrow> 'b\<Colon>eq) = image f" .. |
|
287 |
||
288 |
lemma [code func]: |
|
289 |
"UNION xs (f \<Colon> 'a \<Rightarrow> 'b\<Colon>eq set) = UNION xs f" .. |
|
290 |
||
291 |
lemma [code func]: |
|
292 |
"INTER xs (f \<Colon> 'a \<Rightarrow> 'b\<Colon>eq set) = INTER xs f" .. |
|
293 |
||
294 |
lemma [code func]: |
|
295 |
"Ball (xs \<Colon> 'a\<Colon>type set) = Ball xs" .. |
|
296 |
||
297 |
lemma [code func]: |
|
298 |
"Bex (xs \<Colon> 'a\<Colon>type set) = Bex xs" .. |
|
299 |
||
|
21385
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
300 |
lemma [code func]: |
|
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
301 |
"filter_set P (xs \<Colon> 'a\<Colon>type set) = filter_set P xs" .. |
|
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
302 |
|
| 20934 | 303 |
code_abstype "'a set" "'a list" where |
| 21115 | 304 |
"{}" \<equiv> empty_list
|
| 20934 | 305 |
insert \<equiv> insertl |
306 |
"op \<union>" \<equiv> unionl |
|
307 |
"op \<inter>" \<equiv> intersect |
|
|
21385
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
308 |
minus_set \<equiv> subtract |
| 20934 | 309 |
image \<equiv> map_distinct |
310 |
Union \<equiv> unions |
|
311 |
Inter \<equiv> intersects |
|
312 |
UNION \<equiv> map_union |
|
313 |
INTER \<equiv> map_inter |
|
314 |
Ball \<equiv> Blall |
|
315 |
Bex \<equiv> Blex |
|
|
21385
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
316 |
filter_set \<equiv> filter |
| 20934 | 317 |
|
|
21385
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
318 |
code_gen "{}" insert "op \<union>" "op \<inter>" minus_set
|
|
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
319 |
image Union Inter UNION INTER Ball Bex filter_set (SML -) |
| 20934 | 320 |
|
321 |
||
| 19791 | 322 |
subsection {* type serializations *}
|
323 |
||
| 17632 | 324 |
types_code |
325 |
set ("_ list")
|
|
326 |
attach (term_of) {*
|
|
327 |
fun term_of_set f T [] = Const ("{}", Type ("set", [T]))
|
|
328 |
| term_of_set f T (x :: xs) = Const ("insert",
|
|
329 |
T --> Type ("set", [T]) --> Type ("set", [T])) $ f x $ term_of_set f T xs;
|
|
330 |
*} |
|
331 |
attach (test) {*
|
|
332 |
fun gen_set' aG i j = frequency |
|
333 |
[(i, fn () => aG j :: gen_set' aG (i-1) j), (1, fn () => [])] () |
|
334 |
and gen_set aG i = gen_set' aG i i; |
|
335 |
*} |
|
336 |
||
| 19791 | 337 |
|
338 |
subsection {* const serializations *}
|
|
| 18702 | 339 |
|
| 17632 | 340 |
consts_code |
341 |
"{}" ("[]")
|
|
| 19791 | 342 |
"insert" ("{*insertl*}")
|
343 |
"op Un" ("{*unionl*}")
|
|
344 |
"op Int" ("{*intersect*}")
|
|
345 |
"HOL.minus" :: "'a set \<Rightarrow> 'a set \<Rightarrow> 'a set" |
|
346 |
("{*flip subtract*}")
|
|
347 |
"image" ("{*map_distinct*}")
|
|
348 |
"Union" ("{*unions*}")
|
|
349 |
"Inter" ("{*intersects*}")
|
|
350 |
"UNION" ("{*map_union*}")
|
|
351 |
"INTER" ("{*map_inter*}")
|
|
352 |
"Ball" ("{*Blall*}")
|
|
353 |
"Bex" ("{*Blex*}")
|
|
|
21385
cf398bb8a8be
added filter_set; adaptions to more strict type discipline for code lemmas
haftmann
parents:
21323
diff
changeset
|
354 |
"filter_set" ("{*filter*}")
|
| 17632 | 355 |
|
356 |
end |