separate class for notions specific for integral (semi)domains, in contrast to fields where these are trivial
1 (* Author: Tobias Nipkow, Lawrence C Paulson and Markus Wenzel *)
3 section {* Set theory for higher-order logic *}
9 subsection {* Sets as predicates *}
13 axiomatization Collect :: "('a \<Rightarrow> bool) \<Rightarrow> 'a set" -- "comprehension"
14 and member :: "'a \<Rightarrow> 'a set \<Rightarrow> bool" -- "membership"
16 mem_Collect_eq [iff, code_unfold]: "member a (Collect P) = P a"
17 and Collect_mem_eq [simp]: "Collect (\<lambda>x. member x A) = A"
21 member ("(_/ : _)" [51, 51] 50)
23 abbreviation not_member where
24 "not_member x A \<equiv> ~ (x : A)" -- "non-membership"
27 not_member ("op ~:") and
28 not_member ("(_/ ~: _)" [51, 51] 50)
31 member ("op \<in>") and
32 member ("(_/ \<in> _)" [51, 51] 50) and
33 not_member ("op \<notin>") and
34 not_member ("(_/ \<notin> _)" [51, 51] 50)
36 notation (HTML output)
37 member ("op \<in>") and
38 member ("(_/ \<in> _)" [51, 51] 50) and
39 not_member ("op \<notin>") and
40 not_member ("(_/ \<notin> _)" [51, 51] 50)
43 text {* Set comprehensions *}
46 "_Coll" :: "pttrn => bool => 'a set" ("(1{_./ _})")
48 "{x. P}" == "CONST Collect (%x. P)"
51 "_Collect" :: "pttrn => 'a set => bool => 'a set" ("(1{_ :/ _./ _})")
53 "_Collect" :: "pttrn => 'a set => bool => 'a set" ("(1{_ \<in>/ _./ _})")
55 "{p:A. P}" => "CONST Collect (%p. p:A & P)"
57 lemma CollectI: "P a \<Longrightarrow> a \<in> {x. P x}"
60 lemma CollectD: "a \<in> {x. P x} \<Longrightarrow> P a"
63 lemma Collect_cong: "(\<And>x. P x = Q x) ==> {x. P x} = {x. Q x}"
67 Simproc for pulling @{text "x=t"} in @{text "{x. \<dots> & x=t & \<dots>}"}
68 to the front (and similarly for @{text "t=x"}):
71 simproc_setup defined_Collect ("{x. P x & Q x}") = {*
72 fn _ => Quantifier1.rearrange_Collect
74 resolve_tac ctxt @{thms Collect_cong} 1 THEN
75 resolve_tac ctxt @{thms iffI} 1 THEN
77 (EVERY' [REPEAT_DETERM o eresolve_tac ctxt @{thms conjE},
78 DEPTH_SOLVE_1 o (assume_tac ctxt ORELSE' resolve_tac ctxt @{thms conjI})]))
81 lemmas CollectE = CollectD [elim_format]
84 assumes "\<And>x. x \<in> A \<longleftrightarrow> x \<in> B"
87 from assms have "{x. x \<in> A} = {x. x \<in> B}" by simp
88 then show ?thesis by simp
92 "A = B \<longleftrightarrow> (\<forall>x. x \<in> A \<longleftrightarrow> x \<in> B)"
93 by (auto intro:set_eqI)
95 text {* Lifting of predicate class instances *}
97 instantiation set :: (type) boolean_algebra
100 definition less_eq_set where
101 "A \<le> B \<longleftrightarrow> (\<lambda>x. member x A) \<le> (\<lambda>x. member x B)"
103 definition less_set where
104 "A < B \<longleftrightarrow> (\<lambda>x. member x A) < (\<lambda>x. member x B)"
106 definition inf_set where
107 "A \<sqinter> B = Collect ((\<lambda>x. member x A) \<sqinter> (\<lambda>x. member x B))"
109 definition sup_set where
110 "A \<squnion> B = Collect ((\<lambda>x. member x A) \<squnion> (\<lambda>x. member x B))"
112 definition bot_set where
113 "\<bottom> = Collect \<bottom>"
115 definition top_set where
116 "\<top> = Collect \<top>"
118 definition uminus_set where
119 "- A = Collect (- (\<lambda>x. member x A))"
121 definition minus_set where
122 "A - B = Collect ((\<lambda>x. member x A) - (\<lambda>x. member x B))"
125 qed (simp_all add: less_eq_set_def less_set_def inf_set_def sup_set_def
126 bot_set_def top_set_def uminus_set_def minus_set_def
127 less_le_not_le inf_compl_bot sup_compl_top sup_inf_distrib1 diff_eq
129 del: inf_apply sup_apply bot_apply top_apply minus_apply uminus_apply)
133 text {* Set enumerations *}
135 abbreviation empty :: "'a set" ("{}") where
138 definition insert :: "'a \<Rightarrow> 'a set \<Rightarrow> 'a set" where
139 insert_compr: "insert a B = {x. x = a \<or> x \<in> B}"
142 "_Finset" :: "args => 'a set" ("{(_)}")
144 "{x, xs}" == "CONST insert x {xs}"
145 "{x}" == "CONST insert x {}"
148 subsection {* Subsets and bounded quantifiers *}
151 subset :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where
152 "subset \<equiv> less"
155 subset_eq :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where
156 "subset_eq \<equiv> less_eq"
160 subset ("(_/ < _)" [51, 51] 50) and
161 subset_eq ("op <=") and
162 subset_eq ("(_/ <= _)" [51, 51] 50)
165 subset ("op \<subset>") and
166 subset ("(_/ \<subset> _)" [51, 51] 50) and
167 subset_eq ("op \<subseteq>") and
168 subset_eq ("(_/ \<subseteq> _)" [51, 51] 50)
170 notation (HTML output)
171 subset ("op \<subset>") and
172 subset ("(_/ \<subset> _)" [51, 51] 50) and
173 subset_eq ("op \<subseteq>") and
174 subset_eq ("(_/ \<subseteq> _)" [51, 51] 50)
177 supset :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where
178 "supset \<equiv> greater"
181 supset_eq :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where
182 "supset_eq \<equiv> greater_eq"
185 supset ("op \<supset>") and
186 supset ("(_/ \<supset> _)" [51, 51] 50) and
187 supset_eq ("op \<supseteq>") and
188 supset_eq ("(_/ \<supseteq> _)" [51, 51] 50)
190 definition Ball :: "'a set \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> bool" where
191 "Ball A P \<longleftrightarrow> (\<forall>x. x \<in> A \<longrightarrow> P x)" -- "bounded universal quantifiers"
193 definition Bex :: "'a set \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> bool" where
194 "Bex A P \<longleftrightarrow> (\<exists>x. x \<in> A \<and> P x)" -- "bounded existential quantifiers"
197 "_Ball" :: "pttrn => 'a set => bool => bool" ("(3ALL _:_./ _)" [0, 0, 10] 10)
198 "_Bex" :: "pttrn => 'a set => bool => bool" ("(3EX _:_./ _)" [0, 0, 10] 10)
199 "_Bex1" :: "pttrn => 'a set => bool => bool" ("(3EX! _:_./ _)" [0, 0, 10] 10)
200 "_Bleast" :: "id => 'a set => bool => 'a" ("(3LEAST _:_./ _)" [0, 0, 10] 10)
203 "_Ball" :: "pttrn => 'a set => bool => bool" ("(3! _:_./ _)" [0, 0, 10] 10)
204 "_Bex" :: "pttrn => 'a set => bool => bool" ("(3? _:_./ _)" [0, 0, 10] 10)
205 "_Bex1" :: "pttrn => 'a set => bool => bool" ("(3?! _:_./ _)" [0, 0, 10] 10)
208 "_Ball" :: "pttrn => 'a set => bool => bool" ("(3\<forall>_\<in>_./ _)" [0, 0, 10] 10)
209 "_Bex" :: "pttrn => 'a set => bool => bool" ("(3\<exists>_\<in>_./ _)" [0, 0, 10] 10)
210 "_Bex1" :: "pttrn => 'a set => bool => bool" ("(3\<exists>!_\<in>_./ _)" [0, 0, 10] 10)
211 "_Bleast" :: "id => 'a set => bool => 'a" ("(3LEAST_\<in>_./ _)" [0, 0, 10] 10)
214 "_Ball" :: "pttrn => 'a set => bool => bool" ("(3\<forall>_\<in>_./ _)" [0, 0, 10] 10)
215 "_Bex" :: "pttrn => 'a set => bool => bool" ("(3\<exists>_\<in>_./ _)" [0, 0, 10] 10)
216 "_Bex1" :: "pttrn => 'a set => bool => bool" ("(3\<exists>!_\<in>_./ _)" [0, 0, 10] 10)
219 "ALL x:A. P" == "CONST Ball A (%x. P)"
220 "EX x:A. P" == "CONST Bex A (%x. P)"
221 "EX! x:A. P" => "EX! x. x:A & P"
222 "LEAST x:A. P" => "LEAST x. x:A & P"
225 "_setlessAll" :: "[idt, 'a, bool] => bool" ("(3ALL _<_./ _)" [0, 0, 10] 10)
226 "_setlessEx" :: "[idt, 'a, bool] => bool" ("(3EX _<_./ _)" [0, 0, 10] 10)
227 "_setleAll" :: "[idt, 'a, bool] => bool" ("(3ALL _<=_./ _)" [0, 0, 10] 10)
228 "_setleEx" :: "[idt, 'a, bool] => bool" ("(3EX _<=_./ _)" [0, 0, 10] 10)
229 "_setleEx1" :: "[idt, 'a, bool] => bool" ("(3EX! _<=_./ _)" [0, 0, 10] 10)
232 "_setlessAll" :: "[idt, 'a, bool] => bool" ("(3\<forall>_\<subset>_./ _)" [0, 0, 10] 10)
233 "_setlessEx" :: "[idt, 'a, bool] => bool" ("(3\<exists>_\<subset>_./ _)" [0, 0, 10] 10)
234 "_setleAll" :: "[idt, 'a, bool] => bool" ("(3\<forall>_\<subseteq>_./ _)" [0, 0, 10] 10)
235 "_setleEx" :: "[idt, 'a, bool] => bool" ("(3\<exists>_\<subseteq>_./ _)" [0, 0, 10] 10)
236 "_setleEx1" :: "[idt, 'a, bool] => bool" ("(3\<exists>!_\<subseteq>_./ _)" [0, 0, 10] 10)
239 "_setlessAll" :: "[idt, 'a, bool] => bool" ("(3! _<_./ _)" [0, 0, 10] 10)
240 "_setlessEx" :: "[idt, 'a, bool] => bool" ("(3? _<_./ _)" [0, 0, 10] 10)
241 "_setleAll" :: "[idt, 'a, bool] => bool" ("(3! _<=_./ _)" [0, 0, 10] 10)
242 "_setleEx" :: "[idt, 'a, bool] => bool" ("(3? _<=_./ _)" [0, 0, 10] 10)
243 "_setleEx1" :: "[idt, 'a, bool] => bool" ("(3?! _<=_./ _)" [0, 0, 10] 10)
246 "_setlessAll" :: "[idt, 'a, bool] => bool" ("(3\<forall>_\<subset>_./ _)" [0, 0, 10] 10)
247 "_setlessEx" :: "[idt, 'a, bool] => bool" ("(3\<exists>_\<subset>_./ _)" [0, 0, 10] 10)
248 "_setleAll" :: "[idt, 'a, bool] => bool" ("(3\<forall>_\<subseteq>_./ _)" [0, 0, 10] 10)
249 "_setleEx" :: "[idt, 'a, bool] => bool" ("(3\<exists>_\<subseteq>_./ _)" [0, 0, 10] 10)
250 "_setleEx1" :: "[idt, 'a, bool] => bool" ("(3\<exists>!_\<subseteq>_./ _)" [0, 0, 10] 10)
253 "\<forall>A\<subset>B. P" => "ALL A. A \<subset> B --> P"
254 "\<exists>A\<subset>B. P" => "EX A. A \<subset> B & P"
255 "\<forall>A\<subseteq>B. P" => "ALL A. A \<subseteq> B --> P"
256 "\<exists>A\<subseteq>B. P" => "EX A. A \<subseteq> B & P"
257 "\<exists>!A\<subseteq>B. P" => "EX! A. A \<subseteq> B & P"
261 val All_binder = Mixfix.binder_name @{const_syntax All};
262 val Ex_binder = Mixfix.binder_name @{const_syntax Ex};
263 val impl = @{const_syntax HOL.implies};
264 val conj = @{const_syntax HOL.conj};
265 val sbset = @{const_syntax subset};
266 val sbset_eq = @{const_syntax subset_eq};
269 [((All_binder, impl, sbset), @{syntax_const "_setlessAll"}),
270 ((All_binder, impl, sbset_eq), @{syntax_const "_setleAll"}),
271 ((Ex_binder, conj, sbset), @{syntax_const "_setlessEx"}),
272 ((Ex_binder, conj, sbset_eq), @{syntax_const "_setleEx"})];
274 fun mk v (v', T) c n P =
275 if v = v' andalso not (Term.exists_subterm (fn Free (x, _) => x = v | _ => false) n)
276 then Syntax.const c $ Syntax_Trans.mark_bound_body (v', T) $ n $ P
279 fun tr' q = (q, fn _ =>
280 (fn [Const (@{syntax_const "_bound"}, _) $ Free (v, Type (@{type_name set}, _)),
282 (Const (d, _) $ (Const (@{syntax_const "_bound"}, _) $ Free (v', T)) $ n) $ P] =>
283 (case AList.lookup (op =) trans (q, c, d) of
285 | SOME l => mk v (v', T) l n P)
286 | _ => raise Match));
288 [tr' All_binder, tr' Ex_binder]
294 \medskip Translate between @{text "{e | x1...xn. P}"} and @{text
295 "{u. EX x1..xn. u = e & P}"}; @{text "{y. EX x1..xn. y = e & P}"} is
296 only translated if @{text "[0..n] subset bvs(e)"}.
300 "_Setcompr" :: "'a => idts => bool => 'a set" ("(1{_ |/_./ _})")
304 val ex_tr = snd (Syntax_Trans.mk_binder_tr ("EX ", @{const_syntax Ex}));
306 fun nvars (Const (@{syntax_const "_idts"}, _) $ _ $ idts) = nvars idts + 1
309 fun setcompr_tr ctxt [e, idts, b] =
311 val eq = Syntax.const @{const_syntax HOL.eq} $ Bound (nvars idts) $ e;
312 val P = Syntax.const @{const_syntax HOL.conj} $ eq $ b;
313 val exP = ex_tr ctxt [idts, P];
314 in Syntax.const @{const_syntax Collect} $ absdummy dummyT exP end;
316 in [(@{syntax_const "_Setcompr"}, setcompr_tr)] end;
320 [Syntax_Trans.preserve_binder_abs2_tr' @{const_syntax Ball} @{syntax_const "_Ball"},
321 Syntax_Trans.preserve_binder_abs2_tr' @{const_syntax Bex} @{syntax_const "_Bex"}]
322 *} -- {* to avoid eta-contraction of body *}
326 val ex_tr' = snd (Syntax_Trans.mk_binder_tr' (@{const_syntax Ex}, "DUMMY"));
328 fun setcompr_tr' ctxt [Abs (abs as (_, _, P))] =
330 fun check (Const (@{const_syntax Ex}, _) $ Abs (_, _, P), n) = check (P, n + 1)
331 | check (Const (@{const_syntax HOL.conj}, _) $
332 (Const (@{const_syntax HOL.eq}, _) $ Bound m $ e) $ P, n) =
333 n > 0 andalso m = n andalso not (loose_bvar1 (P, n)) andalso
334 subset (op =) (0 upto (n - 1), add_loose_bnos (e, 0, []))
338 let val _ $ idts $ (_ $ (_ $ _ $ e) $ Q) = ex_tr' ctxt [abs]
339 in Syntax.const @{syntax_const "_Setcompr"} $ e $ idts $ Q end;
341 if check (P, 0) then tr' P
344 val (x as _ $ Free(xN, _), t) = Syntax_Trans.atomic_abs_tr' abs;
345 val M = Syntax.const @{syntax_const "_Coll"} $ x $ t;
348 Const (@{const_syntax HOL.conj}, _) $
349 (Const (@{const_syntax Set.member}, _) $
350 (Const (@{syntax_const "_bound"}, _) $ Free (yN, _)) $ A) $ P =>
351 if xN = yN then Syntax.const @{syntax_const "_Collect"} $ x $ A $ P else M
355 in [(@{const_syntax Collect}, setcompr_tr')] end;
358 simproc_setup defined_Bex ("EX x:A. P x & Q x") = {*
359 fn _ => Quantifier1.rearrange_bex
361 unfold_tac ctxt @{thms Bex_def} THEN
362 Quantifier1.prove_one_point_ex_tac ctxt)
365 simproc_setup defined_All ("ALL x:A. P x --> Q x") = {*
366 fn _ => Quantifier1.rearrange_ball
368 unfold_tac ctxt @{thms Ball_def} THEN
369 Quantifier1.prove_one_point_all_tac ctxt)
372 lemma ballI [intro!]: "(!!x. x:A ==> P x) ==> ALL x:A. P x"
373 by (simp add: Ball_def)
375 lemmas strip = impI allI ballI
377 lemma bspec [dest?]: "ALL x:A. P x ==> x:A ==> P x"
378 by (simp add: Ball_def)
381 Gives better instantiation for bound:
385 map_theory_claset (fn ctxt =>
386 ctxt addbefore ("bspec", fn ctxt' => dresolve_tac ctxt' @{thms bspec} THEN' assume_tac ctxt'))
395 val mksimps_pairs = [(@{const_name Ball}, @{thms bspec})] @ mksimps_pairs;
402 declaration {* fn _ =>
403 Simplifier.map_ss (Simplifier.set_mksimps (mksimps mksimps_pairs))
406 lemma ballE [elim]: "ALL x:A. P x ==> (P x ==> Q) ==> (x ~: A ==> Q) ==> Q"
407 by (unfold Ball_def) blast
409 lemma bexI [intro]: "P x ==> x:A ==> EX x:A. P x"
410 -- {* Normally the best argument order: @{prop "P x"} constrains the
411 choice of @{prop "x:A"}. *}
412 by (unfold Bex_def) blast
414 lemma rev_bexI [intro?]: "x:A ==> P x ==> EX x:A. P x"
415 -- {* The best argument order when there is only one @{prop "x:A"}. *}
416 by (unfold Bex_def) blast
418 lemma bexCI: "(ALL x:A. ~P x ==> P a) ==> a:A ==> EX x:A. P x"
419 by (unfold Bex_def) blast
421 lemma bexE [elim!]: "EX x:A. P x ==> (!!x. x:A ==> P x ==> Q) ==> Q"
422 by (unfold Bex_def) blast
424 lemma ball_triv [simp]: "(ALL x:A. P) = ((EX x. x:A) --> P)"
425 -- {* Trival rewrite rule. *}
426 by (simp add: Ball_def)
428 lemma bex_triv [simp]: "(EX x:A. P) = ((EX x. x:A) & P)"
429 -- {* Dual form for existentials. *}
430 by (simp add: Bex_def)
432 lemma bex_triv_one_point1 [simp]: "(EX x:A. x = a) = (a:A)"
435 lemma bex_triv_one_point2 [simp]: "(EX x:A. a = x) = (a:A)"
438 lemma bex_one_point1 [simp]: "(EX x:A. x = a & P x) = (a:A & P a)"
441 lemma bex_one_point2 [simp]: "(EX x:A. a = x & P x) = (a:A & P a)"
444 lemma ball_one_point1 [simp]: "(ALL x:A. x = a --> P x) = (a:A --> P a)"
447 lemma ball_one_point2 [simp]: "(ALL x:A. a = x --> P x) = (a:A --> P a)"
450 lemma ball_conj_distrib:
451 "(\<forall>x\<in>A. P x \<and> Q x) \<longleftrightarrow> ((\<forall>x\<in>A. P x) \<and> (\<forall>x\<in>A. Q x))"
454 lemma bex_disj_distrib:
455 "(\<exists>x\<in>A. P x \<or> Q x) \<longleftrightarrow> ((\<exists>x\<in>A. P x) \<or> (\<exists>x\<in>A. Q x))"
459 text {* Congruence rules *}
462 "A = B ==> (!!x. x:B ==> P x = Q x) ==>
463 (ALL x:A. P x) = (ALL x:B. Q x)"
464 by (simp add: Ball_def)
466 lemma strong_ball_cong [cong]:
467 "A = B ==> (!!x. x:B =simp=> P x = Q x) ==>
468 (ALL x:A. P x) = (ALL x:B. Q x)"
469 by (simp add: simp_implies_def Ball_def)
472 "A = B ==> (!!x. x:B ==> P x = Q x) ==>
473 (EX x:A. P x) = (EX x:B. Q x)"
474 by (simp add: Bex_def cong: conj_cong)
476 lemma strong_bex_cong [cong]:
477 "A = B ==> (!!x. x:B =simp=> P x = Q x) ==>
478 (EX x:A. P x) = (EX x:B. Q x)"
479 by (simp add: simp_implies_def Bex_def cong: conj_cong)
481 lemma bex1_def: "(\<exists>!x\<in>X. P x) \<longleftrightarrow> (\<exists>x\<in>X. P x) \<and> (\<forall>x\<in>X. \<forall>y\<in>X. P x \<longrightarrow> P y \<longrightarrow> x = y)"
484 subsection {* Basic operations *}
486 subsubsection {* Subsets *}
488 lemma subsetI [intro!]: "(\<And>x. x \<in> A \<Longrightarrow> x \<in> B) \<Longrightarrow> A \<subseteq> B"
489 by (simp add: less_eq_set_def le_fun_def)
492 \medskip Map the type @{text "'a set => anything"} to just @{typ
493 'a}; for overloading constants whose first argument has type @{typ
497 lemma subsetD [elim, intro?]: "A \<subseteq> B ==> c \<in> A ==> c \<in> B"
498 by (simp add: less_eq_set_def le_fun_def)
499 -- {* Rule in Modus Ponens style. *}
501 lemma rev_subsetD [intro?]: "c \<in> A ==> A \<subseteq> B ==> c \<in> B"
502 -- {* The same, with reversed premises for use with @{text erule} --
503 cf @{text rev_mp}. *}
507 \medskip Converts @{prop "A \<subseteq> B"} to @{prop "x \<in> A ==> x \<in> B"}.
510 lemma subsetCE [elim]: "A \<subseteq> B ==> (c \<notin> A ==> P) ==> (c \<in> B ==> P) ==> P"
511 -- {* Classical elimination rule. *}
512 by (auto simp add: less_eq_set_def le_fun_def)
514 lemma subset_eq: "A \<le> B = (\<forall>x\<in>A. x \<in> B)" by blast
516 lemma contra_subsetD: "A \<subseteq> B ==> c \<notin> B ==> c \<notin> A"
519 lemma subset_refl: "A \<subseteq> A"
520 by (fact order_refl) (* already [iff] *)
522 lemma subset_trans: "A \<subseteq> B ==> B \<subseteq> C ==> A \<subseteq> C"
523 by (fact order_trans)
525 lemma set_rev_mp: "x:A ==> A \<subseteq> B ==> x:B"
528 lemma set_mp: "A \<subseteq> B ==> x:A ==> x:B"
531 lemma subset_not_subset_eq [code]:
532 "A \<subset> B \<longleftrightarrow> A \<subseteq> B \<and> \<not> B \<subseteq> A"
533 by (fact less_le_not_le)
535 lemma eq_mem_trans: "a=b ==> b \<in> A ==> a \<in> A"
538 lemmas basic_trans_rules [trans] =
539 order_trans_rules set_rev_mp set_mp eq_mem_trans
542 subsubsection {* Equality *}
544 lemma subset_antisym [intro!]: "A \<subseteq> B ==> B \<subseteq> A ==> A = B"
545 -- {* Anti-symmetry of the subset relation. *}
546 by (iprover intro: set_eqI subsetD)
549 \medskip Equality rules from ZF set theory -- are they appropriate
553 lemma equalityD1: "A = B ==> A \<subseteq> B"
556 lemma equalityD2: "A = B ==> B \<subseteq> A"
560 \medskip Be careful when adding this to the claset as @{text
561 subset_empty} is in the simpset: @{prop "A = {}"} goes to @{prop "{}
562 \<subseteq> A"} and @{prop "A \<subseteq> {}"} and then back to @{prop "A = {}"}!
565 lemma equalityE: "A = B ==> (A \<subseteq> B ==> B \<subseteq> A ==> P) ==> P"
568 lemma equalityCE [elim]:
569 "A = B ==> (c \<in> A ==> c \<in> B ==> P) ==> (c \<notin> A ==> c \<notin> B ==> P) ==> P"
572 lemma eqset_imp_iff: "A = B ==> (x : A) = (x : B)"
575 lemma eqelem_imp_iff: "x = y ==> (x : A) = (y : A)"
579 subsubsection {* The empty set *}
583 by (simp add: bot_set_def bot_fun_def)
585 lemma empty_iff [simp]: "(c : {}) = False"
586 by (simp add: empty_def)
588 lemma emptyE [elim!]: "a : {} ==> P"
591 lemma empty_subsetI [iff]: "{} \<subseteq> A"
592 -- {* One effect is to delete the ASSUMPTION @{prop "{} <= A"} *}
595 lemma equals0I: "(!!y. y \<in> A ==> False) ==> A = {}"
598 lemma equals0D: "A = {} ==> a \<notin> A"
599 -- {* Use for reasoning about disjointness: @{text "A Int B = {}"} *}
602 lemma ball_empty [simp]: "Ball {} P = True"
603 by (simp add: Ball_def)
605 lemma bex_empty [simp]: "Bex {} P = False"
606 by (simp add: Bex_def)
609 subsubsection {* The universal set -- UNIV *}
611 abbreviation UNIV :: "'a set" where
616 by (simp add: top_set_def top_fun_def)
618 lemma UNIV_I [simp]: "x : UNIV"
619 by (simp add: UNIV_def)
621 declare UNIV_I [intro] -- {* unsafe makes it less likely to cause problems *}
623 lemma UNIV_witness [intro?]: "EX x. x : UNIV"
626 lemma subset_UNIV: "A \<subseteq> UNIV"
627 by (fact top_greatest) (* already simp *)
630 \medskip Eta-contracting these two rules (to remove @{text P})
631 causes them to be ignored because of their interaction with
635 lemma ball_UNIV [simp]: "Ball UNIV P = All P"
636 by (simp add: Ball_def)
638 lemma bex_UNIV [simp]: "Bex UNIV P = Ex P"
639 by (simp add: Bex_def)
641 lemma UNIV_eq_I: "(\<And>x. x \<in> A) \<Longrightarrow> UNIV = A"
644 lemma UNIV_not_empty [iff]: "UNIV ~= {}"
645 by (blast elim: equalityE)
647 lemma empty_not_UNIV[simp]: "{} \<noteq> UNIV"
650 subsubsection {* The Powerset operator -- Pow *}
652 definition Pow :: "'a set => 'a set set" where
653 Pow_def: "Pow A = {B. B \<le> A}"
655 lemma Pow_iff [iff]: "(A \<in> Pow B) = (A \<subseteq> B)"
656 by (simp add: Pow_def)
658 lemma PowI: "A \<subseteq> B ==> A \<in> Pow B"
659 by (simp add: Pow_def)
661 lemma PowD: "A \<in> Pow B ==> A \<subseteq> B"
662 by (simp add: Pow_def)
664 lemma Pow_bottom: "{} \<in> Pow B"
667 lemma Pow_top: "A \<in> Pow A"
670 lemma Pow_not_empty: "Pow A \<noteq> {}"
671 using Pow_top by blast
674 subsubsection {* Set complement *}
676 lemma Compl_iff [simp]: "(c \<in> -A) = (c \<notin> A)"
677 by (simp add: fun_Compl_def uminus_set_def)
679 lemma ComplI [intro!]: "(c \<in> A ==> False) ==> c \<in> -A"
680 by (simp add: fun_Compl_def uminus_set_def) blast
683 \medskip This form, with negated conclusion, works well with the
684 Classical prover. Negated assumptions behave like formulae on the
685 right side of the notional turnstile ... *}
687 lemma ComplD [dest!]: "c : -A ==> c~:A"
690 lemmas ComplE = ComplD [elim_format]
692 lemma Compl_eq: "- A = {x. ~ x : A}"
696 subsubsection {* Binary intersection *}
698 abbreviation inter :: "'a set \<Rightarrow> 'a set \<Rightarrow> 'a set" (infixl "Int" 70) where
699 "op Int \<equiv> inf"
702 inter (infixl "\<inter>" 70)
704 notation (HTML output)
705 inter (infixl "\<inter>" 70)
708 "A \<inter> B = {x. x \<in> A \<and> x \<in> B}"
709 by (simp add: inf_set_def inf_fun_def)
711 lemma Int_iff [simp]: "(c : A Int B) = (c:A & c:B)"
712 by (unfold Int_def) blast
714 lemma IntI [intro!]: "c:A ==> c:B ==> c : A Int B"
717 lemma IntD1: "c : A Int B ==> c:A"
720 lemma IntD2: "c : A Int B ==> c:B"
723 lemma IntE [elim!]: "c : A Int B ==> (c:A ==> c:B ==> P) ==> P"
726 lemma mono_Int: "mono f \<Longrightarrow> f (A \<inter> B) \<subseteq> f A \<inter> f B"
730 subsubsection {* Binary union *}
732 abbreviation union :: "'a set \<Rightarrow> 'a set \<Rightarrow> 'a set" (infixl "Un" 65) where
736 union (infixl "\<union>" 65)
738 notation (HTML output)
739 union (infixl "\<union>" 65)
742 "A \<union> B = {x. x \<in> A \<or> x \<in> B}"
743 by (simp add: sup_set_def sup_fun_def)
745 lemma Un_iff [simp]: "(c : A Un B) = (c:A | c:B)"
746 by (unfold Un_def) blast
748 lemma UnI1 [elim?]: "c:A ==> c : A Un B"
751 lemma UnI2 [elim?]: "c:B ==> c : A Un B"
755 \medskip Classical introduction rule: no commitment to @{prop A} vs
759 lemma UnCI [intro!]: "(c~:B ==> c:A) ==> c : A Un B"
762 lemma UnE [elim!]: "c : A Un B ==> (c:A ==> P) ==> (c:B ==> P) ==> P"
763 by (unfold Un_def) blast
765 lemma insert_def: "insert a B = {x. x = a} \<union> B"
766 by (simp add: insert_compr Un_def)
768 lemma mono_Un: "mono f \<Longrightarrow> f A \<union> f B \<subseteq> f (A \<union> B)"
772 subsubsection {* Set difference *}
774 lemma Diff_iff [simp]: "(c : A - B) = (c:A & c~:B)"
775 by (simp add: minus_set_def fun_diff_def)
777 lemma DiffI [intro!]: "c : A ==> c ~: B ==> c : A - B"
780 lemma DiffD1: "c : A - B ==> c : A"
783 lemma DiffD2: "c : A - B ==> c : B ==> P"
786 lemma DiffE [elim!]: "c : A - B ==> (c:A ==> c~:B ==> P) ==> P"
789 lemma set_diff_eq: "A - B = {x. x : A & ~ x : B}" by blast
791 lemma Compl_eq_Diff_UNIV: "-A = (UNIV - A)"
795 subsubsection {* Augmenting a set -- @{const insert} *}
797 lemma insert_iff [simp]: "(a : insert b A) = (a = b | a:A)"
798 by (unfold insert_def) blast
800 lemma insertI1: "a : insert a B"
803 lemma insertI2: "a : B ==> a : insert b B"
806 lemma insertE [elim!]: "a : insert b A ==> (a = b ==> P) ==> (a:A ==> P) ==> P"
807 by (unfold insert_def) blast
809 lemma insertCI [intro!]: "(a~:B ==> a = b) ==> a: insert b B"
810 -- {* Classical introduction rule. *}
813 lemma subset_insert_iff: "(A \<subseteq> insert x B) = (if x:A then A - {x} \<subseteq> B else A \<subseteq> B)"
818 obtains B where "A = insert x B" and "x \<notin> B"
820 from assms show "A = insert x (A - {x})" by blast
822 show "x \<notin> A - {x}" by blast
825 lemma insert_ident: "x ~: A ==> x ~: B ==> (insert x A = insert x B) = (A = B)"
828 lemma insert_eq_iff: assumes "a \<notin> A" "b \<notin> B"
829 shows "insert a A = insert b B \<longleftrightarrow>
830 (if a=b then A=B else \<exists>C. A = insert b C \<and> b \<notin> C \<and> B = insert a C \<and> a \<notin> C)"
831 (is "?L \<longleftrightarrow> ?R")
836 assume "a=b" with assms `?L` show ?R by (simp add: insert_ident)
840 have "A = insert b ?C \<and> b \<notin> ?C \<and> B = insert a ?C \<and> a \<notin> ?C"
841 using assms `?L` `a\<noteq>b` by auto
842 thus ?R using `a\<noteq>b` by auto
845 assume ?R thus ?L by (auto split: if_splits)
848 lemma insert_UNIV: "insert x UNIV = UNIV"
851 subsubsection {* Singletons, using insert *}
853 lemma singletonI [intro!]: "a : {a}"
854 -- {* Redundant? But unlike @{text insertCI}, it proves the subgoal immediately! *}
857 lemma singletonD [dest!]: "b : {a} ==> b = a"
860 lemmas singletonE = singletonD [elim_format]
862 lemma singleton_iff: "(b : {a}) = (b = a)"
865 lemma singleton_inject [dest!]: "{a} = {b} ==> a = b"
868 lemma singleton_insert_inj_eq [iff]:
869 "({b} = insert a A) = (a = b & A \<subseteq> {b})"
872 lemma singleton_insert_inj_eq' [iff]:
873 "(insert a A = {b}) = (a = b & A \<subseteq> {b})"
876 lemma subset_singletonD: "A \<subseteq> {x} ==> A = {} | A = {x}"
879 lemma singleton_conv [simp]: "{x. x = a} = {a}"
882 lemma singleton_conv2 [simp]: "{x. a = x} = {a}"
885 lemma diff_single_insert: "A - {x} \<subseteq> B ==> A \<subseteq> insert x B"
888 lemma doubleton_eq_iff: "({a,b} = {c,d}) = (a=c & b=d | a=d & b=c)"
889 by (blast elim: equalityE)
891 lemma Un_singleton_iff:
892 "(A \<union> B = {x}) = (A = {} \<and> B = {x} \<or> A = {x} \<and> B = {} \<or> A = {x} \<and> B = {x})"
895 lemma singleton_Un_iff:
896 "({x} = A \<union> B) = (A = {} \<and> B = {x} \<or> A = {x} \<and> B = {} \<or> A = {x} \<and> B = {x})"
900 subsubsection {* Image of a set under a function *}
903 Frequently @{term b} does not have the syntactic form of @{term "f x"}.
906 definition image :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a set \<Rightarrow> 'b set" (infixr "`" 90)
908 "f ` A = {y. \<exists>x\<in>A. y = f x}"
910 lemma image_eqI [simp, intro]:
911 "b = f x \<Longrightarrow> x \<in> A \<Longrightarrow> b \<in> f ` A"
912 by (unfold image_def) blast
915 "x \<in> A \<Longrightarrow> f x \<in> f ` A"
916 by (rule image_eqI) (rule refl)
919 "x \<in> A \<Longrightarrow> b = f x \<Longrightarrow> b \<in> f ` A"
920 -- {* This version's more effective when we already have the
921 required @{term x}. *}
924 lemma imageE [elim!]:
925 assumes "b \<in> (\<lambda>x. f x) ` A" -- {* The eta-expansion gives variable-name preservation. *}
926 obtains x where "b = f x" and "x \<in> A"
927 using assms by (unfold image_def) blast
929 lemma Compr_image_eq:
930 "{x \<in> f ` A. P x} = f ` {x \<in> A. P (f x)}"
934 "f ` (A \<union> B) = f ` A \<union> f ` B"
938 "z \<in> f ` A \<longleftrightarrow> (\<exists>x\<in>A. z = f x)"
942 "(\<And>x. x \<in> A \<Longrightarrow> f x \<in> B) \<Longrightarrow> f ` A \<subseteq> B"
943 -- {* Replaces the three steps @{text subsetI}, @{text imageE},
944 @{text hypsubst}, but breaks too many existing proofs. *}
947 lemma image_subset_iff:
948 "f ` A \<subseteq> B \<longleftrightarrow> (\<forall>x\<in>A. f x \<in> B)"
949 -- {* This rewrite rule would confuse users if made default. *}
953 assumes "B \<subseteq> f ` A"
954 obtains C where "C \<subseteq> A" and "B = f ` C"
956 from assms have "B = f ` {a \<in> A. f a \<in> B}" by fast
957 moreover have "{a \<in> A. f a \<in> B} \<subseteq> A" by blast
958 ultimately show thesis by (blast intro: that)
961 lemma subset_image_iff:
962 "B \<subseteq> f ` A \<longleftrightarrow> (\<exists>AA\<subseteq>A. B = f ` AA)"
963 by (blast elim: subset_imageE)
965 lemma image_ident [simp]:
966 "(\<lambda>x. x) ` Y = Y"
969 lemma image_empty [simp]:
973 lemma image_insert [simp]:
974 "f ` insert a B = insert (f a) (f ` B)"
977 lemma image_constant:
978 "x \<in> A \<Longrightarrow> (\<lambda>x. c) ` A = {c}"
981 lemma image_constant_conv:
982 "(\<lambda>x. c) ` A = (if A = {} then {} else {c})"
986 "f ` (g ` A) = (\<lambda>x. f (g x)) ` A"
989 lemma insert_image [simp]:
990 "x \<in> A ==> insert (f x) (f ` A) = f ` A"
993 lemma image_is_empty [iff]:
994 "f ` A = {} \<longleftrightarrow> A = {}"
997 lemma empty_is_image [iff]:
998 "{} = f ` A \<longleftrightarrow> A = {}"
1001 lemma image_Collect:
1002 "f ` {x. P x} = {f x | x. P x}"
1003 -- {* NOT suitable as a default simprule: the RHS isn't simpler than the LHS,
1004 with its implicit quantifier and conjunction. Also image enjoys better
1005 equational properties than does the RHS. *}
1008 lemma if_image_distrib [simp]:
1009 "(\<lambda>x. if P x then f x else g x) ` S
1010 = (f ` (S \<inter> {x. P x})) \<union> (g ` (S \<inter> {x. \<not> P x}))"
1014 "M = N \<Longrightarrow> (\<And>x. x \<in> N \<Longrightarrow> f x = g x) \<Longrightarrow> f ` M = g ` N"
1015 by (simp add: image_def)
1017 lemma image_Int_subset:
1018 "f ` (A \<inter> B) \<subseteq> f ` A \<inter> f ` B"
1021 lemma image_diff_subset:
1022 "f ` A - f ` B \<subseteq> f ` (A - B)"
1025 lemma Setcompr_eq_image: "{f x | x. x \<in> A} = f ` A"
1029 assumes "\<forall>x\<in>f ` A. P x"
1030 shows "\<forall>x\<in>A. P (f x)"
1034 assumes "\<exists>x\<in>f ` A. P x"
1035 shows "\<exists>x\<in>A. P (f x)"
1040 \medskip Range of a function -- just a translation for image!
1043 abbreviation range :: "('a \<Rightarrow> 'b) \<Rightarrow> 'b set"
1044 where -- "of function"
1045 "range f \<equiv> f ` UNIV"
1048 "b = f x \<Longrightarrow> b \<in> range f"
1055 lemma rangeE [elim?]:
1056 "b \<in> range (\<lambda>x. f x) \<Longrightarrow> (\<And>x. b = f x \<Longrightarrow> P) \<Longrightarrow> P"
1059 lemma full_SetCompr_eq:
1060 "{u. \<exists>x. u = f x} = range f"
1063 lemma range_composition:
1064 "range (\<lambda>x. f (g x)) = f ` range g"
1068 subsubsection {* Some rules with @{text "if"} *}
1070 text{* Elimination of @{text"{x. \<dots> & x=t & \<dots>}"}. *}
1072 lemma Collect_conv_if: "{x. x=a & P x} = (if P a then {a} else {})"
1075 lemma Collect_conv_if2: "{x. a=x & P x} = (if P a then {a} else {})"
1079 Rewrite rules for boolean case-splitting: faster than @{text
1080 "split_if [split]"}.
1083 lemma split_if_eq1: "((if Q then x else y) = b) = ((Q --> x = b) & (~ Q --> y = b))"
1086 lemma split_if_eq2: "(a = (if Q then x else y)) = ((Q --> a = x) & (~ Q --> a = y))"
1090 Split ifs on either side of the membership relation. Not for @{text
1091 "[simp]"} -- can cause goals to blow up!
1094 lemma split_if_mem1: "((if Q then x else y) : b) = ((Q --> x : b) & (~ Q --> y : b))"
1097 lemma split_if_mem2: "(a : (if Q then x else y)) = ((Q --> a : x) & (~ Q --> a : y))"
1098 by (rule split_if [where P="%S. a : S"])
1100 lemmas split_ifs = if_bool_eq_conj split_if_eq1 split_if_eq2 split_if_mem1 split_if_mem2
1102 (*Would like to add these, but the existing code only searches for the
1103 outer-level constant, which in this case is just Set.member; we instead need
1104 to use term-nets to associate patterns with rules. Also, if a rule fails to
1105 apply, then the formula should be kept.
1106 [("uminus", Compl_iff RS iffD1), ("minus", [Diff_iff RS iffD1]),
1107 ("Int", [IntD1,IntD2]),
1108 ("Collect", [CollectD]), ("Inter", [InterD]), ("INTER", [INT_D])]
1112 subsection {* Further operations and lemmas *}
1114 subsubsection {* The ``proper subset'' relation *}
1116 lemma psubsetI [intro!]: "A \<subseteq> B ==> A \<noteq> B ==> A \<subset> B"
1117 by (unfold less_le) blast
1119 lemma psubsetE [elim!]:
1120 "[|A \<subset> B; [|A \<subseteq> B; ~ (B\<subseteq>A)|] ==> R|] ==> R"
1121 by (unfold less_le) blast
1123 lemma psubset_insert_iff:
1124 "(A \<subset> insert x B) = (if x \<in> B then A \<subset> B else if x \<in> A then A - {x} \<subset> B else A \<subseteq> B)"
1125 by (auto simp add: less_le subset_insert_iff)
1127 lemma psubset_eq: "(A \<subset> B) = (A \<subseteq> B & A \<noteq> B)"
1128 by (simp only: less_le)
1130 lemma psubset_imp_subset: "A \<subset> B ==> A \<subseteq> B"
1131 by (simp add: psubset_eq)
1133 lemma psubset_trans: "[| A \<subset> B; B \<subset> C |] ==> A \<subset> C"
1134 apply (unfold less_le)
1135 apply (auto dest: subset_antisym)
1138 lemma psubsetD: "[| A \<subset> B; c \<in> A |] ==> c \<in> B"
1139 apply (unfold less_le)
1140 apply (auto dest: subsetD)
1143 lemma psubset_subset_trans: "A \<subset> B ==> B \<subseteq> C ==> A \<subset> C"
1144 by (auto simp add: psubset_eq)
1146 lemma subset_psubset_trans: "A \<subseteq> B ==> B \<subset> C ==> A \<subset> C"
1147 by (auto simp add: psubset_eq)
1149 lemma psubset_imp_ex_mem: "A \<subset> B ==> \<exists>b. b \<in> (B - A)"
1150 by (unfold less_le) blast
1153 "(!!x. x \<in> A ==> P x) == Trueprop (\<forall>x\<in>A. P x)"
1154 by (simp only: Ball_def atomize_all atomize_imp)
1156 lemmas [symmetric, rulify] = atomize_ball
1157 and [symmetric, defn] = atomize_ball
1159 lemma image_Pow_mono:
1160 assumes "f ` A \<subseteq> B"
1161 shows "image f ` Pow A \<subseteq> Pow B"
1162 using assms by blast
1164 lemma image_Pow_surj:
1166 shows "image f ` Pow A = Pow B"
1167 using assms by (blast elim: subset_imageE)
1170 subsubsection {* Derived rules involving subsets. *}
1172 text {* @{text insert}. *}
1174 lemma subset_insertI: "B \<subseteq> insert a B"
1175 by (rule subsetI) (erule insertI2)
1177 lemma subset_insertI2: "A \<subseteq> B \<Longrightarrow> A \<subseteq> insert b B"
1180 lemma subset_insert: "x \<notin> A ==> (A \<subseteq> insert x B) = (A \<subseteq> B)"
1184 text {* \medskip Finite Union -- the least upper bound of two sets. *}
1186 lemma Un_upper1: "A \<subseteq> A \<union> B"
1189 lemma Un_upper2: "B \<subseteq> A \<union> B"
1192 lemma Un_least: "A \<subseteq> C ==> B \<subseteq> C ==> A \<union> B \<subseteq> C"
1196 text {* \medskip Finite Intersection -- the greatest lower bound of two sets. *}
1198 lemma Int_lower1: "A \<inter> B \<subseteq> A"
1201 lemma Int_lower2: "A \<inter> B \<subseteq> B"
1204 lemma Int_greatest: "C \<subseteq> A ==> C \<subseteq> B ==> C \<subseteq> A \<inter> B"
1205 by (fact inf_greatest)
1208 text {* \medskip Set difference. *}
1210 lemma Diff_subset: "A - B \<subseteq> A"
1213 lemma Diff_subset_conv: "(A - B \<subseteq> C) = (A \<subseteq> B \<union> C)"
1217 subsubsection {* Equalities involving union, intersection, inclusion, etc. *}
1219 text {* @{text "{}"}. *}
1221 lemma Collect_const [simp]: "{s. P} = (if P then UNIV else {})"
1222 -- {* supersedes @{text "Collect_False_empty"} *}
1225 lemma subset_empty [simp]: "(A \<subseteq> {}) = (A = {})"
1226 by (fact bot_unique)
1228 lemma not_psubset_empty [iff]: "\<not> (A < {})"
1229 by (fact not_less_bot) (* FIXME: already simp *)
1231 lemma Collect_empty_eq [simp]: "(Collect P = {}) = (\<forall>x. \<not> P x)"
1234 lemma empty_Collect_eq [simp]: "({} = Collect P) = (\<forall>x. \<not> P x)"
1237 lemma Collect_neg_eq: "{x. \<not> P x} = - {x. P x}"
1240 lemma Collect_disj_eq: "{x. P x | Q x} = {x. P x} \<union> {x. Q x}"
1243 lemma Collect_imp_eq: "{x. P x --> Q x} = -{x. P x} \<union> {x. Q x}"
1246 lemma Collect_conj_eq: "{x. P x & Q x} = {x. P x} \<inter> {x. Q x}"
1249 lemma Collect_mono_iff: "Collect P \<subseteq> Collect Q \<longleftrightarrow> (\<forall>x. P x \<longrightarrow> Q x)"
1253 text {* \medskip @{text insert}. *}
1255 lemma insert_is_Un: "insert a A = {a} Un A"
1256 -- {* NOT SUITABLE FOR REWRITING since @{text "{a} == insert a {}"} *}
1259 lemma insert_not_empty [simp]: "insert a A \<noteq> {}"
1262 lemmas empty_not_insert = insert_not_empty [symmetric]
1263 declare empty_not_insert [simp]
1265 lemma insert_absorb: "a \<in> A ==> insert a A = A"
1266 -- {* @{text "[simp]"} causes recursive calls when there are nested inserts *}
1267 -- {* with \emph{quadratic} running time *}
1270 lemma insert_absorb2 [simp]: "insert x (insert x A) = insert x A"
1273 lemma insert_commute: "insert x (insert y A) = insert y (insert x A)"
1276 lemma insert_subset [simp]: "(insert x A \<subseteq> B) = (x \<in> B & A \<subseteq> B)"
1279 lemma mk_disjoint_insert: "a \<in> A ==> \<exists>B. A = insert a B & a \<notin> B"
1280 -- {* use new @{text B} rather than @{text "A - {a}"} to avoid infinite unfolding *}
1281 apply (rule_tac x = "A - {a}" in exI, blast)
1284 lemma insert_Collect: "insert a (Collect P) = {u. u \<noteq> a --> P u}"
1287 lemma insert_inter_insert[simp]: "insert a A \<inter> insert a B = insert a (A \<inter> B)"
1290 lemma insert_disjoint [simp]:
1291 "(insert a A \<inter> B = {}) = (a \<notin> B \<and> A \<inter> B = {})"
1292 "({} = insert a A \<inter> B) = (a \<notin> B \<and> {} = A \<inter> B)"
1295 lemma disjoint_insert [simp]:
1296 "(B \<inter> insert a A = {}) = (a \<notin> B \<and> B \<inter> A = {})"
1297 "({} = A \<inter> insert b B) = (b \<notin> A \<and> {} = A \<inter> B)"
1301 text {* \medskip @{text Int} *}
1303 lemma Int_absorb: "A \<inter> A = A"
1304 by (fact inf_idem) (* already simp *)
1306 lemma Int_left_absorb: "A \<inter> (A \<inter> B) = A \<inter> B"
1307 by (fact inf_left_idem)
1309 lemma Int_commute: "A \<inter> B = B \<inter> A"
1310 by (fact inf_commute)
1312 lemma Int_left_commute: "A \<inter> (B \<inter> C) = B \<inter> (A \<inter> C)"
1313 by (fact inf_left_commute)
1315 lemma Int_assoc: "(A \<inter> B) \<inter> C = A \<inter> (B \<inter> C)"
1318 lemmas Int_ac = Int_assoc Int_left_absorb Int_commute Int_left_commute
1319 -- {* Intersection is an AC-operator *}
1321 lemma Int_absorb1: "B \<subseteq> A ==> A \<inter> B = B"
1322 by (fact inf_absorb2)
1324 lemma Int_absorb2: "A \<subseteq> B ==> A \<inter> B = A"
1325 by (fact inf_absorb1)
1327 lemma Int_empty_left: "{} \<inter> B = {}"
1328 by (fact inf_bot_left) (* already simp *)
1330 lemma Int_empty_right: "A \<inter> {} = {}"
1331 by (fact inf_bot_right) (* already simp *)
1333 lemma disjoint_eq_subset_Compl: "(A \<inter> B = {}) = (A \<subseteq> -B)"
1336 lemma disjoint_iff_not_equal: "(A \<inter> B = {}) = (\<forall>x\<in>A. \<forall>y\<in>B. x \<noteq> y)"
1339 lemma Int_UNIV_left: "UNIV \<inter> B = B"
1340 by (fact inf_top_left) (* already simp *)
1342 lemma Int_UNIV_right: "A \<inter> UNIV = A"
1343 by (fact inf_top_right) (* already simp *)
1345 lemma Int_Un_distrib: "A \<inter> (B \<union> C) = (A \<inter> B) \<union> (A \<inter> C)"
1346 by (fact inf_sup_distrib1)
1348 lemma Int_Un_distrib2: "(B \<union> C) \<inter> A = (B \<inter> A) \<union> (C \<inter> A)"
1349 by (fact inf_sup_distrib2)
1351 lemma Int_UNIV [simp]: "(A \<inter> B = UNIV) = (A = UNIV & B = UNIV)"
1352 by (fact inf_eq_top_iff) (* already simp *)
1354 lemma Int_subset_iff [simp]: "(C \<subseteq> A \<inter> B) = (C \<subseteq> A & C \<subseteq> B)"
1355 by (fact le_inf_iff)
1357 lemma Int_Collect: "(x \<in> A \<inter> {x. P x}) = (x \<in> A & P x)"
1361 text {* \medskip @{text Un}. *}
1363 lemma Un_absorb: "A \<union> A = A"
1364 by (fact sup_idem) (* already simp *)
1366 lemma Un_left_absorb: "A \<union> (A \<union> B) = A \<union> B"
1367 by (fact sup_left_idem)
1369 lemma Un_commute: "A \<union> B = B \<union> A"
1370 by (fact sup_commute)
1372 lemma Un_left_commute: "A \<union> (B \<union> C) = B \<union> (A \<union> C)"
1373 by (fact sup_left_commute)
1375 lemma Un_assoc: "(A \<union> B) \<union> C = A \<union> (B \<union> C)"
1378 lemmas Un_ac = Un_assoc Un_left_absorb Un_commute Un_left_commute
1379 -- {* Union is an AC-operator *}
1381 lemma Un_absorb1: "A \<subseteq> B ==> A \<union> B = B"
1382 by (fact sup_absorb2)
1384 lemma Un_absorb2: "B \<subseteq> A ==> A \<union> B = A"
1385 by (fact sup_absorb1)
1387 lemma Un_empty_left: "{} \<union> B = B"
1388 by (fact sup_bot_left) (* already simp *)
1390 lemma Un_empty_right: "A \<union> {} = A"
1391 by (fact sup_bot_right) (* already simp *)
1393 lemma Un_UNIV_left: "UNIV \<union> B = UNIV"
1394 by (fact sup_top_left) (* already simp *)
1396 lemma Un_UNIV_right: "A \<union> UNIV = UNIV"
1397 by (fact sup_top_right) (* already simp *)
1399 lemma Un_insert_left [simp]: "(insert a B) \<union> C = insert a (B \<union> C)"
1402 lemma Un_insert_right [simp]: "A \<union> (insert a B) = insert a (A \<union> B)"
1405 lemma Int_insert_left:
1406 "(insert a B) Int C = (if a \<in> C then insert a (B \<inter> C) else B \<inter> C)"
1409 lemma Int_insert_left_if0[simp]:
1410 "a \<notin> C \<Longrightarrow> (insert a B) Int C = B \<inter> C"
1413 lemma Int_insert_left_if1[simp]:
1414 "a \<in> C \<Longrightarrow> (insert a B) Int C = insert a (B Int C)"
1417 lemma Int_insert_right:
1418 "A \<inter> (insert a B) = (if a \<in> A then insert a (A \<inter> B) else A \<inter> B)"
1421 lemma Int_insert_right_if0[simp]:
1422 "a \<notin> A \<Longrightarrow> A Int (insert a B) = A Int B"
1425 lemma Int_insert_right_if1[simp]:
1426 "a \<in> A \<Longrightarrow> A Int (insert a B) = insert a (A Int B)"
1429 lemma Un_Int_distrib: "A \<union> (B \<inter> C) = (A \<union> B) \<inter> (A \<union> C)"
1430 by (fact sup_inf_distrib1)
1432 lemma Un_Int_distrib2: "(B \<inter> C) \<union> A = (B \<union> A) \<inter> (C \<union> A)"
1433 by (fact sup_inf_distrib2)
1436 "(A \<inter> B) \<union> (B \<inter> C) \<union> (C \<inter> A) = (A \<union> B) \<inter> (B \<union> C) \<inter> (C \<union> A)"
1439 lemma subset_Un_eq: "(A \<subseteq> B) = (A \<union> B = B)"
1440 by (fact le_iff_sup)
1442 lemma Un_empty [iff]: "(A \<union> B = {}) = (A = {} & B = {})"
1443 by (fact sup_eq_bot_iff) (* FIXME: already simp *)
1445 lemma Un_subset_iff [simp]: "(A \<union> B \<subseteq> C) = (A \<subseteq> C & B \<subseteq> C)"
1446 by (fact le_sup_iff)
1448 lemma Un_Diff_Int: "(A - B) \<union> (A \<inter> B) = A"
1451 lemma Diff_Int2: "A \<inter> C - B \<inter> C = A \<inter> C - B"
1455 text {* \medskip Set complement *}
1457 lemma Compl_disjoint [simp]: "A \<inter> -A = {}"
1458 by (fact inf_compl_bot)
1460 lemma Compl_disjoint2 [simp]: "-A \<inter> A = {}"
1461 by (fact compl_inf_bot)
1463 lemma Compl_partition: "A \<union> -A = UNIV"
1464 by (fact sup_compl_top)
1466 lemma Compl_partition2: "-A \<union> A = UNIV"
1467 by (fact compl_sup_top)
1469 lemma double_complement: "- (-A) = (A::'a set)"
1470 by (fact double_compl) (* already simp *)
1472 lemma Compl_Un: "-(A \<union> B) = (-A) \<inter> (-B)"
1473 by (fact compl_sup) (* already simp *)
1475 lemma Compl_Int: "-(A \<inter> B) = (-A) \<union> (-B)"
1476 by (fact compl_inf) (* already simp *)
1478 lemma subset_Compl_self_eq: "(A \<subseteq> -A) = (A = {})"
1481 lemma Un_Int_assoc_eq: "((A \<inter> B) \<union> C = A \<inter> (B \<union> C)) = (C \<subseteq> A)"
1482 -- {* Halmos, Naive Set Theory, page 16. *}
1485 lemma Compl_UNIV_eq: "-UNIV = {}"
1486 by (fact compl_top_eq) (* already simp *)
1488 lemma Compl_empty_eq: "-{} = UNIV"
1489 by (fact compl_bot_eq) (* already simp *)
1491 lemma Compl_subset_Compl_iff [iff]: "(-A \<subseteq> -B) = (B \<subseteq> A)"
1492 by (fact compl_le_compl_iff) (* FIXME: already simp *)
1494 lemma Compl_eq_Compl_iff [iff]: "(-A = -B) = (A = (B::'a set))"
1495 by (fact compl_eq_compl_iff) (* FIXME: already simp *)
1497 lemma Compl_insert: "- insert x A = (-A) - {x}"
1500 text {* \medskip Bounded quantifiers.
1502 The following are not added to the default simpset because
1503 (a) they duplicate the body and (b) there are no similar rules for @{text Int}. *}
1505 lemma ball_Un: "(\<forall>x \<in> A \<union> B. P x) = ((\<forall>x\<in>A. P x) & (\<forall>x\<in>B. P x))"
1508 lemma bex_Un: "(\<exists>x \<in> A \<union> B. P x) = ((\<exists>x\<in>A. P x) | (\<exists>x\<in>B. P x))"
1512 text {* \medskip Set difference. *}
1514 lemma Diff_eq: "A - B = A \<inter> (-B)"
1517 lemma Diff_eq_empty_iff [simp]: "(A - B = {}) = (A \<subseteq> B)"
1520 lemma Diff_cancel [simp]: "A - A = {}"
1523 lemma Diff_idemp [simp]: "(A - B) - B = A - (B::'a set)"
1526 lemma Diff_triv: "A \<inter> B = {} ==> A - B = A"
1527 by (blast elim: equalityE)
1529 lemma empty_Diff [simp]: "{} - A = {}"
1532 lemma Diff_empty [simp]: "A - {} = A"
1535 lemma Diff_UNIV [simp]: "A - UNIV = {}"
1538 lemma Diff_insert0 [simp]: "x \<notin> A ==> A - insert x B = A - B"
1541 lemma Diff_insert: "A - insert a B = A - B - {a}"
1542 -- {* NOT SUITABLE FOR REWRITING since @{text "{a} == insert a 0"} *}
1545 lemma Diff_insert2: "A - insert a B = A - {a} - B"
1546 -- {* NOT SUITABLE FOR REWRITING since @{text "{a} == insert a 0"} *}
1549 lemma insert_Diff_if: "insert x A - B = (if x \<in> B then A - B else insert x (A - B))"
1552 lemma insert_Diff1 [simp]: "x \<in> B ==> insert x A - B = A - B"
1555 lemma insert_Diff_single[simp]: "insert a (A - {a}) = insert a A"
1558 lemma insert_Diff: "a \<in> A ==> insert a (A - {a}) = A"
1561 lemma Diff_insert_absorb: "x \<notin> A ==> (insert x A) - {x} = A"
1564 lemma Diff_disjoint [simp]: "A \<inter> (B - A) = {}"
1567 lemma Diff_partition: "A \<subseteq> B ==> A \<union> (B - A) = B"
1570 lemma double_diff: "A \<subseteq> B ==> B \<subseteq> C ==> B - (C - A) = A"
1573 lemma Un_Diff_cancel [simp]: "A \<union> (B - A) = A \<union> B"
1576 lemma Un_Diff_cancel2 [simp]: "(B - A) \<union> A = B \<union> A"
1579 lemma Diff_Un: "A - (B \<union> C) = (A - B) \<inter> (A - C)"
1582 lemma Diff_Int: "A - (B \<inter> C) = (A - B) \<union> (A - C)"
1585 lemma Un_Diff: "(A \<union> B) - C = (A - C) \<union> (B - C)"
1588 lemma Int_Diff: "(A \<inter> B) - C = A \<inter> (B - C)"
1591 lemma Diff_Int_distrib: "C \<inter> (A - B) = (C \<inter> A) - (C \<inter> B)"
1594 lemma Diff_Int_distrib2: "(A - B) \<inter> C = (A \<inter> C) - (B \<inter> C)"
1597 lemma Diff_Compl [simp]: "A - (- B) = A \<inter> B"
1600 lemma Compl_Diff_eq [simp]: "- (A - B) = -A \<union> B"
1604 text {* \medskip Quantification over type @{typ bool}. *}
1606 lemma bool_induct: "P True \<Longrightarrow> P False \<Longrightarrow> P x"
1609 lemma all_bool_eq: "(\<forall>b. P b) \<longleftrightarrow> P True \<and> P False"
1610 by (auto intro: bool_induct)
1612 lemma bool_contrapos: "P x \<Longrightarrow> \<not> P False \<Longrightarrow> P True"
1615 lemma ex_bool_eq: "(\<exists>b. P b) \<longleftrightarrow> P True \<or> P False"
1616 by (auto intro: bool_contrapos)
1618 lemma UNIV_bool: "UNIV = {False, True}"
1619 by (auto intro: bool_induct)
1621 text {* \medskip @{text Pow} *}
1623 lemma Pow_empty [simp]: "Pow {} = {{}}"
1624 by (auto simp add: Pow_def)
1626 lemma Pow_singleton_iff [simp]: "Pow X = {Y} \<longleftrightarrow> X = {} \<and> Y = {}"
1629 lemma Pow_insert: "Pow (insert a A) = Pow A \<union> (insert a ` Pow A)"
1630 by (blast intro: image_eqI [where ?x = "u - {a}" for u])
1632 lemma Pow_Compl: "Pow (- A) = {-B | B. A \<in> Pow B}"
1633 by (blast intro: exI [where ?x = "- u" for u])
1635 lemma Pow_UNIV [simp]: "Pow UNIV = UNIV"
1638 lemma Un_Pow_subset: "Pow A \<union> Pow B \<subseteq> Pow (A \<union> B)"
1641 lemma Pow_Int_eq [simp]: "Pow (A \<inter> B) = Pow A \<inter> Pow B"
1645 text {* \medskip Miscellany. *}
1647 lemma set_eq_subset: "(A = B) = (A \<subseteq> B & B \<subseteq> A)"
1650 lemma subset_iff: "(A \<subseteq> B) = (\<forall>t. t \<in> A --> t \<in> B)"
1653 lemma subset_iff_psubset_eq: "(A \<subseteq> B) = ((A \<subset> B) | (A = B))"
1654 by (unfold less_le) blast
1656 lemma all_not_in_conv [simp]: "(\<forall>x. x \<notin> A) = (A = {})"
1659 lemma ex_in_conv: "(\<exists>x. x \<in> A) = (A \<noteq> {})"
1662 lemma ball_simps [simp, no_atp]:
1663 "\<And>A P Q. (\<forall>x\<in>A. P x \<or> Q) \<longleftrightarrow> ((\<forall>x\<in>A. P x) \<or> Q)"
1664 "\<And>A P Q. (\<forall>x\<in>A. P \<or> Q x) \<longleftrightarrow> (P \<or> (\<forall>x\<in>A. Q x))"
1665 "\<And>A P Q. (\<forall>x\<in>A. P \<longrightarrow> Q x) \<longleftrightarrow> (P \<longrightarrow> (\<forall>x\<in>A. Q x))"
1666 "\<And>A P Q. (\<forall>x\<in>A. P x \<longrightarrow> Q) \<longleftrightarrow> ((\<exists>x\<in>A. P x) \<longrightarrow> Q)"
1667 "\<And>P. (\<forall>x\<in>{}. P x) \<longleftrightarrow> True"
1668 "\<And>P. (\<forall>x\<in>UNIV. P x) \<longleftrightarrow> (\<forall>x. P x)"
1669 "\<And>a B P. (\<forall>x\<in>insert a B. P x) \<longleftrightarrow> (P a \<and> (\<forall>x\<in>B. P x))"
1670 "\<And>P Q. (\<forall>x\<in>Collect Q. P x) \<longleftrightarrow> (\<forall>x. Q x \<longrightarrow> P x)"
1671 "\<And>A P f. (\<forall>x\<in>f`A. P x) \<longleftrightarrow> (\<forall>x\<in>A. P (f x))"
1672 "\<And>A P. (\<not> (\<forall>x\<in>A. P x)) \<longleftrightarrow> (\<exists>x\<in>A. \<not> P x)"
1675 lemma bex_simps [simp, no_atp]:
1676 "\<And>A P Q. (\<exists>x\<in>A. P x \<and> Q) \<longleftrightarrow> ((\<exists>x\<in>A. P x) \<and> Q)"
1677 "\<And>A P Q. (\<exists>x\<in>A. P \<and> Q x) \<longleftrightarrow> (P \<and> (\<exists>x\<in>A. Q x))"
1678 "\<And>P. (\<exists>x\<in>{}. P x) \<longleftrightarrow> False"
1679 "\<And>P. (\<exists>x\<in>UNIV. P x) \<longleftrightarrow> (\<exists>x. P x)"
1680 "\<And>a B P. (\<exists>x\<in>insert a B. P x) \<longleftrightarrow> (P a | (\<exists>x\<in>B. P x))"
1681 "\<And>P Q. (\<exists>x\<in>Collect Q. P x) \<longleftrightarrow> (\<exists>x. Q x \<and> P x)"
1682 "\<And>A P f. (\<exists>x\<in>f`A. P x) \<longleftrightarrow> (\<exists>x\<in>A. P (f x))"
1683 "\<And>A P. (\<not>(\<exists>x\<in>A. P x)) \<longleftrightarrow> (\<forall>x\<in>A. \<not> P x)"
1687 subsubsection {* Monotonicity of various operations *}
1689 lemma image_mono: "A \<subseteq> B ==> f`A \<subseteq> f`B"
1692 lemma Pow_mono: "A \<subseteq> B ==> Pow A \<subseteq> Pow B"
1695 lemma insert_mono: "C \<subseteq> D ==> insert a C \<subseteq> insert a D"
1698 lemma Un_mono: "A \<subseteq> C ==> B \<subseteq> D ==> A \<union> B \<subseteq> C \<union> D"
1701 lemma Int_mono: "A \<subseteq> C ==> B \<subseteq> D ==> A \<inter> B \<subseteq> C \<inter> D"
1704 lemma Diff_mono: "A \<subseteq> C ==> D \<subseteq> B ==> A - B \<subseteq> C - D"
1707 lemma Compl_anti_mono: "A \<subseteq> B ==> -B \<subseteq> -A"
1708 by (fact compl_mono)
1710 text {* \medskip Monotonicity of implications. *}
1712 lemma in_mono: "A \<subseteq> B ==> x \<in> A --> x \<in> B"
1714 apply (erule subsetD, assumption)
1717 lemma conj_mono: "P1 --> Q1 ==> P2 --> Q2 ==> (P1 & P2) --> (Q1 & Q2)"
1720 lemma disj_mono: "P1 --> Q1 ==> P2 --> Q2 ==> (P1 | P2) --> (Q1 | Q2)"
1723 lemma imp_mono: "Q1 --> P1 ==> P2 --> Q2 ==> (P1 --> P2) --> (Q1 --> Q2)"
1726 lemma imp_refl: "P --> P" ..
1728 lemma not_mono: "Q --> P ==> ~ P --> ~ Q"
1731 lemma ex_mono: "(!!x. P x --> Q x) ==> (EX x. P x) --> (EX x. Q x)"
1734 lemma all_mono: "(!!x. P x --> Q x) ==> (ALL x. P x) --> (ALL x. Q x)"
1737 lemma Collect_mono: "(!!x. P x --> Q x) ==> Collect P \<subseteq> Collect Q"
1740 lemma Int_Collect_mono:
1741 "A \<subseteq> B ==> (!!x. x \<in> A ==> P x --> Q x) ==> A \<inter> Collect P \<subseteq> B \<inter> Collect Q"
1744 lemmas basic_monos =
1745 subset_refl imp_refl disj_mono conj_mono
1746 ex_mono Collect_mono in_mono
1748 lemma eq_to_mono: "a = b ==> c = d ==> b --> d ==> a --> c"
1752 subsubsection {* Inverse image of a function *}
1754 definition vimage :: "('a => 'b) => 'b set => 'a set" (infixr "-`" 90) where
1755 "f -` B == {x. f x : B}"
1757 lemma vimage_eq [simp]: "(a : f -` B) = (f a : B)"
1758 by (unfold vimage_def) blast
1760 lemma vimage_singleton_eq: "(a : f -` {b}) = (f a = b)"
1763 lemma vimageI [intro]: "f a = b ==> b:B ==> a : f -` B"
1764 by (unfold vimage_def) blast
1766 lemma vimageI2: "f a : A ==> a : f -` A"
1767 by (unfold vimage_def) fast
1769 lemma vimageE [elim!]: "a: f -` B ==> (!!x. f a = x ==> x:B ==> P) ==> P"
1770 by (unfold vimage_def) blast
1772 lemma vimageD: "a : f -` A ==> f a : A"
1773 by (unfold vimage_def) fast
1775 lemma vimage_empty [simp]: "f -` {} = {}"
1778 lemma vimage_Compl: "f -` (-A) = -(f -` A)"
1781 lemma vimage_Un [simp]: "f -` (A Un B) = (f -` A) Un (f -` B)"
1784 lemma vimage_Int [simp]: "f -` (A Int B) = (f -` A) Int (f -` B)"
1787 lemma vimage_Collect_eq [simp]: "f -` Collect P = {y. P (f y)}"
1790 lemma vimage_Collect: "(!!x. P (f x) = Q x) ==> f -` (Collect P) = Collect Q"
1793 lemma vimage_insert: "f-`(insert a B) = (f-`{a}) Un (f-`B)"
1794 -- {* NOT suitable for rewriting because of the recurrence of @{term "{a}"}. *}
1797 lemma vimage_Diff: "f -` (A - B) = (f -` A) - (f -` B)"
1800 lemma vimage_UNIV [simp]: "f -` UNIV = UNIV"
1803 lemma vimage_mono: "A \<subseteq> B ==> f -` A \<subseteq> f -` B"
1804 -- {* monotonicity *}
1807 lemma vimage_image_eq: "f -` (f ` A) = {y. EX x:A. f x = f y}"
1808 by (blast intro: sym)
1810 lemma image_vimage_subset: "f ` (f -` A) <= A"
1813 lemma image_vimage_eq [simp]: "f ` (f -` A) = A Int range f"
1816 lemma image_subset_iff_subset_vimage: "f ` A \<subseteq> B \<longleftrightarrow> A \<subseteq> f -` B"
1819 lemma vimage_const [simp]: "((\<lambda>x. c) -` A) = (if c \<in> A then UNIV else {})"
1822 lemma vimage_if [simp]: "((\<lambda>x. if x \<in> B then c else d) -` A) =
1823 (if c \<in> A then (if d \<in> A then UNIV else B)
1824 else if d \<in> A then -B else {})"
1825 by (auto simp add: vimage_def)
1827 lemma vimage_inter_cong:
1828 "(\<And> w. w \<in> S \<Longrightarrow> f w = g w) \<Longrightarrow> f -` y \<inter> S = g -` y \<inter> S"
1831 lemma vimage_ident [simp]: "(%x. x) -` Y = Y"
1835 subsubsection {* Getting the Contents of a Singleton Set *}
1837 definition the_elem :: "'a set \<Rightarrow> 'a" where
1838 "the_elem X = (THE x. X = {x})"
1840 lemma the_elem_eq [simp]: "the_elem {x} = x"
1841 by (simp add: the_elem_def)
1843 lemma the_elem_image_unique:
1844 assumes "A \<noteq> {}"
1845 assumes *: "\<And>y. y \<in> A \<Longrightarrow> f y = f x"
1846 shows "the_elem (f ` A) = f x"
1847 unfolding the_elem_def proof (rule the1_equality)
1848 from `A \<noteq> {}` obtain y where "y \<in> A" by auto
1849 with * have "f x = f y" by simp
1850 with `y \<in> A` have "f x \<in> f ` A" by blast
1851 with * show "f ` A = {f x}" by auto
1852 then show "\<exists>!x. f ` A = {x}" by auto
1856 subsubsection {* Least value operator *}
1859 "mono (f::'a::order => 'b::order) ==> EX x:S. ALL y:S. x <= y
1860 ==> (LEAST y. y : f ` S) = f (LEAST x. x : S)"
1861 -- {* Courtesy of Stephan Merz *}
1863 apply (erule_tac P = "%x. x : S" in LeastI2_order, fast)
1864 apply (rule LeastI2_order)
1865 apply (auto elim: monoD intro!: order_antisym)
1869 subsubsection {* Monad operation *}
1871 definition bind :: "'a set \<Rightarrow> ('a \<Rightarrow> 'b set) \<Rightarrow> 'b set" where
1872 "bind A f = {x. \<exists>B \<in> f`A. x \<in> B}"
1874 hide_const (open) bind
1878 shows "Set.bind (Set.bind A B) C = Set.bind A (\<lambda>x. Set.bind (B x) C)"
1879 by (auto simp add: bind_def)
1881 lemma empty_bind [simp]:
1882 "Set.bind {} f = {}"
1883 by (simp add: bind_def)
1885 lemma nonempty_bind_const:
1886 "A \<noteq> {} \<Longrightarrow> Set.bind A (\<lambda>_. B) = B"
1887 by (auto simp add: bind_def)
1889 lemma bind_const: "Set.bind A (\<lambda>_. B) = (if A = {} then {} else B)"
1890 by (auto simp add: bind_def)
1892 lemma bind_singleton_conv_image: "Set.bind A (\<lambda>x. {f x}) = f ` A"
1893 by(auto simp add: bind_def)
1895 subsubsection {* Operations for execution *}
1897 definition is_empty :: "'a set \<Rightarrow> bool" where
1898 [code_abbrev]: "is_empty A \<longleftrightarrow> A = {}"
1900 hide_const (open) is_empty
1902 definition remove :: "'a \<Rightarrow> 'a set \<Rightarrow> 'a set" where
1903 [code_abbrev]: "remove x A = A - {x}"
1905 hide_const (open) remove
1907 lemma member_remove [simp]:
1908 "x \<in> Set.remove y A \<longleftrightarrow> x \<in> A \<and> x \<noteq> y"
1909 by (simp add: remove_def)
1911 definition filter :: "('a \<Rightarrow> bool) \<Rightarrow> 'a set \<Rightarrow> 'a set" where
1912 [code_abbrev]: "filter P A = {a \<in> A. P a}"
1914 hide_const (open) filter
1916 lemma member_filter [simp]:
1917 "x \<in> Set.filter P A \<longleftrightarrow> x \<in> A \<and> P x"
1918 by (simp add: filter_def)
1920 instantiation set :: (equal) equal
1924 "HOL.equal A B \<longleftrightarrow> A \<subseteq> B \<and> B \<subseteq> A"
1927 qed (auto simp add: equal_set_def)
1934 hide_const (open) member not_member
1936 lemmas equalityI = subset_antisym
1939 val Ball_def = @{thm Ball_def}
1940 val Bex_def = @{thm Bex_def}
1941 val CollectD = @{thm CollectD}
1942 val CollectE = @{thm CollectE}
1943 val CollectI = @{thm CollectI}
1944 val Collect_conj_eq = @{thm Collect_conj_eq}
1945 val Collect_mem_eq = @{thm Collect_mem_eq}
1946 val IntD1 = @{thm IntD1}
1947 val IntD2 = @{thm IntD2}
1948 val IntE = @{thm IntE}
1949 val IntI = @{thm IntI}
1950 val Int_Collect = @{thm Int_Collect}
1951 val UNIV_I = @{thm UNIV_I}
1952 val UNIV_witness = @{thm UNIV_witness}
1953 val UnE = @{thm UnE}
1954 val UnI1 = @{thm UnI1}
1955 val UnI2 = @{thm UnI2}
1956 val ballE = @{thm ballE}
1957 val ballI = @{thm ballI}
1958 val bexCI = @{thm bexCI}
1959 val bexE = @{thm bexE}
1960 val bexI = @{thm bexI}
1961 val bex_triv = @{thm bex_triv}
1962 val bspec = @{thm bspec}
1963 val contra_subsetD = @{thm contra_subsetD}
1964 val equalityCE = @{thm equalityCE}
1965 val equalityD1 = @{thm equalityD1}
1966 val equalityD2 = @{thm equalityD2}
1967 val equalityE = @{thm equalityE}
1968 val equalityI = @{thm equalityI}
1969 val imageE = @{thm imageE}
1970 val imageI = @{thm imageI}
1971 val image_Un = @{thm image_Un}
1972 val image_insert = @{thm image_insert}
1973 val insert_commute = @{thm insert_commute}
1974 val insert_iff = @{thm insert_iff}
1975 val mem_Collect_eq = @{thm mem_Collect_eq}
1976 val rangeE = @{thm rangeE}
1977 val rangeI = @{thm rangeI}
1978 val range_eqI = @{thm range_eqI}
1979 val subsetCE = @{thm subsetCE}
1980 val subsetD = @{thm subsetD}
1981 val subsetI = @{thm subsetI}
1982 val subset_refl = @{thm subset_refl}
1983 val subset_trans = @{thm subset_trans}
1984 val vimageD = @{thm vimageD}
1985 val vimageE = @{thm vimageE}
1986 val vimageI = @{thm vimageI}
1987 val vimageI2 = @{thm vimageI2}
1988 val vimage_Collect = @{thm vimage_Collect}
1989 val vimage_Int = @{thm vimage_Int}
1990 val vimage_Un = @{thm vimage_Un}