1823
|
1 |
(* Title: Quotient.thy
|
|
2 |
Author: Cezary Kaliszyk
|
|
3 |
Author: Christian Urban
|
|
4 |
|
|
5 |
provides a reasoning infrastructure for the type of finite sets
|
|
6 |
*)
|
1518
|
7 |
theory FSet
|
|
8 |
imports Quotient Quotient_List List
|
|
9 |
begin
|
|
10 |
|
1909
|
11 |
text {* Definiton of List relation and the quotient type *}
|
|
12 |
|
1518
|
13 |
fun
|
|
14 |
list_eq :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool" (infix "\<approx>" 50)
|
|
15 |
where
|
|
16 |
"list_eq xs ys = (\<forall>x. x \<in> set xs \<longleftrightarrow> x \<in> set ys)"
|
|
17 |
|
|
18 |
lemma list_eq_equivp:
|
|
19 |
shows "equivp list_eq"
|
1909
|
20 |
unfolding equivp_reflp_symp_transp
|
1889
|
21 |
unfolding reflp_def symp_def transp_def
|
|
22 |
by auto
|
|
23 |
|
1909
|
24 |
quotient_type
|
|
25 |
'a fset = "'a list" / "list_eq"
|
|
26 |
by (rule list_eq_equivp)
|
|
27 |
|
|
28 |
text {* Raw definitions *}
|
|
29 |
|
1889
|
30 |
definition
|
|
31 |
memb :: "'a \<Rightarrow> 'a list \<Rightarrow> bool"
|
|
32 |
where
|
|
33 |
"memb x xs \<equiv> x \<in> set xs"
|
|
34 |
|
|
35 |
definition
|
|
36 |
sub_list :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool"
|
|
37 |
where
|
|
38 |
"sub_list xs ys \<equiv> (\<forall>x. x \<in> set xs \<longrightarrow> x \<in> set ys)"
|
|
39 |
|
1909
|
40 |
fun
|
|
41 |
fcard_raw :: "'a list \<Rightarrow> nat"
|
|
42 |
where
|
|
43 |
fcard_raw_nil: "fcard_raw [] = 0"
|
|
44 |
| fcard_raw_cons: "fcard_raw (x # xs) = (if memb x xs then fcard_raw xs else Suc (fcard_raw xs))"
|
1518
|
45 |
|
1909
|
46 |
primrec
|
|
47 |
finter_raw :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list"
|
|
48 |
where
|
|
49 |
"finter_raw [] l = []"
|
|
50 |
| "finter_raw (h # t) l =
|
|
51 |
(if memb h l then h # (finter_raw t l) else finter_raw t l)"
|
1893
|
52 |
|
1909
|
53 |
fun
|
|
54 |
delete_raw :: "'a list \<Rightarrow> 'a \<Rightarrow> 'a list"
|
|
55 |
where
|
|
56 |
"delete_raw [] x = []"
|
|
57 |
| "delete_raw (a # A) x = (if (a = x) then delete_raw A x else a # (delete_raw A x))"
|
|
58 |
|
|
59 |
definition
|
|
60 |
rsp_fold
|
|
61 |
where
|
|
62 |
"rsp_fold f = (\<forall>u v w. (f u (f v w) = f v (f u w)))"
|
1893
|
63 |
|
1909
|
64 |
primrec
|
|
65 |
ffold_raw :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a list \<Rightarrow> 'b"
|
|
66 |
where
|
|
67 |
"ffold_raw f z [] = z"
|
|
68 |
| "ffold_raw f z (a # A) =
|
|
69 |
(if (rsp_fold f) then
|
|
70 |
if memb a A then ffold_raw f z A
|
|
71 |
else f a (ffold_raw f z A)
|
|
72 |
else z)"
|
|
73 |
|
|
74 |
text {* Respectfullness *}
|
1893
|
75 |
|
1895
|
76 |
lemma [quot_respect]:
|
|
77 |
shows "(op \<approx> ===> op \<approx> ===> op \<approx>) op @ op @"
|
|
78 |
by auto
|
|
79 |
|
1909
|
80 |
lemma [quot_respect]:
|
|
81 |
shows "(op \<approx> ===> op \<approx> ===> op =) sub_list sub_list"
|
|
82 |
by (auto simp add: sub_list_def)
|
|
83 |
|
|
84 |
lemma memb_rsp[quot_respect]:
|
|
85 |
shows "(op = ===> op \<approx> ===> op =) memb memb"
|
|
86 |
by (auto simp add: memb_def)
|
|
87 |
|
|
88 |
lemma nil_rsp[quot_respect]:
|
|
89 |
shows "[] \<approx> []"
|
|
90 |
by simp
|
|
91 |
|
|
92 |
lemma cons_rsp[quot_respect]:
|
|
93 |
shows "(op = ===> op \<approx> ===> op \<approx>) op # op #"
|
|
94 |
by simp
|
|
95 |
|
|
96 |
lemma map_rsp[quot_respect]:
|
|
97 |
shows "(op = ===> op \<approx> ===> op \<approx>) map map"
|
|
98 |
by auto
|
|
99 |
|
|
100 |
lemma set_rsp[quot_respect]:
|
|
101 |
"(op \<approx> ===> op =) set set"
|
|
102 |
by auto
|
|
103 |
|
|
104 |
lemma list_equiv_rsp[quot_respect]:
|
|
105 |
shows "(op \<approx> ===> op \<approx> ===> op =) op \<approx> op \<approx>"
|
|
106 |
by auto
|
|
107 |
|
|
108 |
lemma not_memb_nil:
|
|
109 |
shows "\<not> memb x []"
|
|
110 |
by (simp add: memb_def)
|
|
111 |
|
|
112 |
lemma memb_cons_iff:
|
|
113 |
shows "memb x (y # xs) = (x = y \<or> memb x xs)"
|
|
114 |
by (induct xs) (auto simp add: memb_def)
|
|
115 |
|
|
116 |
lemma memb_finter_raw:
|
|
117 |
"memb x (finter_raw xs ys) \<longleftrightarrow> memb x xs \<and> memb x ys"
|
|
118 |
by (induct xs) (auto simp add: not_memb_nil memb_cons_iff)
|
|
119 |
|
|
120 |
lemma [quot_respect]:
|
|
121 |
"(op \<approx> ===> op \<approx> ===> op \<approx>) finter_raw finter_raw"
|
|
122 |
by (simp add: memb_def[symmetric] memb_finter_raw)
|
|
123 |
|
|
124 |
lemma memb_delete_raw:
|
|
125 |
"memb x (delete_raw xs y) = (memb x xs \<and> x \<noteq> y)"
|
|
126 |
by (induct xs arbitrary: x y) (auto simp add: memb_def)
|
|
127 |
|
|
128 |
lemma [quot_respect]:
|
|
129 |
"(op \<approx> ===> op = ===> op \<approx>) delete_raw delete_raw"
|
|
130 |
by (simp add: memb_def[symmetric] memb_delete_raw)
|
|
131 |
|
|
132 |
lemma fcard_raw_gt_0:
|
|
133 |
assumes a: "x \<in> set xs"
|
|
134 |
shows "0 < fcard_raw xs"
|
|
135 |
using a by (induct xs) (auto simp add: memb_def)
|
|
136 |
|
|
137 |
lemma fcard_raw_delete_one:
|
|
138 |
shows "fcard_raw ([x \<leftarrow> xs. x \<noteq> y]) = (if memb y xs then fcard_raw xs - 1 else fcard_raw xs)"
|
|
139 |
by (induct xs) (auto dest: fcard_raw_gt_0 simp add: memb_def)
|
|
140 |
|
|
141 |
lemma fcard_raw_rsp_aux:
|
|
142 |
assumes a: "xs \<approx> ys"
|
|
143 |
shows "fcard_raw xs = fcard_raw ys"
|
|
144 |
using a
|
|
145 |
apply (induct xs arbitrary: ys)
|
|
146 |
apply (auto simp add: memb_def)
|
|
147 |
apply (subgoal_tac "\<forall>x. (x \<in> set xs) = (x \<in> set ys)")
|
|
148 |
apply (auto)
|
|
149 |
apply (drule_tac x="x" in spec)
|
|
150 |
apply (blast)
|
|
151 |
apply (drule_tac x="[x \<leftarrow> ys. x \<noteq> a]" in meta_spec)
|
|
152 |
apply (simp add: fcard_raw_delete_one memb_def)
|
|
153 |
apply (case_tac "a \<in> set ys")
|
|
154 |
apply (simp only: if_True)
|
|
155 |
apply (subgoal_tac "\<forall>x. (x \<in> set xs) = (x \<in> set ys \<and> x \<noteq> a)")
|
|
156 |
apply (drule Suc_pred'[OF fcard_raw_gt_0])
|
|
157 |
apply (auto)
|
|
158 |
done
|
|
159 |
|
|
160 |
lemma fcard_raw_rsp[quot_respect]:
|
|
161 |
shows "(op \<approx> ===> op =) fcard_raw fcard_raw"
|
|
162 |
by (simp add: fcard_raw_rsp_aux)
|
|
163 |
|
|
164 |
lemma memb_absorb:
|
|
165 |
shows "memb x xs \<Longrightarrow> x # xs \<approx> xs"
|
|
166 |
by (induct xs) (auto simp add: memb_def)
|
|
167 |
|
|
168 |
lemma none_memb_nil:
|
|
169 |
"(\<forall>x. \<not> memb x xs) = (xs \<approx> [])"
|
|
170 |
by (simp add: memb_def)
|
|
171 |
|
|
172 |
lemma not_memb_delete_raw_ident:
|
|
173 |
shows "\<not> memb x xs \<Longrightarrow> delete_raw xs x = xs"
|
|
174 |
by (induct xs) (auto simp add: memb_def)
|
|
175 |
|
|
176 |
lemma memb_commute_ffold_raw:
|
|
177 |
"rsp_fold f \<Longrightarrow> memb h b \<Longrightarrow> ffold_raw f z b = f h (ffold_raw f z (delete_raw b h))"
|
|
178 |
apply (induct b)
|
|
179 |
apply (simp_all add: not_memb_nil)
|
|
180 |
apply (auto)
|
|
181 |
apply (simp_all add: memb_delete_raw not_memb_delete_raw_ident rsp_fold_def memb_cons_iff)
|
|
182 |
done
|
|
183 |
|
|
184 |
lemma ffold_raw_rsp_pre:
|
|
185 |
"\<forall>e. memb e a = memb e b \<Longrightarrow> ffold_raw f z a = ffold_raw f z b"
|
|
186 |
apply (induct a arbitrary: b)
|
|
187 |
apply (simp add: memb_absorb memb_def none_memb_nil)
|
|
188 |
apply (simp)
|
|
189 |
apply (rule conjI)
|
|
190 |
apply (rule_tac [!] impI)
|
|
191 |
apply (rule_tac [!] conjI)
|
|
192 |
apply (rule_tac [!] impI)
|
|
193 |
apply (subgoal_tac "\<forall>e. memb e a2 = memb e b")
|
|
194 |
apply (simp)
|
|
195 |
apply (simp add: memb_cons_iff memb_def)
|
|
196 |
apply (auto)[1]
|
|
197 |
apply (drule_tac x="e" in spec)
|
|
198 |
apply (blast)
|
|
199 |
apply (case_tac b)
|
|
200 |
apply (simp_all)
|
|
201 |
apply (subgoal_tac "ffold_raw f z b = f a1 (ffold_raw f z (delete_raw b a1))")
|
|
202 |
apply (simp only:)
|
|
203 |
apply (rule_tac f="f a1" in arg_cong)
|
|
204 |
apply (subgoal_tac "\<forall>e. memb e a2 = memb e (delete_raw b a1)")
|
|
205 |
apply (simp)
|
|
206 |
apply (simp add: memb_delete_raw)
|
|
207 |
apply (auto simp add: memb_cons_iff)[1]
|
|
208 |
apply (erule memb_commute_ffold_raw)
|
|
209 |
apply (drule_tac x="a1" in spec)
|
|
210 |
apply (simp add: memb_cons_iff)
|
|
211 |
apply (simp add: memb_cons_iff)
|
|
212 |
apply (case_tac b)
|
|
213 |
apply (simp_all)
|
|
214 |
done
|
|
215 |
|
|
216 |
lemma [quot_respect]:
|
|
217 |
"(op = ===> op = ===> op \<approx> ===> op =) ffold_raw ffold_raw"
|
|
218 |
by (simp add: memb_def[symmetric] ffold_raw_rsp_pre)
|
|
219 |
|
|
220 |
text {* Distributive lattice with bot *}
|
|
221 |
|
1893
|
222 |
lemma sub_list_not_eq:
|
|
223 |
"(sub_list x y \<and> \<not> list_eq x y) = (sub_list x y \<and> \<not> sub_list y x)"
|
|
224 |
by (auto simp add: sub_list_def)
|
|
225 |
|
|
226 |
lemma sub_list_refl:
|
|
227 |
"sub_list x x"
|
|
228 |
by (simp add: sub_list_def)
|
|
229 |
|
|
230 |
lemma sub_list_trans:
|
|
231 |
"sub_list x y \<Longrightarrow> sub_list y z \<Longrightarrow> sub_list x z"
|
|
232 |
by (simp add: sub_list_def)
|
|
233 |
|
|
234 |
lemma sub_list_empty:
|
|
235 |
"sub_list [] x"
|
|
236 |
by (simp add: sub_list_def)
|
|
237 |
|
1905
|
238 |
lemma sub_list_append_left:
|
|
239 |
"sub_list x (x @ y)"
|
|
240 |
by (simp add: sub_list_def)
|
|
241 |
|
|
242 |
lemma sub_list_append_right:
|
|
243 |
"sub_list y (x @ y)"
|
|
244 |
by (simp add: sub_list_def)
|
|
245 |
|
|
246 |
lemma sub_list_inter_left:
|
|
247 |
shows "sub_list (finter_raw x y) x"
|
|
248 |
by (simp add: sub_list_def memb_def[symmetric] memb_finter_raw)
|
|
249 |
|
|
250 |
lemma sub_list_inter_right:
|
|
251 |
shows "sub_list (finter_raw x y) y"
|
|
252 |
by (simp add: sub_list_def memb_def[symmetric] memb_finter_raw)
|
|
253 |
|
|
254 |
lemma sub_list_list_eq:
|
|
255 |
"sub_list x y \<Longrightarrow> sub_list y x \<Longrightarrow> list_eq x y"
|
|
256 |
unfolding sub_list_def list_eq.simps by blast
|
|
257 |
|
|
258 |
lemma sub_list_append:
|
|
259 |
"sub_list y x \<Longrightarrow> sub_list z x \<Longrightarrow> sub_list (y @ z) x"
|
|
260 |
unfolding sub_list_def by auto
|
|
261 |
|
|
262 |
lemma sub_list_inter:
|
|
263 |
"sub_list x y \<Longrightarrow> sub_list x z \<Longrightarrow> sub_list x (finter_raw y z)"
|
|
264 |
by (simp add: sub_list_def memb_def[symmetric] memb_finter_raw)
|
|
265 |
|
|
266 |
lemma append_inter_distrib:
|
|
267 |
"x @ (finter_raw y z) \<approx> finter_raw (x @ y) (x @ z)"
|
|
268 |
apply (induct x)
|
|
269 |
apply (simp_all add: memb_def)
|
|
270 |
apply (simp add: memb_def[symmetric] memb_finter_raw)
|
1909
|
271 |
by (auto simp add: memb_def)
|
1905
|
272 |
|
|
273 |
instantiation fset :: (type) "{bot,distrib_lattice}"
|
1893
|
274 |
begin
|
|
275 |
|
|
276 |
quotient_definition
|
|
277 |
"bot :: 'a fset" is "[] :: 'a list"
|
|
278 |
|
|
279 |
abbreviation
|
|
280 |
fempty ("{||}")
|
|
281 |
where
|
|
282 |
"{||} \<equiv> bot :: 'a fset"
|
|
283 |
|
|
284 |
quotient_definition
|
|
285 |
"less_eq_fset \<Colon> ('a fset \<Rightarrow> 'a fset \<Rightarrow> bool)"
|
|
286 |
is
|
|
287 |
"sub_list \<Colon> ('a list \<Rightarrow> 'a list \<Rightarrow> bool)"
|
|
288 |
|
|
289 |
abbreviation
|
|
290 |
f_subset_eq :: "'a fset \<Rightarrow> 'a fset \<Rightarrow> bool" (infix "|\<subseteq>|" 50)
|
|
291 |
where
|
|
292 |
"xs |\<subseteq>| ys \<equiv> xs \<le> ys"
|
|
293 |
|
|
294 |
definition
|
|
295 |
less_fset:
|
|
296 |
"(xs :: 'a fset) < ys \<equiv> xs \<le> ys \<and> xs \<noteq> ys"
|
|
297 |
|
|
298 |
abbreviation
|
|
299 |
f_subset :: "'a fset \<Rightarrow> 'a fset \<Rightarrow> bool" (infix "|\<subset>|" 50)
|
|
300 |
where
|
|
301 |
"xs |\<subset>| ys \<equiv> xs < ys"
|
|
302 |
|
1895
|
303 |
quotient_definition
|
|
304 |
"sup \<Colon> ('a fset \<Rightarrow> 'a fset \<Rightarrow> 'a fset)"
|
|
305 |
is
|
|
306 |
"(op @) \<Colon> ('a list \<Rightarrow> 'a list \<Rightarrow> 'a list)"
|
|
307 |
|
|
308 |
abbreviation
|
|
309 |
funion (infixl "|\<union>|" 65)
|
|
310 |
where
|
|
311 |
"xs |\<union>| ys \<equiv> sup (xs :: 'a fset) ys"
|
|
312 |
|
1905
|
313 |
quotient_definition
|
|
314 |
"inf \<Colon> ('a fset \<Rightarrow> 'a fset \<Rightarrow> 'a fset)"
|
|
315 |
is
|
|
316 |
"finter_raw \<Colon> ('a list \<Rightarrow> 'a list \<Rightarrow> 'a list)"
|
|
317 |
|
|
318 |
abbreviation
|
|
319 |
finter (infixl "|\<inter>|" 65)
|
|
320 |
where
|
|
321 |
"xs |\<inter>| ys \<equiv> inf (xs :: 'a fset) ys"
|
|
322 |
|
1895
|
323 |
instance
|
|
324 |
proof
|
1905
|
325 |
fix x y z :: "'a fset"
|
|
326 |
show "(x |\<subset>| y) = (x |\<subseteq>| y \<and> \<not> y |\<subseteq>| x)"
|
|
327 |
unfolding less_fset by (lifting sub_list_not_eq)
|
|
328 |
show "x |\<subseteq>| x" by (lifting sub_list_refl)
|
|
329 |
show "{||} |\<subseteq>| x" by (lifting sub_list_empty)
|
1895
|
330 |
show "x |\<subseteq>| x |\<union>| y" by (lifting sub_list_append_left)
|
|
331 |
show "y |\<subseteq>| x |\<union>| y" by (lifting sub_list_append_right)
|
1905
|
332 |
show "x |\<inter>| y |\<subseteq>| x" by (lifting sub_list_inter_left)
|
|
333 |
show "x |\<inter>| y |\<subseteq>| y" by (lifting sub_list_inter_right)
|
|
334 |
show "x |\<union>| (y |\<inter>| z) = x |\<union>| y |\<inter>| (x |\<union>| z)" by (lifting append_inter_distrib)
|
|
335 |
next
|
|
336 |
fix x y z :: "'a fset"
|
|
337 |
assume a: "x |\<subseteq>| y"
|
|
338 |
assume b: "y |\<subseteq>| z"
|
|
339 |
show "x |\<subseteq>| z" using a b by (lifting sub_list_trans)
|
1895
|
340 |
next
|
|
341 |
fix x y :: "'a fset"
|
|
342 |
assume a: "x |\<subseteq>| y"
|
|
343 |
assume b: "y |\<subseteq>| x"
|
|
344 |
show "x = y" using a b by (lifting sub_list_list_eq)
|
|
345 |
next
|
|
346 |
fix x y z :: "'a fset"
|
|
347 |
assume a: "y |\<subseteq>| x"
|
|
348 |
assume b: "z |\<subseteq>| x"
|
|
349 |
show "y |\<union>| z |\<subseteq>| x" using a b by (lifting sub_list_append)
|
1905
|
350 |
next
|
|
351 |
fix x y z :: "'a fset"
|
|
352 |
assume a: "x |\<subseteq>| y"
|
|
353 |
assume b: "x |\<subseteq>| z"
|
|
354 |
show "x |\<subseteq>| y |\<inter>| z" using a b by (lifting sub_list_inter)
|
1895
|
355 |
qed
|
1905
|
356 |
|
1893
|
357 |
end
|
|
358 |
|
1909
|
359 |
section {* Finsert and Membership *}
|
1518
|
360 |
|
|
361 |
quotient_definition
|
1893
|
362 |
"finsert :: 'a \<Rightarrow> 'a fset \<Rightarrow> 'a fset"
|
1518
|
363 |
is "op #"
|
|
364 |
|
|
365 |
syntax
|
|
366 |
"@Finset" :: "args => 'a fset" ("{|(_)|}")
|
|
367 |
|
|
368 |
translations
|
|
369 |
"{|x, xs|}" == "CONST finsert x {|xs|}"
|
|
370 |
"{|x|}" == "CONST finsert x {||}"
|
|
371 |
|
|
372 |
quotient_definition
|
|
373 |
fin ("_ |\<in>| _" [50, 51] 50)
|
|
374 |
where
|
1816
|
375 |
"fin :: 'a \<Rightarrow> 'a fset \<Rightarrow> bool" is "memb"
|
1518
|
376 |
|
|
377 |
abbreviation
|
|
378 |
fnotin :: "'a \<Rightarrow> 'a fset \<Rightarrow> bool" ("_ |\<notin>| _" [50, 51] 50)
|
|
379 |
where
|
1860
|
380 |
"x |\<notin>| S \<equiv> \<not> (x |\<in>| S)"
|
1518
|
381 |
|
1816
|
382 |
section {* Augmenting an fset -- @{const finsert} *}
|
1518
|
383 |
|
1892
|
384 |
lemma nil_not_cons:
|
|
385 |
shows "\<not> ([] \<approx> x # xs)"
|
|
386 |
and "\<not> (x # xs \<approx> [])"
|
|
387 |
by auto
|
|
388 |
|
1878
|
389 |
lemma no_memb_nil:
|
|
390 |
"(\<forall>x. \<not> memb x xs) = (xs = [])"
|
|
391 |
by (simp add: memb_def)
|
|
392 |
|
1518
|
393 |
lemma memb_consI1:
|
|
394 |
shows "memb x (x # xs)"
|
|
395 |
by (simp add: memb_def)
|
|
396 |
|
|
397 |
lemma memb_consI2:
|
|
398 |
shows "memb x xs \<Longrightarrow> memb x (y # xs)"
|
|
399 |
by (simp add: memb_def)
|
|
400 |
|
|
401 |
section {* Singletons *}
|
|
402 |
|
|
403 |
lemma singleton_list_eq:
|
|
404 |
shows "[x] \<approx> [y] \<longleftrightarrow> x = y"
|
|
405 |
by (simp add: id_simps) auto
|
|
406 |
|
1892
|
407 |
section {* sub_list *}
|
|
408 |
|
|
409 |
lemma sub_list_cons:
|
|
410 |
"sub_list (x # xs) ys = (memb x ys \<and> sub_list xs ys)"
|
|
411 |
by (auto simp add: memb_def sub_list_def)
|
|
412 |
|
1518
|
413 |
section {* Cardinality of finite sets *}
|
|
414 |
|
|
415 |
quotient_definition
|
|
416 |
"fcard :: 'a fset \<Rightarrow> nat"
|
|
417 |
is
|
|
418 |
"fcard_raw"
|
|
419 |
|
1813
|
420 |
lemma fcard_raw_0:
|
1860
|
421 |
shows "fcard_raw xs = 0 \<longleftrightarrow> xs \<approx> []"
|
1821
|
422 |
by (induct xs) (auto simp add: memb_def)
|
1813
|
423 |
|
1518
|
424 |
|
1813
|
425 |
lemma fcard_raw_not_memb:
|
1860
|
426 |
shows "\<not> memb x xs \<longleftrightarrow> fcard_raw (x # xs) = Suc (fcard_raw xs)"
|
1813
|
427 |
by auto
|
|
428 |
|
|
429 |
lemma fcard_raw_suc:
|
1860
|
430 |
assumes a: "fcard_raw xs = Suc n"
|
|
431 |
shows "\<exists>x ys. \<not> (memb x ys) \<and> xs \<approx> (x # ys) \<and> fcard_raw ys = n"
|
|
432 |
using a
|
|
433 |
by (induct xs) (auto simp add: memb_def split: if_splits)
|
1819
|
434 |
|
1821
|
435 |
lemma singleton_fcard_1:
|
1860
|
436 |
shows "set xs = {x} \<Longrightarrow> fcard_raw xs = 1"
|
|
437 |
by (induct xs) (auto simp add: memb_def subset_insert)
|
1819
|
438 |
|
|
439 |
lemma fcard_raw_1:
|
1823
|
440 |
shows "fcard_raw xs = 1 \<longleftrightarrow> (\<exists>x. xs \<approx> [x])"
|
|
441 |
apply (auto dest!: fcard_raw_suc)
|
1819
|
442 |
apply (simp add: fcard_raw_0)
|
1821
|
443 |
apply (rule_tac x="x" in exI)
|
1819
|
444 |
apply simp
|
1821
|
445 |
apply (subgoal_tac "set xs = {x}")
|
1860
|
446 |
apply (drule singleton_fcard_1)
|
1819
|
447 |
apply auto
|
1813
|
448 |
done
|
|
449 |
|
1878
|
450 |
lemma fcard_raw_suc_memb:
|
|
451 |
assumes a: "fcard_raw A = Suc n"
|
|
452 |
shows "\<exists>a. memb a A"
|
|
453 |
using a
|
|
454 |
apply (induct A)
|
|
455 |
apply simp
|
|
456 |
apply (rule_tac x="a" in exI)
|
|
457 |
apply (simp add: memb_def)
|
|
458 |
done
|
|
459 |
|
1884
|
460 |
lemma memb_card_not_0:
|
1878
|
461 |
assumes a: "memb a A"
|
|
462 |
shows "\<not>(fcard_raw A = 0)"
|
1883
|
463 |
proof -
|
|
464 |
have "\<not>(\<forall>x. \<not> memb x A)" using a by auto
|
|
465 |
then have "\<not>A \<approx> []" using none_memb_nil[of A] by simp
|
|
466 |
then show ?thesis using fcard_raw_0[of A] by simp
|
|
467 |
qed
|
1878
|
468 |
|
1909
|
469 |
section {* fmap *}
|
1518
|
470 |
|
|
471 |
quotient_definition
|
|
472 |
"fmap :: ('a \<Rightarrow> 'b) \<Rightarrow> 'a fset \<Rightarrow> 'b fset"
|
|
473 |
is
|
|
474 |
"map"
|
|
475 |
|
1813
|
476 |
lemma map_append:
|
1821
|
477 |
"map f (xs @ ys) \<approx> (map f xs) @ (map f ys)"
|
1813
|
478 |
by simp
|
|
479 |
|
1819
|
480 |
lemma memb_append:
|
1823
|
481 |
"memb x (xs @ ys) \<longleftrightarrow> memb x xs \<or> memb x ys"
|
1821
|
482 |
by (induct xs) (simp_all add: not_memb_nil memb_cons_iff)
|
1819
|
483 |
|
1518
|
484 |
lemma cons_left_comm:
|
1821
|
485 |
"x # y # xs \<approx> y # x # xs"
|
|
486 |
by auto
|
1518
|
487 |
|
|
488 |
lemma cons_left_idem:
|
1821
|
489 |
"x # x # xs \<approx> x # xs"
|
|
490 |
by auto
|
1518
|
491 |
|
1819
|
492 |
lemma fset_raw_strong_cases:
|
1822
|
493 |
"(xs = []) \<or> (\<exists>x ys. ((\<not> memb x ys) \<and> (xs \<approx> x # ys)))"
|
1821
|
494 |
apply (induct xs)
|
1518
|
495 |
apply (simp)
|
|
496 |
apply (rule disjI2)
|
|
497 |
apply (erule disjE)
|
|
498 |
apply (rule_tac x="a" in exI)
|
|
499 |
apply (rule_tac x="[]" in exI)
|
1822
|
500 |
apply (simp add: memb_def)
|
1518
|
501 |
apply (erule exE)+
|
1821
|
502 |
apply (case_tac "x = a")
|
1518
|
503 |
apply (rule_tac x="a" in exI)
|
1821
|
504 |
apply (rule_tac x="ys" in exI)
|
1518
|
505 |
apply (simp)
|
1821
|
506 |
apply (rule_tac x="x" in exI)
|
|
507 |
apply (rule_tac x="a # ys" in exI)
|
1822
|
508 |
apply (auto simp add: memb_def)
|
1518
|
509 |
done
|
|
510 |
|
1860
|
511 |
section {* deletion *}
|
|
512 |
|
1819
|
513 |
lemma memb_delete_raw_ident:
|
1860
|
514 |
shows "\<not> memb x (delete_raw xs x)"
|
1821
|
515 |
by (induct xs) (auto simp add: memb_def)
|
1518
|
516 |
|
1819
|
517 |
lemma fset_raw_delete_raw_cases:
|
1821
|
518 |
"xs = [] \<or> (\<exists>x. memb x xs \<and> xs \<approx> x # delete_raw xs x)"
|
|
519 |
by (induct xs) (auto simp add: memb_def)
|
1518
|
520 |
|
1819
|
521 |
lemma fdelete_raw_filter:
|
|
522 |
"delete_raw xs y = [x \<leftarrow> xs. x \<noteq> y]"
|
|
523 |
by (induct xs) simp_all
|
1518
|
524 |
|
1819
|
525 |
lemma fcard_raw_delete:
|
|
526 |
"fcard_raw (delete_raw xs y) = (if memb y xs then fcard_raw xs - 1 else fcard_raw xs)"
|
|
527 |
by (simp add: fdelete_raw_filter fcard_raw_delete_one)
|
1518
|
528 |
|
|
529 |
|
1819
|
530 |
|
1820
|
531 |
|
|
532 |
|
1819
|
533 |
lemma finter_raw_empty:
|
|
534 |
"finter_raw l [] = []"
|
|
535 |
by (induct l) (simp_all add: not_memb_nil)
|
|
536 |
|
1518
|
537 |
section {* Constants on the Quotient Type *}
|
|
538 |
|
|
539 |
quotient_definition
|
|
540 |
"fdelete :: 'a fset \<Rightarrow> 'a \<Rightarrow> 'a fset"
|
|
541 |
is "delete_raw"
|
|
542 |
|
|
543 |
quotient_definition
|
|
544 |
"fset_to_set :: 'a fset \<Rightarrow> 'a set"
|
|
545 |
is "set"
|
|
546 |
|
1819
|
547 |
quotient_definition
|
|
548 |
"ffold :: ('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a fset \<Rightarrow> 'b"
|
|
549 |
is "ffold_raw"
|
|
550 |
|
1821
|
551 |
lemma set_cong:
|
|
552 |
shows "(set x = set y) = (x \<approx> y)"
|
|
553 |
by auto
|
1533
|
554 |
|
|
555 |
lemma inj_map_eq_iff:
|
|
556 |
"inj f \<Longrightarrow> (map f l \<approx> map f m) = (l \<approx> m)"
|
|
557 |
by (simp add: expand_set_eq[symmetric] inj_image_eq_iff)
|
|
558 |
|
1813
|
559 |
quotient_definition
|
|
560 |
"fconcat :: ('a fset) fset \<Rightarrow> 'a fset"
|
|
561 |
is
|
|
562 |
"concat"
|
1533
|
563 |
|
1518
|
564 |
|
1888
|
565 |
text {* alternate formulation with a different decomposition principle
|
|
566 |
and a proof of equivalence *}
|
|
567 |
|
|
568 |
inductive
|
|
569 |
list_eq2
|
|
570 |
where
|
|
571 |
"list_eq2 (a # b # xs) (b # a # xs)"
|
|
572 |
| "list_eq2 [] []"
|
|
573 |
| "list_eq2 xs ys \<Longrightarrow> list_eq2 ys xs"
|
|
574 |
| "list_eq2 (a # a # xs) (a # xs)"
|
|
575 |
| "list_eq2 xs ys \<Longrightarrow> list_eq2 (a # xs) (a # ys)"
|
|
576 |
| "\<lbrakk>list_eq2 xs1 xs2; list_eq2 xs2 xs3\<rbrakk> \<Longrightarrow> list_eq2 xs1 xs3"
|
|
577 |
|
|
578 |
lemma list_eq2_refl:
|
|
579 |
shows "list_eq2 xs xs"
|
|
580 |
by (induct xs) (auto intro: list_eq2.intros)
|
|
581 |
|
|
582 |
lemma cons_delete_list_eq2:
|
|
583 |
shows "list_eq2 (a # (delete_raw A a)) (if memb a A then A else a # A)"
|
|
584 |
apply (induct A)
|
|
585 |
apply (simp add: memb_def list_eq2_refl)
|
|
586 |
apply (case_tac "memb a (aa # A)")
|
|
587 |
apply (simp_all only: memb_cons_iff)
|
|
588 |
apply (case_tac [!] "a = aa")
|
1909
|
589 |
apply (simp_all)
|
1888
|
590 |
apply (case_tac "memb a A")
|
|
591 |
apply (auto simp add: memb_def)[2]
|
|
592 |
apply (metis list_eq2.intros(3) list_eq2.intros(4) list_eq2.intros(5) list_eq2.intros(6))
|
1895
|
593 |
apply (metis list_eq2.intros(1) list_eq2.intros(5) list_eq2.intros(6))
|
1888
|
594 |
apply (auto simp add: list_eq2_refl not_memb_delete_raw_ident)
|
|
595 |
done
|
|
596 |
|
|
597 |
lemma memb_delete_list_eq2:
|
|
598 |
assumes a: "memb e r"
|
|
599 |
shows "list_eq2 (e # delete_raw r e) r"
|
|
600 |
using a cons_delete_list_eq2[of e r]
|
|
601 |
by simp
|
|
602 |
|
1909
|
603 |
lemma delete_raw_rsp:
|
|
604 |
"xs \<approx> ys \<Longrightarrow> delete_raw xs x \<approx> delete_raw ys x"
|
|
605 |
by (simp add: memb_def[symmetric] memb_delete_raw)
|
|
606 |
|
1888
|
607 |
lemma list_eq2_equiv_aux:
|
|
608 |
assumes a: "fcard_raw l = n"
|
|
609 |
and b: "l \<approx> r"
|
|
610 |
shows "list_eq2 l r"
|
|
611 |
using a b
|
|
612 |
proof (induct n arbitrary: l r)
|
|
613 |
case 0
|
|
614 |
have "fcard_raw l = 0" by fact
|
1889
|
615 |
then have "\<forall>x. \<not> memb x l" using memb_card_not_0[of _ l] by auto
|
1888
|
616 |
then have z: "l = []" using no_memb_nil by auto
|
|
617 |
then have "r = []" sorry
|
|
618 |
then show ?case using z list_eq2_refl by simp
|
|
619 |
next
|
|
620 |
case (Suc m)
|
|
621 |
have b: "l \<approx> r" by fact
|
|
622 |
have d: "fcard_raw l = Suc m" by fact
|
|
623 |
have "\<exists>a. memb a l" by (rule fcard_raw_suc_memb[OF d])
|
|
624 |
then obtain a where e: "memb a l" by auto
|
|
625 |
then have e': "memb a r" using list_eq.simps[simplified memb_def[symmetric], of l r] b by auto
|
|
626 |
have f: "fcard_raw (delete_raw l a) = m" using fcard_raw_delete[of l a] e d by simp
|
|
627 |
have g: "delete_raw l a \<approx> delete_raw r a" using delete_raw_rsp[OF b] by simp
|
|
628 |
have g': "list_eq2 (delete_raw l a) (delete_raw r a)" by (rule Suc.hyps[OF f g])
|
|
629 |
have h: "list_eq2 (a # delete_raw l a) (a # delete_raw r a)" by (rule list_eq2.intros(5)[OF g'])
|
|
630 |
have i: "list_eq2 l (a # delete_raw l a)" by (rule list_eq2.intros(3)[OF memb_delete_list_eq2[OF e]])
|
|
631 |
have "list_eq2 l (a # delete_raw r a)" by (rule list_eq2.intros(6)[OF i h])
|
|
632 |
then show ?case using list_eq2.intros(6)[OF _ memb_delete_list_eq2[OF e']] by simp
|
|
633 |
qed
|
|
634 |
|
|
635 |
lemma list_eq2_equiv:
|
|
636 |
"(l \<approx> r) \<longleftrightarrow> (list_eq2 l r)"
|
|
637 |
proof
|
|
638 |
show "list_eq2 l r \<Longrightarrow> l \<approx> r" by (induct rule: list_eq2.induct) auto
|
|
639 |
show "l \<approx> r \<Longrightarrow> list_eq2 l r" using list_eq2_equiv_aux by blast
|
|
640 |
qed
|
|
641 |
|
1518
|
642 |
section {* lifted part *}
|
|
643 |
|
1819
|
644 |
lemma not_fin_fnil: "x |\<notin>| {||}"
|
|
645 |
by (lifting not_memb_nil)
|
1518
|
646 |
|
|
647 |
lemma fin_finsert_iff[simp]:
|
|
648 |
"x |\<in>| finsert y S = (x = y \<or> x |\<in>| S)"
|
|
649 |
by (lifting memb_cons_iff)
|
|
650 |
|
|
651 |
lemma
|
|
652 |
shows finsertI1: "x |\<in>| finsert x S"
|
|
653 |
and finsertI2: "x |\<in>| S \<Longrightarrow> x |\<in>| finsert y S"
|
|
654 |
by (lifting memb_consI1, lifting memb_consI2)
|
|
655 |
|
|
656 |
lemma finsert_absorb[simp]:
|
|
657 |
shows "x |\<in>| S \<Longrightarrow> finsert x S = S"
|
|
658 |
by (lifting memb_absorb)
|
|
659 |
|
|
660 |
lemma fempty_not_finsert[simp]:
|
1533
|
661 |
"{||} \<noteq> finsert x S"
|
|
662 |
"finsert x S \<noteq> {||}"
|
1518
|
663 |
by (lifting nil_not_cons)
|
|
664 |
|
|
665 |
lemma finsert_left_comm:
|
1822
|
666 |
"finsert x (finsert y S) = finsert y (finsert x S)"
|
1518
|
667 |
by (lifting cons_left_comm)
|
|
668 |
|
|
669 |
lemma finsert_left_idem:
|
1822
|
670 |
"finsert x (finsert x S) = finsert x S"
|
1518
|
671 |
by (lifting cons_left_idem)
|
|
672 |
|
|
673 |
lemma fsingleton_eq[simp]:
|
|
674 |
shows "{|x|} = {|y|} \<longleftrightarrow> x = y"
|
|
675 |
by (lifting singleton_list_eq)
|
|
676 |
|
|
677 |
text {* fset_to_set *}
|
|
678 |
|
1533
|
679 |
lemma fset_to_set_simps[simp]:
|
1819
|
680 |
"fset_to_set {||} = ({} :: 'a set)"
|
|
681 |
"fset_to_set (finsert (h :: 'a) t) = insert h (fset_to_set t)"
|
|
682 |
by (lifting set.simps)
|
1518
|
683 |
|
|
684 |
lemma in_fset_to_set:
|
1822
|
685 |
"x \<in> fset_to_set S \<equiv> x |\<in>| S"
|
1518
|
686 |
by (lifting memb_def[symmetric])
|
|
687 |
|
1819
|
688 |
lemma none_fin_fempty:
|
1824
|
689 |
"(\<forall>x. x |\<notin>| S) = (S = {||})"
|
|
690 |
by (lifting none_memb_nil)
|
1518
|
691 |
|
1533
|
692 |
lemma fset_cong:
|
1822
|
693 |
"(fset_to_set S = fset_to_set T) = (S = T)"
|
1533
|
694 |
by (lifting set_cong)
|
|
695 |
|
1518
|
696 |
text {* fcard *}
|
|
697 |
|
|
698 |
lemma fcard_fempty [simp]:
|
|
699 |
shows "fcard {||} = 0"
|
|
700 |
by (lifting fcard_raw_nil)
|
|
701 |
|
|
702 |
lemma fcard_finsert_if [simp]:
|
|
703 |
shows "fcard (finsert x S) = (if x |\<in>| S then fcard S else Suc (fcard S))"
|
|
704 |
by (lifting fcard_raw_cons)
|
|
705 |
|
1822
|
706 |
lemma fcard_0: "(fcard S = 0) = (S = {||})"
|
1813
|
707 |
by (lifting fcard_raw_0)
|
|
708 |
|
1821
|
709 |
lemma fcard_1:
|
1822
|
710 |
shows "(fcard S = 1) = (\<exists>x. S = {|x|})"
|
1819
|
711 |
by (lifting fcard_raw_1)
|
|
712 |
|
1860
|
713 |
lemma fcard_gt_0:
|
|
714 |
shows "x \<in> fset_to_set S \<Longrightarrow> 0 < fcard S"
|
1518
|
715 |
by (lifting fcard_raw_gt_0)
|
|
716 |
|
1860
|
717 |
lemma fcard_not_fin:
|
|
718 |
shows "(x |\<notin>| S) = (fcard (finsert x S) = Suc (fcard S))"
|
1813
|
719 |
by (lifting fcard_raw_not_memb)
|
|
720 |
|
1822
|
721 |
lemma fcard_suc: "fcard S = Suc n \<Longrightarrow> \<exists>x T. x |\<notin>| T \<and> S = finsert x T \<and> fcard T = n"
|
1813
|
722 |
by (lifting fcard_raw_suc)
|
|
723 |
|
1819
|
724 |
lemma fcard_delete:
|
1822
|
725 |
"fcard (fdelete S y) = (if y |\<in>| S then fcard S - 1 else fcard S)"
|
1819
|
726 |
by (lifting fcard_raw_delete)
|
|
727 |
|
1878
|
728 |
lemma fcard_suc_memb: "fcard A = Suc n \<Longrightarrow> \<exists>a. a |\<in>| A"
|
|
729 |
by (lifting fcard_raw_suc_memb)
|
|
730 |
|
|
731 |
lemma fin_fcard_not_0: "a |\<in>| A \<Longrightarrow> fcard A \<noteq> 0"
|
1887
|
732 |
by (lifting memb_card_not_0)
|
1878
|
733 |
|
1518
|
734 |
text {* funion *}
|
|
735 |
|
|
736 |
lemma funion_simps[simp]:
|
1860
|
737 |
shows "{||} |\<union>| S = S"
|
|
738 |
and "finsert x S |\<union>| T = finsert x (S |\<union>| T)"
|
1518
|
739 |
by (lifting append.simps)
|
|
740 |
|
1887
|
741 |
lemma funion_empty[simp]:
|
|
742 |
shows "S |\<union>| {||} = S"
|
|
743 |
by (lifting append_Nil2)
|
|
744 |
|
1907
|
745 |
thm sup.commute[where 'a="'a fset"]
|
1518
|
746 |
|
1907
|
747 |
thm sup.assoc[where 'a="'a fset"]
|
1518
|
748 |
|
1887
|
749 |
lemma singleton_union_left:
|
|
750 |
"{|a|} |\<union>| S = finsert a S"
|
|
751 |
by simp
|
|
752 |
|
|
753 |
lemma singleton_union_right:
|
|
754 |
"S |\<union>| {|a|} = finsert a S"
|
1907
|
755 |
by (subst sup.commute) simp
|
1887
|
756 |
|
1518
|
757 |
section {* Induction and Cases rules for finite sets *}
|
|
758 |
|
|
759 |
lemma fset_strong_cases:
|
1822
|
760 |
"S = {||} \<or> (\<exists>x T. x |\<notin>| T \<and> S = finsert x T)"
|
1819
|
761 |
by (lifting fset_raw_strong_cases)
|
1518
|
762 |
|
|
763 |
lemma fset_exhaust[case_names fempty finsert, cases type: fset]:
|
|
764 |
shows "\<lbrakk>S = {||} \<Longrightarrow> P; \<And>x S'. S = finsert x S' \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P"
|
|
765 |
by (lifting list.exhaust)
|
|
766 |
|
1533
|
767 |
lemma fset_induct_weak[case_names fempty finsert]:
|
1518
|
768 |
shows "\<lbrakk>P {||}; \<And>x S. P S \<Longrightarrow> P (finsert x S)\<rbrakk> \<Longrightarrow> P S"
|
|
769 |
by (lifting list.induct)
|
|
770 |
|
1533
|
771 |
lemma fset_induct[case_names fempty finsert, induct type: fset]:
|
1518
|
772 |
assumes prem1: "P {||}"
|
|
773 |
and prem2: "\<And>x S. \<lbrakk>x |\<notin>| S; P S\<rbrakk> \<Longrightarrow> P (finsert x S)"
|
|
774 |
shows "P S"
|
1533
|
775 |
proof(induct S rule: fset_induct_weak)
|
1518
|
776 |
case fempty
|
|
777 |
show "P {||}" by (rule prem1)
|
|
778 |
next
|
|
779 |
case (finsert x S)
|
|
780 |
have asm: "P S" by fact
|
|
781 |
show "P (finsert x S)"
|
|
782 |
proof(cases "x |\<in>| S")
|
|
783 |
case True
|
|
784 |
have "x |\<in>| S" by fact
|
|
785 |
then show "P (finsert x S)" using asm by simp
|
|
786 |
next
|
|
787 |
case False
|
|
788 |
have "x |\<notin>| S" by fact
|
|
789 |
then show "P (finsert x S)" using prem2 asm by simp
|
|
790 |
qed
|
|
791 |
qed
|
|
792 |
|
1533
|
793 |
lemma fset_induct2:
|
|
794 |
"P {||} {||} \<Longrightarrow>
|
|
795 |
(\<And>x xs. x |\<notin>| xs \<Longrightarrow> P (finsert x xs) {||}) \<Longrightarrow>
|
|
796 |
(\<And>y ys. y |\<notin>| ys \<Longrightarrow> P {||} (finsert y ys)) \<Longrightarrow>
|
|
797 |
(\<And>x xs y ys. \<lbrakk>P xs ys; x |\<notin>| xs; y |\<notin>| ys\<rbrakk> \<Longrightarrow> P (finsert x xs) (finsert y ys)) \<Longrightarrow>
|
|
798 |
P xsa ysa"
|
|
799 |
apply (induct xsa arbitrary: ysa)
|
|
800 |
apply (induct_tac x rule: fset_induct)
|
|
801 |
apply simp_all
|
|
802 |
apply (induct_tac xa rule: fset_induct)
|
|
803 |
apply simp_all
|
|
804 |
done
|
1518
|
805 |
|
1819
|
806 |
text {* fmap *}
|
|
807 |
|
1533
|
808 |
lemma fmap_simps[simp]:
|
|
809 |
"fmap (f :: 'a \<Rightarrow> 'b) {||} = {||}"
|
1822
|
810 |
"fmap f (finsert x S) = finsert (f x) (fmap f S)"
|
1533
|
811 |
by (lifting map.simps)
|
|
812 |
|
|
813 |
lemma fmap_set_image:
|
1822
|
814 |
"fset_to_set (fmap f S) = f ` (fset_to_set S)"
|
|
815 |
by (induct S) (simp_all)
|
1533
|
816 |
|
|
817 |
lemma inj_fmap_eq_iff:
|
1822
|
818 |
"inj f \<Longrightarrow> (fmap f S = fmap f T) = (S = T)"
|
1533
|
819 |
by (lifting inj_map_eq_iff)
|
|
820 |
|
1822
|
821 |
lemma fmap_funion: "fmap f (S |\<union>| T) = fmap f S |\<union>| fmap f T"
|
1813
|
822 |
by (lifting map_append)
|
|
823 |
|
1819
|
824 |
lemma fin_funion:
|
1822
|
825 |
"x |\<in>| S |\<union>| T \<longleftrightarrow> x |\<in>| S \<or> x |\<in>| T"
|
1819
|
826 |
by (lifting memb_append)
|
|
827 |
|
|
828 |
text {* ffold *}
|
|
829 |
|
|
830 |
lemma ffold_nil: "ffold f z {||} = z"
|
|
831 |
by (lifting ffold_raw.simps(1)[where 'a="'b" and 'b="'a"])
|
|
832 |
|
|
833 |
lemma ffold_finsert: "ffold f z (finsert a A) =
|
|
834 |
(if rsp_fold f then if a |\<in>| A then ffold f z A else f a (ffold f z A) else z)"
|
|
835 |
by (lifting ffold_raw.simps(2)[where 'a="'b" and 'b="'a"])
|
|
836 |
|
|
837 |
lemma fin_commute_ffold:
|
|
838 |
"\<lbrakk>rsp_fold f; h |\<in>| b\<rbrakk> \<Longrightarrow> ffold f z b = f h (ffold f z (fdelete b h))"
|
|
839 |
by (lifting memb_commute_ffold_raw)
|
|
840 |
|
|
841 |
text {* fdelete *}
|
|
842 |
|
1822
|
843 |
lemma fin_fdelete:
|
|
844 |
shows "x |\<in>| fdelete S y \<longleftrightarrow> x |\<in>| S \<and> x \<noteq> y"
|
1819
|
845 |
by (lifting memb_delete_raw)
|
|
846 |
|
1822
|
847 |
lemma fin_fdelete_ident:
|
|
848 |
shows "x |\<notin>| fdelete S x"
|
1819
|
849 |
by (lifting memb_delete_raw_ident)
|
|
850 |
|
1822
|
851 |
lemma not_memb_fdelete_ident:
|
|
852 |
shows "x |\<notin>| S \<Longrightarrow> fdelete S x = S"
|
1819
|
853 |
by (lifting not_memb_delete_raw_ident)
|
|
854 |
|
|
855 |
lemma fset_fdelete_cases:
|
1822
|
856 |
shows "S = {||} \<or> (\<exists>x. x |\<in>| S \<and> S = finsert x (fdelete S x))"
|
1819
|
857 |
by (lifting fset_raw_delete_raw_cases)
|
|
858 |
|
|
859 |
text {* inter *}
|
|
860 |
|
1822
|
861 |
lemma finter_empty_l: "({||} |\<inter>| S) = {||}"
|
1819
|
862 |
by (lifting finter_raw.simps(1))
|
|
863 |
|
1822
|
864 |
lemma finter_empty_r: "(S |\<inter>| {||}) = {||}"
|
1819
|
865 |
by (lifting finter_raw_empty)
|
|
866 |
|
|
867 |
lemma finter_finsert:
|
1822
|
868 |
"finsert x S |\<inter>| T = (if x |\<in>| T then finsert x (S |\<inter>| T) else S |\<inter>| T)"
|
1819
|
869 |
by (lifting finter_raw.simps(2))
|
|
870 |
|
|
871 |
lemma fin_finter:
|
1822
|
872 |
"x |\<in>| (S |\<inter>| T) \<longleftrightarrow> x |\<in>| S \<and> x |\<in>| T"
|
1819
|
873 |
by (lifting memb_finter_raw)
|
|
874 |
|
1893
|
875 |
lemma fsubset_finsert:
|
|
876 |
"(finsert x xs |\<subseteq>| ys) = (x |\<in>| ys \<and> xs |\<subseteq>| ys)"
|
|
877 |
by (lifting sub_list_cons)
|
|
878 |
|
|
879 |
thm sub_list_def[simplified memb_def[symmetric], quot_lifted, no_vars]
|
|
880 |
|
|
881 |
lemma fsubset_fin: "xs |\<subseteq>| ys = (\<forall>x. x |\<in>| xs \<longrightarrow> x |\<in>| ys)"
|
|
882 |
by (rule meta_eq_to_obj_eq)
|
|
883 |
(lifting sub_list_def[simplified memb_def[symmetric]])
|
|
884 |
|
1820
|
885 |
lemma expand_fset_eq:
|
1822
|
886 |
"(S = T) = (\<forall>x. (x |\<in>| S) = (x |\<in>| T))"
|
1820
|
887 |
by (lifting list_eq.simps[simplified memb_def[symmetric]])
|
|
888 |
|
1888
|
889 |
(* We cannot write it as "assumes .. shows" since Isabelle changes
|
|
890 |
the quantifiers to schematic variables and reintroduces them in
|
|
891 |
a different order *)
|
|
892 |
lemma fset_eq_cases:
|
|
893 |
"\<lbrakk>a1 = a2;
|
|
894 |
\<And>a b xs. \<lbrakk>a1 = finsert a (finsert b xs); a2 = finsert b (finsert a xs)\<rbrakk> \<Longrightarrow> P;
|
|
895 |
\<lbrakk>a1 = {||}; a2 = {||}\<rbrakk> \<Longrightarrow> P; \<And>xs ys. \<lbrakk>a1 = ys; a2 = xs; xs = ys\<rbrakk> \<Longrightarrow> P;
|
|
896 |
\<And>a xs. \<lbrakk>a1 = finsert a (finsert a xs); a2 = finsert a xs\<rbrakk> \<Longrightarrow> P;
|
|
897 |
\<And>xs ys a. \<lbrakk>a1 = finsert a xs; a2 = finsert a ys; xs = ys\<rbrakk> \<Longrightarrow> P;
|
|
898 |
\<And>xs1 xs2 xs3. \<lbrakk>a1 = xs1; a2 = xs3; xs1 = xs2; xs2 = xs3\<rbrakk> \<Longrightarrow> P\<rbrakk>
|
|
899 |
\<Longrightarrow> P"
|
|
900 |
by (lifting list_eq2.cases[simplified list_eq2_equiv[symmetric]])
|
|
901 |
|
|
902 |
lemma fset_eq_induct:
|
|
903 |
assumes "x1 = x2"
|
|
904 |
and "\<And>a b xs. P (finsert a (finsert b xs)) (finsert b (finsert a xs))"
|
|
905 |
and "P {||} {||}"
|
|
906 |
and "\<And>xs ys. \<lbrakk>xs = ys; P xs ys\<rbrakk> \<Longrightarrow> P ys xs"
|
|
907 |
and "\<And>a xs. P (finsert a (finsert a xs)) (finsert a xs)"
|
|
908 |
and "\<And>xs ys a. \<lbrakk>xs = ys; P xs ys\<rbrakk> \<Longrightarrow> P (finsert a xs) (finsert a ys)"
|
|
909 |
and "\<And>xs1 xs2 xs3. \<lbrakk>xs1 = xs2; P xs1 xs2; xs2 = xs3; P xs2 xs3\<rbrakk> \<Longrightarrow> P xs1 xs3"
|
|
910 |
shows "P x1 x2"
|
|
911 |
using assms
|
|
912 |
by (lifting list_eq2.induct[simplified list_eq2_equiv[symmetric]])
|
1820
|
913 |
|
1533
|
914 |
ML {*
|
|
915 |
fun dest_fsetT (Type ("FSet.fset", [T])) = T
|
|
916 |
| dest_fsetT T = raise TYPE ("dest_fsetT: fset type expected", [T], []);
|
|
917 |
*}
|
1518
|
918 |
|
1682
|
919 |
no_notation
|
|
920 |
list_eq (infix "\<approx>" 50)
|
|
921 |
|
1518
|
922 |
end
|