8 section \<open> Potentially infinite sets \<close>
10 definition complement :: "('a \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> bool" where
11 "complement S v = Not (S v)"
13 definition mapi :: "('a \<Rightarrow> 'b) \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> bool)" where
14 "mapi f s x = Set.member x (image f (Collect s))"
16 definition filteri :: " ('a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> bool" where
17 "filteri f s x = conj (s x) (f x)"
19 definition product :: "('a \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> bool) \<Rightarrow> ('a \<times> 'b \<Rightarrow> bool)" where
20 "product s1 s2 p = conj (s1 (fst p)) (s2 (snd p))"
22 why3_open "set/Set.xml"
30 complement = complement
37 why3_vc diffqtdef by (simp add: mem_def)
39 why3_vc interqtdef by (simp add: mem_def)
41 why3_vc is_empty_empty by (simp add: constqtdef mem_def set.Set.is_empty_def)
43 why3_vc unionqtdef by (simp add: mem_def)
47 by (simp add: fun_upd_idem_iff mem_def)
49 why3_vc remove_add by auto
53 by (auto simp add: mem_def is_empty_def intro: someI_ex)
56 by (simp add: mem_def diffqtdef subset_def)
59 by (simp add: subset_def)
63 by (simp add: subset_def)
66 by (simp add: mem_def remove_def subset_def)
68 why3_vc complementqtdef
69 by (simp add: mem_def complement_def)
71 why3_vc extensionality
73 by (auto simp add: infix_eqeq_def mem_def)
75 why3_vc mapqtdef by (simp add: mem_def mapi_def image_iff)
79 by (meson facts.mapqtdef mem_def)
82 by (metis assms constqtdef fun_upd_other mem_def)
84 why3_vc empty_is_empty
86 by (meson extensionality infix_eqeq_def is_empty_empty set.Set.is_empty_def)
88 why3_vc subset_inter_1
89 by (simp add: set.Set.subset_def mem_def)
91 why3_vc subset_inter_2
92 by (simp add: set.Set.subset_def mem_def)
94 why3_vc subset_union_1
95 by (simp add: set.Set.subset_def mem_def)
97 why3_vc subset_union_2
98 by (simp add: set.Set.subset_def mem_def)
100 why3_vc disjoint_diff_eq
101 by (smt diffqtdef disjoint_def extensionality infix_eqeq_def mem_def)
103 why3_vc disjoint_diff_s2
104 by (simp add: disjoint_def mem_def)
106 why3_vc disjoint_inter_empty
107 by (simp add: disjoint_def mem_def set.Set.is_empty_def)
110 by (metis filteri_def mem_def)
112 why3_vc subset_filter
113 by (simp add: filter_def subset_def)
116 by (simp add: product_def mem_def)
121 section \<open> Finite sets \<close>
123 definition fremove :: "'a \<Rightarrow> 'a fset \<Rightarrow> 'a fset" where
124 "fremove x A = A - {|x|}"
126 definition fchoose :: "'a fset \<Rightarrow> 'a" where
127 "fchoose S = (\<some>x. x |\<in>| S)"
129 definition is_empty :: "'a fset \<Rightarrow> bool" where
130 "is_empty S = (S = fempty)"
132 definition filter :: "'a fset \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> 'a fset" where
133 "filter S p = ffilter p S"
135 why3_open "set/Fset.xml"
152 why3_vc add_def by auto
156 by (auto simp add: fremove_def)
158 why3_vc remove_add by (simp add: fremove_def)
160 why3_vc map_def by auto
162 why3_vc mem_map by (simp add: assms)
164 why3_vc inter_def by simp
166 why3_vc union_def by simp
168 why3_vc remove_def by (auto simp add: fremove_def)
170 why3_vc diff_def by auto
174 by (auto simp add: fchoose_def is_empty_def intro: someI_ex)
176 why3_vc subset_diff by (simp add: Fset.subset_def)
178 why3_vc subset_refl by (simp add: Fset.subset_def)
182 by (simp add: Fset.subset_def)
184 why3_vc subset_remove by (auto simp add: Fset.subset_def fremove_def)
187 using assms fcard_seteq
188 by (metis Fset.subset_def eq_imp_le fsubsetI of_nat_eq_iff)
190 why3_vc extensionality
192 by (simp add: Fset.infix_eqeq_def fset_eqI)
195 proof (cases s rule: fset_strong_cases)
198 show ?thesis by (simp add: fcard_fempty)
202 proof (cases s' rule: fset_strong_cases)
204 with `s = finsert x s'` assms
205 show ?thesis by (simp add: fchoose_def)
208 with `s = finsert x s'` assms
209 show ?thesis by (auto simp add: fcard_finsert_if fchoose_def
214 why3_vc cardinal_add by (auto simp add: fcard_finsert_if finsert_absorb)
216 why3_vc cardinal_empty by (simp add: is_empty_def)
218 why3_vc cardinal_nonneg by simp
220 lemma cardinal_remove_in:
221 "x |\<in>| s \<longrightarrow> int (fcard (fremove x s)) = int (fcard s) - 1"
222 by (smt cardinal_add(2) fminus_finsert_absorb fremove_def set_finsert)
224 lemma cardinal_remove_out:
225 "x |\<notin>| s \<longrightarrow> int (fcard (fremove x s)) = int (fcard s)"
226 by (simp add: fremove_def)
228 why3_vc cardinal_remove by (auto simp add: cardinal_remove_out cardinal_remove_in)
230 why3_vc cardinal_subset
232 by (simp add: Fset.subset_def fcard_mono fsubsetI)
234 why3_vc filter_def by (simp add: Why3_Set.filter_def)
237 apply (simp add: fcard_def card_def)
238 by (metis card_def card_image_le finite_fset)
240 why3_vc cardinal_diff
241 by (metis fcard_funion_fsubset fcard_mono fminus_finter2 inf.idem inf_commute inf_sup_ord(1) of_nat_diff)
242 (* by (smt fcard_funion_fsubset fcard_mono finter_lower1 fminus_finter2 inf.idem inf_commute int_ops(6) of_nat_mono)*)
244 why3_vc mem_singleton
247 why3_vc subset_filter
248 by (simp add: Fset.subset_def Why3_Set.filter_def)
250 why3_vc cardinal_union
251 by (smt fcard_funion_finter of_nat_add)
253 why3_vc empty_is_empty
254 by (meson Fset.is_empty_def assms bot.extremum_uniqueI fsubsetI)
256 why3_vc is_empty_empty
257 by (simp add: cardinal_empty)
259 why3_vc subset_inter_1
260 by (simp add: Fset.subset_def)
262 why3_vc subset_inter_2
263 by (simp add: Fset.subset_def)
265 why3_vc subset_union_1
266 by (simp add: Fset.subset_def)
268 why3_vc subset_union_2
269 by (simp add: Fset.subset_def)
271 why3_vc cardinal_filter
272 using cardinal_subset subset_filter by blast
274 why3_vc disjoint_diff_eq
275 by (smt Fset.disjoint_def Fset.facts.diff_def fsubsetI fsubset_antisym)
277 why3_vc disjoint_diff_s2
278 by (simp add: Fset.facts.disjoint_diff_eq)
280 why3_vc disjoint_inter_empty
281 by (metis Fset.facts.disjoint_diff_eq Fset.facts.empty_is_empty Fset.facts.is_empty_empty fminus_disjoint fminus_triv)
283 why3_vc cardinal_inter_disjoint
284 by (meson Fset.facts.disjoint_inter_empty assms cardinal_empty)