equal
deleted
inserted
replaced
7 |
7 |
8 theory ExecutableSet |
8 theory ExecutableSet |
9 imports Main |
9 imports Main |
10 begin |
10 begin |
11 |
11 |
12 section {* Definitional rewrites *} |
12 subsection {* Definitional rewrites *} |
13 |
13 |
14 instance set :: (eq) eq .. |
14 instance set :: (eq) eq .. |
15 |
15 |
16 lemma [code target: Set]: |
16 lemma [code target: Set]: |
17 "A = B \<longleftrightarrow> A \<subseteq> B \<and> B \<subseteq> A" |
17 "A = B \<longleftrightarrow> A \<subseteq> B \<and> B \<subseteq> A" |
38 "filter_set P xs = {x\<in>xs. P x}" |
38 "filter_set P xs = {x\<in>xs. P x}" |
39 |
39 |
40 lemmas [symmetric, code inline] = filter_set_def |
40 lemmas [symmetric, code inline] = filter_set_def |
41 |
41 |
42 |
42 |
43 section {* Operations on lists *} |
43 subsection {* Operations on lists *} |
44 |
44 |
45 subsection {* Basic definitions *} |
45 subsubsection {* Basic definitions *} |
46 |
46 |
47 definition |
47 definition |
48 flip :: "('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> 'b \<Rightarrow> 'a \<Rightarrow> 'c" where |
48 flip :: "('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> 'b \<Rightarrow> 'a \<Rightarrow> 'c" where |
49 "flip f a b = f b a" |
49 "flip f a b = f b a" |
50 |
50 |
105 lemma foldr_remove1_empty [simp]: |
105 lemma foldr_remove1_empty [simp]: |
106 "foldr remove1 xs [] = []" |
106 "foldr remove1 xs [] = []" |
107 by (induct xs) simp_all |
107 by (induct xs) simp_all |
108 |
108 |
109 |
109 |
110 subsection {* Derived definitions *} |
110 subsubsection {* Derived definitions *} |
111 |
111 |
112 function unionl :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list" |
112 function unionl :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list" |
113 where |
113 where |
114 "unionl [] ys = ys" |
114 "unionl [] ys = ys" |
115 | "unionl xs ys = foldr insertl xs ys" |
115 | "unionl xs ys = foldr insertl xs ys" |
167 definition |
167 definition |
168 map_inter :: "'a list \<Rightarrow> ('a \<Rightarrow> 'b list) \<Rightarrow> 'b list" where |
168 map_inter :: "'a list \<Rightarrow> ('a \<Rightarrow> 'b list) \<Rightarrow> 'b list" where |
169 "map_inter xs f = intersects (map f xs)" |
169 "map_inter xs f = intersects (map f xs)" |
170 |
170 |
171 |
171 |
172 section {* Isomorphism proofs *} |
172 subsection {* Isomorphism proofs *} |
173 |
173 |
174 lemma iso_member: |
174 lemma iso_member: |
175 "member xs x \<longleftrightarrow> x \<in> set xs" |
175 "member xs x \<longleftrightarrow> x \<in> set xs" |
176 unfolding member_def mem_iff .. |
176 unfolding member_def mem_iff .. |
177 |
177 |
246 |
246 |
247 lemma iso_filter: |
247 lemma iso_filter: |
248 "set (filter P xs) = filter_set P (set xs)" |
248 "set (filter P xs) = filter_set P (set xs)" |
249 unfolding filter_set_def by (induct xs) auto |
249 unfolding filter_set_def by (induct xs) auto |
250 |
250 |
251 section {* code generator setup *} |
251 subsection {* code generator setup *} |
252 |
252 |
253 ML {* |
253 ML {* |
254 nonfix inter; |
254 nonfix inter; |
255 nonfix union; |
255 nonfix union; |
256 nonfix subset; |
256 nonfix subset; |
315 Ball \<equiv> Blall |
315 Ball \<equiv> Blall |
316 Bex \<equiv> Blex |
316 Bex \<equiv> Blex |
317 filter_set \<equiv> filter |
317 filter_set \<equiv> filter |
318 |
318 |
319 |
319 |
320 subsection {* type serializations *} |
320 subsubsection {* type serializations *} |
321 |
321 |
322 types_code |
322 types_code |
323 set ("_ list") |
323 set ("_ list") |
324 attach (term_of) {* |
324 attach (term_of) {* |
325 fun term_of_set f T [] = Const ("{}", Type ("set", [T])) |
325 fun term_of_set f T [] = Const ("{}", Type ("set", [T])) |
331 [(i, fn () => aG j :: gen_set' aG (i-1) j), (1, fn () => [])] () |
331 [(i, fn () => aG j :: gen_set' aG (i-1) j), (1, fn () => [])] () |
332 and gen_set aG i = gen_set' aG i i; |
332 and gen_set aG i = gen_set' aG i i; |
333 *} |
333 *} |
334 |
334 |
335 |
335 |
336 subsection {* const serializations *} |
336 subsubsection {* const serializations *} |
337 |
337 |
338 consts_code |
338 consts_code |
339 "{}" ("[]") |
339 "{}" ("[]") |
340 "insert" ("{*insertl*}") |
340 "insert" ("{*insertl*}") |
341 "op Un" ("{*unionl*}") |
341 "op Un" ("{*unionl*}") |