1(* Title: HOL/Set.thy 2 Author: Tobias Nipkow 3 Author: Lawrence C Paulson 4 Author: Markus Wenzel 5*) 6 7section \<open>Set theory for higher-order logic\<close> 8 9theory Set 10 imports Lattices 11begin 12 13subsection \<open>Sets as predicates\<close> 14 15typedecl 'a set 16 17axiomatization Collect :: "('a \<Rightarrow> bool) \<Rightarrow> 'a set" \<comment> \<open>comprehension\<close> 18 and member :: "'a \<Rightarrow> 'a set \<Rightarrow> bool" \<comment> \<open>membership\<close> 19 where mem_Collect_eq [iff, code_unfold]: "member a (Collect P) = P a" 20 and Collect_mem_eq [simp]: "Collect (\<lambda>x. member x A) = A" 21 22notation 23 member ("'(\<in>')") and 24 member ("(_/ \<in> _)" [51, 51] 50) 25 26abbreviation not_member 27 where "not_member x A \<equiv> \<not> (x \<in> A)" \<comment> \<open>non-membership\<close> 28notation 29 not_member ("'(\<notin>')") and 30 not_member ("(_/ \<notin> _)" [51, 51] 50) 31 32notation (ASCII) 33 member ("'(:')") and 34 member ("(_/ : _)" [51, 51] 50) and 35 not_member ("'(~:')") and 36 not_member ("(_/ ~: _)" [51, 51] 50) 37 38 39text \<open>Set comprehensions\<close> 40 41syntax 42 "_Coll" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a set" ("(1{_./ _})") 43translations 44 "{x. P}" \<rightleftharpoons> "CONST Collect (\<lambda>x. P)" 45 46syntax (ASCII) 47 "_Collect" :: "pttrn \<Rightarrow> 'a set \<Rightarrow> bool \<Rightarrow> 'a set" ("(1{(_/: _)./ _})") 48syntax 49 "_Collect" :: "pttrn \<Rightarrow> 'a set \<Rightarrow> bool \<Rightarrow> 'a set" ("(1{(_/ \<in> _)./ _})") 50translations 51 "{p:A. P}" \<rightharpoonup> "CONST Collect (\<lambda>p. p \<in> A \<and> P)" 52 53lemma CollectI: "P a \<Longrightarrow> a \<in> {x. P x}" 54 by simp 55 56lemma CollectD: "a \<in> {x. P x} \<Longrightarrow> P a" 57 by simp 58 59lemma Collect_cong: "(\<And>x. P x = Q x) \<Longrightarrow> {x. P x} = {x. Q x}" 60 by simp 61 62text \<open> 63 Simproc for pulling \<open>x = t\<close> in \<open>{x. \<dots> \<and> x = t \<and> \<dots>}\<close> 64 to the front (and similarly for \<open>t = x\<close>): 65\<close> 66 67simproc_setup defined_Collect ("{x. P x \<and> Q x}") = \<open> 68 fn _ => Quantifier1.rearrange_Collect 69 (fn ctxt => 70 resolve_tac ctxt @{thms Collect_cong} 1 THEN 71 resolve_tac ctxt @{thms iffI} 1 THEN 72 ALLGOALS 73 (EVERY' [REPEAT_DETERM o eresolve_tac ctxt @{thms conjE}, 74 DEPTH_SOLVE_1 o (assume_tac ctxt ORELSE' resolve_tac ctxt @{thms conjI})])) 75\<close> 76 77lemmas CollectE = CollectD [elim_format] 78 79lemma set_eqI: 80 assumes "\<And>x. x \<in> A \<longleftrightarrow> x \<in> B" 81 shows "A = B" 82proof - 83 from assms have "{x. x \<in> A} = {x. x \<in> B}" 84 by simp 85 then show ?thesis by simp 86qed 87 88lemma set_eq_iff: "A = B \<longleftrightarrow> (\<forall>x. x \<in> A \<longleftrightarrow> x \<in> B)" 89 by (auto intro:set_eqI) 90 91lemma Collect_eqI: 92 assumes "\<And>x. P x = Q x" 93 shows "Collect P = Collect Q" 94 using assms by (auto intro: set_eqI) 95 96text \<open>Lifting of predicate class instances\<close> 97 98instantiation set :: (type) boolean_algebra 99begin 100 101definition less_eq_set 102 where "A \<le> B \<longleftrightarrow> (\<lambda>x. member x A) \<le> (\<lambda>x. member x B)" 103 104definition less_set 105 where "A < B \<longleftrightarrow> (\<lambda>x. member x A) < (\<lambda>x. member x B)" 106 107definition inf_set 108 where "A \<sqinter> B = Collect ((\<lambda>x. member x A) \<sqinter> (\<lambda>x. member x B))" 109 110definition sup_set 111 where "A \<squnion> B = Collect ((\<lambda>x. member x A) \<squnion> (\<lambda>x. member x B))" 112 113definition bot_set 114 where "\<bottom> = Collect \<bottom>" 115 116definition top_set 117 where "\<top> = Collect \<top>" 118 119definition uminus_set 120 where "- A = Collect (- (\<lambda>x. member x A))" 121 122definition minus_set 123 where "A - B = Collect ((\<lambda>x. member x A) - (\<lambda>x. member x B))" 124 125instance 126 by standard 127 (simp_all add: less_eq_set_def less_set_def inf_set_def sup_set_def 128 bot_set_def top_set_def uminus_set_def minus_set_def 129 less_le_not_le sup_inf_distrib1 diff_eq set_eqI fun_eq_iff 130 del: inf_apply sup_apply bot_apply top_apply minus_apply uminus_apply) 131 132end 133 134text \<open>Set enumerations\<close> 135 136abbreviation empty :: "'a set" ("{}") 137 where "{} \<equiv> bot" 138 139definition insert :: "'a \<Rightarrow> 'a set \<Rightarrow> 'a set" 140 where insert_compr: "insert a B = {x. x = a \<or> x \<in> B}" 141 142syntax 143 "_Finset" :: "args \<Rightarrow> 'a set" ("{(_)}") 144translations 145 "{x, xs}" \<rightleftharpoons> "CONST insert x {xs}" 146 "{x}" \<rightleftharpoons> "CONST insert x {}" 147 148 149subsection \<open>Subsets and bounded quantifiers\<close> 150 151abbreviation subset :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" 152 where "subset \<equiv> less" 153 154abbreviation subset_eq :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" 155 where "subset_eq \<equiv> less_eq" 156 157notation 158 subset ("'(\<subset>')") and 159 subset ("(_/ \<subset> _)" [51, 51] 50) and 160 subset_eq ("'(\<subseteq>')") and 161 subset_eq ("(_/ \<subseteq> _)" [51, 51] 50) 162 163abbreviation (input) 164 supset :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where 165 "supset \<equiv> greater" 166 167abbreviation (input) 168 supset_eq :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where 169 "supset_eq \<equiv> greater_eq" 170 171notation 172 supset ("'(\<supset>')") and 173 supset ("(_/ \<supset> _)" [51, 51] 50) and 174 supset_eq ("'(\<supseteq>')") and 175 supset_eq ("(_/ \<supseteq> _)" [51, 51] 50) 176 177notation (ASCII output) 178 subset ("'(<')") and 179 subset ("(_/ < _)" [51, 51] 50) and 180 subset_eq ("'(<=')") and 181 subset_eq ("(_/ <= _)" [51, 51] 50) 182 183definition Ball :: "'a set \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> bool" 184 where "Ball A P \<longleftrightarrow> (\<forall>x. x \<in> A \<longrightarrow> P x)" \<comment> \<open>bounded universal quantifiers\<close> 185 186definition Bex :: "'a set \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> bool" 187 where "Bex A P \<longleftrightarrow> (\<exists>x. x \<in> A \<and> P x)" \<comment> \<open>bounded existential quantifiers\<close> 188 189syntax (ASCII) 190 "_Ball" :: "pttrn \<Rightarrow> 'a set \<Rightarrow> bool \<Rightarrow> bool" ("(3ALL (_/:_)./ _)" [0, 0, 10] 10) 191 "_Bex" :: "pttrn \<Rightarrow> 'a set \<Rightarrow> bool \<Rightarrow> bool" ("(3EX (_/:_)./ _)" [0, 0, 10] 10) 192 "_Bex1" :: "pttrn \<Rightarrow> 'a set \<Rightarrow> bool \<Rightarrow> bool" ("(3EX! (_/:_)./ _)" [0, 0, 10] 10) 193 "_Bleast" :: "id \<Rightarrow> 'a set \<Rightarrow> bool \<Rightarrow> 'a" ("(3LEAST (_/:_)./ _)" [0, 0, 10] 10) 194 195syntax (input) 196 "_Ball" :: "pttrn \<Rightarrow> 'a set \<Rightarrow> bool \<Rightarrow> bool" ("(3! (_/:_)./ _)" [0, 0, 10] 10) 197 "_Bex" :: "pttrn \<Rightarrow> 'a set \<Rightarrow> bool \<Rightarrow> bool" ("(3? (_/:_)./ _)" [0, 0, 10] 10) 198 "_Bex1" :: "pttrn \<Rightarrow> 'a set \<Rightarrow> bool \<Rightarrow> bool" ("(3?! (_/:_)./ _)" [0, 0, 10] 10) 199 200syntax 201 "_Ball" :: "pttrn \<Rightarrow> 'a set \<Rightarrow> bool \<Rightarrow> bool" ("(3\<forall>(_/\<in>_)./ _)" [0, 0, 10] 10) 202 "_Bex" :: "pttrn \<Rightarrow> 'a set \<Rightarrow> bool \<Rightarrow> bool" ("(3\<exists>(_/\<in>_)./ _)" [0, 0, 10] 10) 203 "_Bex1" :: "pttrn \<Rightarrow> 'a set \<Rightarrow> bool \<Rightarrow> bool" ("(3\<exists>!(_/\<in>_)./ _)" [0, 0, 10] 10) 204 "_Bleast" :: "id \<Rightarrow> 'a set \<Rightarrow> bool \<Rightarrow> 'a" ("(3LEAST(_/\<in>_)./ _)" [0, 0, 10] 10) 205 206translations 207 "\<forall>x\<in>A. P" \<rightleftharpoons> "CONST Ball A (\<lambda>x. P)" 208 "\<exists>x\<in>A. P" \<rightleftharpoons> "CONST Bex A (\<lambda>x. P)" 209 "\<exists>!x\<in>A. P" \<rightharpoonup> "\<exists>!x. x \<in> A \<and> P" 210 "LEAST x:A. P" \<rightharpoonup> "LEAST x. x \<in> A \<and> P" 211 212syntax (ASCII output) 213 "_setlessAll" :: "[idt, 'a, bool] \<Rightarrow> bool" ("(3ALL _<_./ _)" [0, 0, 10] 10) 214 "_setlessEx" :: "[idt, 'a, bool] \<Rightarrow> bool" ("(3EX _<_./ _)" [0, 0, 10] 10) 215 "_setleAll" :: "[idt, 'a, bool] \<Rightarrow> bool" ("(3ALL _<=_./ _)" [0, 0, 10] 10) 216 "_setleEx" :: "[idt, 'a, bool] \<Rightarrow> bool" ("(3EX _<=_./ _)" [0, 0, 10] 10) 217 "_setleEx1" :: "[idt, 'a, bool] \<Rightarrow> bool" ("(3EX! _<=_./ _)" [0, 0, 10] 10) 218 219syntax 220 "_setlessAll" :: "[idt, 'a, bool] \<Rightarrow> bool" ("(3\<forall>_\<subset>_./ _)" [0, 0, 10] 10) 221 "_setlessEx" :: "[idt, 'a, bool] \<Rightarrow> bool" ("(3\<exists>_\<subset>_./ _)" [0, 0, 10] 10) 222 "_setleAll" :: "[idt, 'a, bool] \<Rightarrow> bool" ("(3\<forall>_\<subseteq>_./ _)" [0, 0, 10] 10) 223 "_setleEx" :: "[idt, 'a, bool] \<Rightarrow> bool" ("(3\<exists>_\<subseteq>_./ _)" [0, 0, 10] 10) 224 "_setleEx1" :: "[idt, 'a, bool] \<Rightarrow> bool" ("(3\<exists>!_\<subseteq>_./ _)" [0, 0, 10] 10) 225 226translations 227 "\<forall>A\<subset>B. P" \<rightharpoonup> "\<forall>A. A \<subset> B \<longrightarrow> P" 228 "\<exists>A\<subset>B. P" \<rightharpoonup> "\<exists>A. A \<subset> B \<and> P" 229 "\<forall>A\<subseteq>B. P" \<rightharpoonup> "\<forall>A. A \<subseteq> B \<longrightarrow> P" 230 "\<exists>A\<subseteq>B. P" \<rightharpoonup> "\<exists>A. A \<subseteq> B \<and> P" 231 "\<exists>!A\<subseteq>B. P" \<rightharpoonup> "\<exists>!A. A \<subseteq> B \<and> P" 232 233print_translation \<open> 234 let 235 val All_binder = Mixfix.binder_name @{const_syntax All}; 236 val Ex_binder = Mixfix.binder_name @{const_syntax Ex}; 237 val impl = @{const_syntax HOL.implies}; 238 val conj = @{const_syntax HOL.conj}; 239 val sbset = @{const_syntax subset}; 240 val sbset_eq = @{const_syntax subset_eq}; 241 242 val trans = 243 [((All_binder, impl, sbset), @{syntax_const "_setlessAll"}), 244 ((All_binder, impl, sbset_eq), @{syntax_const "_setleAll"}), 245 ((Ex_binder, conj, sbset), @{syntax_const "_setlessEx"}), 246 ((Ex_binder, conj, sbset_eq), @{syntax_const "_setleEx"})]; 247 248 fun mk v (v', T) c n P = 249 if v = v' andalso not (Term.exists_subterm (fn Free (x, _) => x = v | _ => false) n) 250 then Syntax.const c $ Syntax_Trans.mark_bound_body (v', T) $ n $ P 251 else raise Match; 252 253 fun tr' q = (q, fn _ => 254 (fn [Const (@{syntax_const "_bound"}, _) $ Free (v, Type (@{type_name set}, _)), 255 Const (c, _) $ 256 (Const (d, _) $ (Const (@{syntax_const "_bound"}, _) $ Free (v', T)) $ n) $ P] => 257 (case AList.lookup (=) trans (q, c, d) of 258 NONE => raise Match 259 | SOME l => mk v (v', T) l n P) 260 | _ => raise Match)); 261 in 262 [tr' All_binder, tr' Ex_binder] 263 end 264\<close> 265 266 267text \<open> 268 \<^medskip> 269 Translate between \<open>{e | x1\<dots>xn. P}\<close> and \<open>{u. \<exists>x1\<dots>xn. u = e \<and> P}\<close>; 270 \<open>{y. \<exists>x1\<dots>xn. y = e \<and> P}\<close> is only translated if \<open>[0..n] \<subseteq> bvs e\<close>. 271\<close> 272 273syntax 274 "_Setcompr" :: "'a \<Rightarrow> idts \<Rightarrow> bool \<Rightarrow> 'a set" ("(1{_ |/_./ _})") 275 276parse_translation \<open> 277 let 278 val ex_tr = snd (Syntax_Trans.mk_binder_tr ("EX ", @{const_syntax Ex})); 279 280 fun nvars (Const (@{syntax_const "_idts"}, _) $ _ $ idts) = nvars idts + 1 281 | nvars _ = 1; 282 283 fun setcompr_tr ctxt [e, idts, b] = 284 let 285 val eq = Syntax.const @{const_syntax HOL.eq} $ Bound (nvars idts) $ e; 286 val P = Syntax.const @{const_syntax HOL.conj} $ eq $ b; 287 val exP = ex_tr ctxt [idts, P]; 288 in Syntax.const @{const_syntax Collect} $ absdummy dummyT exP end; 289 290 in [(@{syntax_const "_Setcompr"}, setcompr_tr)] end; 291\<close> 292 293print_translation \<open> 294 [Syntax_Trans.preserve_binder_abs2_tr' @{const_syntax Ball} @{syntax_const "_Ball"}, 295 Syntax_Trans.preserve_binder_abs2_tr' @{const_syntax Bex} @{syntax_const "_Bex"}] 296\<close> \<comment> \<open>to avoid eta-contraction of body\<close> 297 298print_translation \<open> 299let 300 val ex_tr' = snd (Syntax_Trans.mk_binder_tr' (@{const_syntax Ex}, "DUMMY")); 301 302 fun setcompr_tr' ctxt [Abs (abs as (_, _, P))] = 303 let 304 fun check (Const (@{const_syntax Ex}, _) $ Abs (_, _, P), n) = check (P, n + 1) 305 | check (Const (@{const_syntax HOL.conj}, _) $ 306 (Const (@{const_syntax HOL.eq}, _) $ Bound m $ e) $ P, n) = 307 n > 0 andalso m = n andalso not (loose_bvar1 (P, n)) andalso 308 subset (=) (0 upto (n - 1), add_loose_bnos (e, 0, [])) 309 | check _ = false; 310 311 fun tr' (_ $ abs) = 312 let val _ $ idts $ (_ $ (_ $ _ $ e) $ Q) = ex_tr' ctxt [abs] 313 in Syntax.const @{syntax_const "_Setcompr"} $ e $ idts $ Q end; 314 in 315 if check (P, 0) then tr' P 316 else 317 let 318 val (x as _ $ Free(xN, _), t) = Syntax_Trans.atomic_abs_tr' abs; 319 val M = Syntax.const @{syntax_const "_Coll"} $ x $ t; 320 in 321 case t of 322 Const (@{const_syntax HOL.conj}, _) $ 323 (Const (@{const_syntax Set.member}, _) $ 324 (Const (@{syntax_const "_bound"}, _) $ Free (yN, _)) $ A) $ P => 325 if xN = yN then Syntax.const @{syntax_const "_Collect"} $ x $ A $ P else M 326 | _ => M 327 end 328 end; 329 in [(@{const_syntax Collect}, setcompr_tr')] end; 330\<close> 331 332simproc_setup defined_Bex ("\<exists>x\<in>A. P x \<and> Q x") = \<open> 333 fn _ => Quantifier1.rearrange_bex 334 (fn ctxt => 335 unfold_tac ctxt @{thms Bex_def} THEN 336 Quantifier1.prove_one_point_ex_tac ctxt) 337\<close> 338 339simproc_setup defined_All ("\<forall>x\<in>A. P x \<longrightarrow> Q x") = \<open> 340 fn _ => Quantifier1.rearrange_ball 341 (fn ctxt => 342 unfold_tac ctxt @{thms Ball_def} THEN 343 Quantifier1.prove_one_point_all_tac ctxt) 344\<close> 345 346lemma ballI [intro!]: "(\<And>x. x \<in> A \<Longrightarrow> P x) \<Longrightarrow> \<forall>x\<in>A. P x" 347 by (simp add: Ball_def) 348 349lemmas strip = impI allI ballI 350 351lemma bspec [dest?]: "\<forall>x\<in>A. P x \<Longrightarrow> x \<in> A \<Longrightarrow> P x" 352 by (simp add: Ball_def) 353 354text \<open>Gives better instantiation for bound:\<close> 355setup \<open> 356 map_theory_claset (fn ctxt => 357 ctxt addbefore ("bspec", fn ctxt' => dresolve_tac ctxt' @{thms bspec} THEN' assume_tac ctxt')) 358\<close> 359 360ML \<open> 361structure Simpdata = 362struct 363 open Simpdata; 364 val mksimps_pairs = [(@{const_name Ball}, @{thms bspec})] @ mksimps_pairs; 365end; 366 367open Simpdata; 368\<close> 369 370declaration \<open>fn _ => Simplifier.map_ss (Simplifier.set_mksimps (mksimps mksimps_pairs))\<close> 371 372lemma ballE [elim]: "\<forall>x\<in>A. P x \<Longrightarrow> (P x \<Longrightarrow> Q) \<Longrightarrow> (x \<notin> A \<Longrightarrow> Q) \<Longrightarrow> Q" 373 unfolding Ball_def by blast 374 375lemma bexI [intro]: "P x \<Longrightarrow> x \<in> A \<Longrightarrow> \<exists>x\<in>A. P x" 376 \<comment> \<open>Normally the best argument order: \<open>P x\<close> constrains the choice of \<open>x \<in> A\<close>.\<close> 377 unfolding Bex_def by blast 378 379lemma rev_bexI [intro?]: "x \<in> A \<Longrightarrow> P x \<Longrightarrow> \<exists>x\<in>A. P x" 380 \<comment> \<open>The best argument order when there is only one \<open>x \<in> A\<close>.\<close> 381 unfolding Bex_def by blast 382 383lemma bexCI: "(\<forall>x\<in>A. \<not> P x \<Longrightarrow> P a) \<Longrightarrow> a \<in> A \<Longrightarrow> \<exists>x\<in>A. P x" 384 unfolding Bex_def by blast 385 386lemma bexE [elim!]: "\<exists>x\<in>A. P x \<Longrightarrow> (\<And>x. x \<in> A \<Longrightarrow> P x \<Longrightarrow> Q) \<Longrightarrow> Q" 387 unfolding Bex_def by blast 388 389lemma ball_triv [simp]: "(\<forall>x\<in>A. P) \<longleftrightarrow> ((\<exists>x. x \<in> A) \<longrightarrow> P)" 390 \<comment> \<open>Trival rewrite rule.\<close> 391 by (simp add: Ball_def) 392 393lemma bex_triv [simp]: "(\<exists>x\<in>A. P) \<longleftrightarrow> ((\<exists>x. x \<in> A) \<and> P)" 394 \<comment> \<open>Dual form for existentials.\<close> 395 by (simp add: Bex_def) 396 397lemma bex_triv_one_point1 [simp]: "(\<exists>x\<in>A. x = a) \<longleftrightarrow> a \<in> A" 398 by blast 399 400lemma bex_triv_one_point2 [simp]: "(\<exists>x\<in>A. a = x) \<longleftrightarrow> a \<in> A" 401 by blast 402 403lemma bex_one_point1 [simp]: "(\<exists>x\<in>A. x = a \<and> P x) \<longleftrightarrow> a \<in> A \<and> P a" 404 by blast 405 406lemma bex_one_point2 [simp]: "(\<exists>x\<in>A. a = x \<and> P x) \<longleftrightarrow> a \<in> A \<and> P a" 407 by blast 408 409lemma ball_one_point1 [simp]: "(\<forall>x\<in>A. x = a \<longrightarrow> P x) \<longleftrightarrow> (a \<in> A \<longrightarrow> P a)" 410 by blast 411 412lemma ball_one_point2 [simp]: "(\<forall>x\<in>A. a = x \<longrightarrow> P x) \<longleftrightarrow> (a \<in> A \<longrightarrow> P a)" 413 by blast 414 415lemma ball_conj_distrib: "(\<forall>x\<in>A. P x \<and> Q x) \<longleftrightarrow> (\<forall>x\<in>A. P x) \<and> (\<forall>x\<in>A. Q x)" 416 by blast 417 418lemma bex_disj_distrib: "(\<exists>x\<in>A. P x \<or> Q x) \<longleftrightarrow> (\<exists>x\<in>A. P x) \<or> (\<exists>x\<in>A. Q x)" 419 by blast 420 421 422text \<open>Congruence rules\<close> 423 424lemma ball_cong: 425 "A = B \<Longrightarrow> (\<And>x. x \<in> B \<Longrightarrow> P x \<longleftrightarrow> Q x) \<Longrightarrow> 426 (\<forall>x\<in>A. P x) \<longleftrightarrow> (\<forall>x\<in>B. Q x)" 427 by (simp add: Ball_def) 428 429lemma strong_ball_cong [cong]: 430 "A = B \<Longrightarrow> (\<And>x. x \<in> B =simp=> P x \<longleftrightarrow> Q x) \<Longrightarrow> 431 (\<forall>x\<in>A. P x) \<longleftrightarrow> (\<forall>x\<in>B. Q x)" 432 by (simp add: simp_implies_def Ball_def) 433 434lemma bex_cong: 435 "A = B \<Longrightarrow> (\<And>x. x \<in> B \<Longrightarrow> P x \<longleftrightarrow> Q x) \<Longrightarrow> 436 (\<exists>x\<in>A. P x) \<longleftrightarrow> (\<exists>x\<in>B. Q x)" 437 by (simp add: Bex_def cong: conj_cong) 438 439lemma strong_bex_cong [cong]: 440 "A = B \<Longrightarrow> (\<And>x. x \<in> B =simp=> P x \<longleftrightarrow> Q x) \<Longrightarrow> 441 (\<exists>x\<in>A. P x) \<longleftrightarrow> (\<exists>x\<in>B. Q x)" 442 by (simp add: simp_implies_def Bex_def cong: conj_cong) 443 444lemma 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)" 445 by auto 446 447 448subsection \<open>Basic operations\<close> 449 450subsubsection \<open>Subsets\<close> 451 452lemma subsetI [intro!]: "(\<And>x. x \<in> A \<Longrightarrow> x \<in> B) \<Longrightarrow> A \<subseteq> B" 453 by (simp add: less_eq_set_def le_fun_def) 454 455text \<open> 456 \<^medskip> 457 Map the type \<open>'a set \<Rightarrow> anything\<close> to just \<open>'a\<close>; for overloading constants 458 whose first argument has type \<open>'a set\<close>. 459\<close> 460 461lemma subsetD [elim, intro?]: "A \<subseteq> B \<Longrightarrow> c \<in> A \<Longrightarrow> c \<in> B" 462 by (simp add: less_eq_set_def le_fun_def) 463 \<comment> \<open>Rule in Modus Ponens style.\<close> 464 465lemma rev_subsetD [intro?]: "c \<in> A \<Longrightarrow> A \<subseteq> B \<Longrightarrow> c \<in> B" 466 \<comment> \<open>The same, with reversed premises for use with @{method erule} -- cf. @{thm rev_mp}.\<close> 467 by (rule subsetD) 468 469lemma subsetCE [elim]: "A \<subseteq> B \<Longrightarrow> (c \<notin> A \<Longrightarrow> P) \<Longrightarrow> (c \<in> B \<Longrightarrow> P) \<Longrightarrow> P" 470 \<comment> \<open>Classical elimination rule.\<close> 471 by (auto simp add: less_eq_set_def le_fun_def) 472 473lemma subset_eq: "A \<subseteq> B \<longleftrightarrow> (\<forall>x\<in>A. x \<in> B)" 474 by blast 475 476lemma contra_subsetD: "A \<subseteq> B \<Longrightarrow> c \<notin> B \<Longrightarrow> c \<notin> A" 477 by blast 478 479lemma subset_refl: "A \<subseteq> A" 480 by (fact order_refl) (* already [iff] *) 481 482lemma subset_trans: "A \<subseteq> B \<Longrightarrow> B \<subseteq> C \<Longrightarrow> A \<subseteq> C" 483 by (fact order_trans) 484 485lemma set_rev_mp: "x \<in> A \<Longrightarrow> A \<subseteq> B \<Longrightarrow> x \<in> B" 486 by (rule subsetD) 487 488lemma set_mp: "A \<subseteq> B \<Longrightarrow> x \<in> A \<Longrightarrow> x \<in> B" 489 by (rule subsetD) 490 491lemma subset_not_subset_eq [code]: "A \<subset> B \<longleftrightarrow> A \<subseteq> B \<and> \<not> B \<subseteq> A" 492 by (fact less_le_not_le) 493 494lemma eq_mem_trans: "a = b \<Longrightarrow> b \<in> A \<Longrightarrow> a \<in> A" 495 by simp 496 497lemmas basic_trans_rules [trans] = 498 order_trans_rules set_rev_mp set_mp eq_mem_trans 499 500 501subsubsection \<open>Equality\<close> 502 503lemma subset_antisym [intro!]: "A \<subseteq> B \<Longrightarrow> B \<subseteq> A \<Longrightarrow> A = B" 504 \<comment> \<open>Anti-symmetry of the subset relation.\<close> 505 by (iprover intro: set_eqI subsetD) 506 507text \<open>\<^medskip> Equality rules from ZF set theory -- are they appropriate here?\<close> 508 509lemma equalityD1: "A = B \<Longrightarrow> A \<subseteq> B" 510 by simp 511 512lemma equalityD2: "A = B \<Longrightarrow> B \<subseteq> A" 513 by simp 514 515text \<open> 516 \<^medskip> 517 Be careful when adding this to the claset as \<open>subset_empty\<close> is in the 518 simpset: @{prop "A = {}"} goes to @{prop "{} \<subseteq> A"} and @{prop "A \<subseteq> {}"} 519 and then back to @{prop "A = {}"}! 520\<close> 521 522lemma equalityE: "A = B \<Longrightarrow> (A \<subseteq> B \<Longrightarrow> B \<subseteq> A \<Longrightarrow> P) \<Longrightarrow> P" 523 by simp 524 525lemma equalityCE [elim]: "A = B \<Longrightarrow> (c \<in> A \<Longrightarrow> c \<in> B \<Longrightarrow> P) \<Longrightarrow> (c \<notin> A \<Longrightarrow> c \<notin> B \<Longrightarrow> P) \<Longrightarrow> P" 526 by blast 527 528lemma eqset_imp_iff: "A = B \<Longrightarrow> x \<in> A \<longleftrightarrow> x \<in> B" 529 by simp 530 531lemma eqelem_imp_iff: "x = y \<Longrightarrow> x \<in> A \<longleftrightarrow> y \<in> A" 532 by simp 533 534 535subsubsection \<open>The empty set\<close> 536 537lemma empty_def: "{} = {x. False}" 538 by (simp add: bot_set_def bot_fun_def) 539 540lemma empty_iff [simp]: "c \<in> {} \<longleftrightarrow> False" 541 by (simp add: empty_def) 542 543lemma emptyE [elim!]: "a \<in> {} \<Longrightarrow> P" 544 by simp 545 546lemma empty_subsetI [iff]: "{} \<subseteq> A" 547 \<comment> \<open>One effect is to delete the ASSUMPTION @{prop "{} \<subseteq> A"}\<close> 548 by blast 549 550lemma equals0I: "(\<And>y. y \<in> A \<Longrightarrow> False) \<Longrightarrow> A = {}" 551 by blast 552 553lemma equals0D: "A = {} \<Longrightarrow> a \<notin> A" 554 \<comment> \<open>Use for reasoning about disjointness: \<open>A \<inter> B = {}\<close>\<close> 555 by blast 556 557lemma ball_empty [simp]: "Ball {} P \<longleftrightarrow> True" 558 by (simp add: Ball_def) 559 560lemma bex_empty [simp]: "Bex {} P \<longleftrightarrow> False" 561 by (simp add: Bex_def) 562 563 564subsubsection \<open>The universal set -- UNIV\<close> 565 566abbreviation UNIV :: "'a set" 567 where "UNIV \<equiv> top" 568 569lemma UNIV_def: "UNIV = {x. True}" 570 by (simp add: top_set_def top_fun_def) 571 572lemma UNIV_I [simp]: "x \<in> UNIV" 573 by (simp add: UNIV_def) 574 575declare UNIV_I [intro] \<comment> \<open>unsafe makes it less likely to cause problems\<close> 576 577lemma UNIV_witness [intro?]: "\<exists>x. x \<in> UNIV" 578 by simp 579 580lemma subset_UNIV: "A \<subseteq> UNIV" 581 by (fact top_greatest) (* already simp *) 582 583text \<open> 584 \<^medskip> 585 Eta-contracting these two rules (to remove \<open>P\<close>) causes them 586 to be ignored because of their interaction with congruence rules. 587\<close> 588 589lemma ball_UNIV [simp]: "Ball UNIV P \<longleftrightarrow> All P" 590 by (simp add: Ball_def) 591 592lemma bex_UNIV [simp]: "Bex UNIV P \<longleftrightarrow> Ex P" 593 by (simp add: Bex_def) 594 595lemma UNIV_eq_I: "(\<And>x. x \<in> A) \<Longrightarrow> UNIV = A" 596 by auto 597 598lemma UNIV_not_empty [iff]: "UNIV \<noteq> {}" 599 by (blast elim: equalityE) 600 601lemma empty_not_UNIV[simp]: "{} \<noteq> UNIV" 602 by blast 603 604 605subsubsection \<open>The Powerset operator -- Pow\<close> 606 607definition Pow :: "'a set \<Rightarrow> 'a set set" 608 where Pow_def: "Pow A = {B. B \<subseteq> A}" 609 610lemma Pow_iff [iff]: "A \<in> Pow B \<longleftrightarrow> A \<subseteq> B" 611 by (simp add: Pow_def) 612 613lemma PowI: "A \<subseteq> B \<Longrightarrow> A \<in> Pow B" 614 by (simp add: Pow_def) 615 616lemma PowD: "A \<in> Pow B \<Longrightarrow> A \<subseteq> B" 617 by (simp add: Pow_def) 618 619lemma Pow_bottom: "{} \<in> Pow B" 620 by simp 621 622lemma Pow_top: "A \<in> Pow A" 623 by simp 624 625lemma Pow_not_empty: "Pow A \<noteq> {}" 626 using Pow_top by blast 627 628 629subsubsection \<open>Set complement\<close> 630 631lemma Compl_iff [simp]: "c \<in> - A \<longleftrightarrow> c \<notin> A" 632 by (simp add: fun_Compl_def uminus_set_def) 633 634lemma ComplI [intro!]: "(c \<in> A \<Longrightarrow> False) \<Longrightarrow> c \<in> - A" 635 by (simp add: fun_Compl_def uminus_set_def) blast 636 637text \<open> 638 \<^medskip> 639 This form, with negated conclusion, works well with the Classical prover. 640 Negated assumptions behave like formulae on the right side of the 641 notional turnstile \dots 642\<close> 643 644lemma ComplD [dest!]: "c \<in> - A \<Longrightarrow> c \<notin> A" 645 by simp 646 647lemmas ComplE = ComplD [elim_format] 648 649lemma Compl_eq: "- A = {x. \<not> x \<in> A}" 650 by blast 651 652 653subsubsection \<open>Binary intersection\<close> 654 655abbreviation inter :: "'a set \<Rightarrow> 'a set \<Rightarrow> 'a set" (infixl "\<inter>" 70) 656 where "(\<inter>) \<equiv> inf" 657 658notation (ASCII) 659 inter (infixl "Int" 70) 660 661lemma Int_def: "A \<inter> B = {x. x \<in> A \<and> x \<in> B}" 662 by (simp add: inf_set_def inf_fun_def) 663 664lemma Int_iff [simp]: "c \<in> A \<inter> B \<longleftrightarrow> c \<in> A \<and> c \<in> B" 665 unfolding Int_def by blast 666 667lemma IntI [intro!]: "c \<in> A \<Longrightarrow> c \<in> B \<Longrightarrow> c \<in> A \<inter> B" 668 by simp 669 670lemma IntD1: "c \<in> A \<inter> B \<Longrightarrow> c \<in> A" 671 by simp 672 673lemma IntD2: "c \<in> A \<inter> B \<Longrightarrow> c \<in> B" 674 by simp 675 676lemma IntE [elim!]: "c \<in> A \<inter> B \<Longrightarrow> (c \<in> A \<Longrightarrow> c \<in> B \<Longrightarrow> P) \<Longrightarrow> P" 677 by simp 678 679lemma mono_Int: "mono f \<Longrightarrow> f (A \<inter> B) \<subseteq> f A \<inter> f B" 680 by (fact mono_inf) 681 682 683subsubsection \<open>Binary union\<close> 684 685abbreviation union :: "'a set \<Rightarrow> 'a set \<Rightarrow> 'a set" (infixl "\<union>" 65) 686 where "union \<equiv> sup" 687 688notation (ASCII) 689 union (infixl "Un" 65) 690 691lemma Un_def: "A \<union> B = {x. x \<in> A \<or> x \<in> B}" 692 by (simp add: sup_set_def sup_fun_def) 693 694lemma Un_iff [simp]: "c \<in> A \<union> B \<longleftrightarrow> c \<in> A \<or> c \<in> B" 695 unfolding Un_def by blast 696 697lemma UnI1 [elim?]: "c \<in> A \<Longrightarrow> c \<in> A \<union> B" 698 by simp 699 700lemma UnI2 [elim?]: "c \<in> B \<Longrightarrow> c \<in> A \<union> B" 701 by simp 702 703text \<open>\<^medskip> Classical introduction rule: no commitment to \<open>A\<close> vs. \<open>B\<close>.\<close> 704lemma UnCI [intro!]: "(c \<notin> B \<Longrightarrow> c \<in> A) \<Longrightarrow> c \<in> A \<union> B" 705 by auto 706 707lemma UnE [elim!]: "c \<in> A \<union> B \<Longrightarrow> (c \<in> A \<Longrightarrow> P) \<Longrightarrow> (c \<in> B \<Longrightarrow> P) \<Longrightarrow> P" 708 unfolding Un_def by blast 709 710lemma insert_def: "insert a B = {x. x = a} \<union> B" 711 by (simp add: insert_compr Un_def) 712 713lemma mono_Un: "mono f \<Longrightarrow> f A \<union> f B \<subseteq> f (A \<union> B)" 714 by (fact mono_sup) 715 716 717subsubsection \<open>Set difference\<close> 718 719lemma Diff_iff [simp]: "c \<in> A - B \<longleftrightarrow> c \<in> A \<and> c \<notin> B" 720 by (simp add: minus_set_def fun_diff_def) 721 722lemma DiffI [intro!]: "c \<in> A \<Longrightarrow> c \<notin> B \<Longrightarrow> c \<in> A - B" 723 by simp 724 725lemma DiffD1: "c \<in> A - B \<Longrightarrow> c \<in> A" 726 by simp 727 728lemma DiffD2: "c \<in> A - B \<Longrightarrow> c \<in> B \<Longrightarrow> P" 729 by simp 730 731lemma DiffE [elim!]: "c \<in> A - B \<Longrightarrow> (c \<in> A \<Longrightarrow> c \<notin> B \<Longrightarrow> P) \<Longrightarrow> P" 732 by simp 733 734lemma set_diff_eq: "A - B = {x. x \<in> A \<and> x \<notin> B}" 735 by blast 736 737lemma Compl_eq_Diff_UNIV: "- A = (UNIV - A)" 738 by blast 739 740 741subsubsection \<open>Augmenting a set -- @{const insert}\<close> 742 743lemma insert_iff [simp]: "a \<in> insert b A \<longleftrightarrow> a = b \<or> a \<in> A" 744 unfolding insert_def by blast 745 746lemma insertI1: "a \<in> insert a B" 747 by simp 748 749lemma insertI2: "a \<in> B \<Longrightarrow> a \<in> insert b B" 750 by simp 751 752lemma insertE [elim!]: "a \<in> insert b A \<Longrightarrow> (a = b \<Longrightarrow> P) \<Longrightarrow> (a \<in> A \<Longrightarrow> P) \<Longrightarrow> P" 753 unfolding insert_def by blast 754 755lemma insertCI [intro!]: "(a \<notin> B \<Longrightarrow> a = b) \<Longrightarrow> a \<in> insert b B" 756 \<comment> \<open>Classical introduction rule.\<close> 757 by auto 758 759lemma subset_insert_iff: "A \<subseteq> insert x B \<longleftrightarrow> (if x \<in> A then A - {x} \<subseteq> B else A \<subseteq> B)" 760 by auto 761 762lemma set_insert: 763 assumes "x \<in> A" 764 obtains B where "A = insert x B" and "x \<notin> B" 765proof 766 show "A = insert x (A - {x})" using assms by blast 767 show "x \<notin> A - {x}" by blast 768qed 769 770lemma insert_ident: "x \<notin> A \<Longrightarrow> x \<notin> B \<Longrightarrow> insert x A = insert x B \<longleftrightarrow> A = B" 771 by auto 772 773lemma insert_eq_iff: 774 assumes "a \<notin> A" "b \<notin> B" 775 shows "insert a A = insert b B \<longleftrightarrow> 776 (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)" 777 (is "?L \<longleftrightarrow> ?R") 778proof 779 show ?R if ?L 780 proof (cases "a = b") 781 case True 782 with assms \<open>?L\<close> show ?R 783 by (simp add: insert_ident) 784 next 785 case False 786 let ?C = "A - {b}" 787 have "A = insert b ?C \<and> b \<notin> ?C \<and> B = insert a ?C \<and> a \<notin> ?C" 788 using assms \<open>?L\<close> \<open>a \<noteq> b\<close> by auto 789 then show ?R using \<open>a \<noteq> b\<close> by auto 790 qed 791 show ?L if ?R 792 using that by (auto split: if_splits) 793qed 794 795lemma insert_UNIV: "insert x UNIV = UNIV" 796 by auto 797 798 799subsubsection \<open>Singletons, using insert\<close> 800 801lemma singletonI [intro!]: "a \<in> {a}" 802 \<comment> \<open>Redundant? But unlike \<open>insertCI\<close>, it proves the subgoal immediately!\<close> 803 by (rule insertI1) 804 805lemma singletonD [dest!]: "b \<in> {a} \<Longrightarrow> b = a" 806 by blast 807 808lemmas singletonE = singletonD [elim_format] 809 810lemma singleton_iff: "b \<in> {a} \<longleftrightarrow> b = a" 811 by blast 812 813lemma singleton_inject [dest!]: "{a} = {b} \<Longrightarrow> a = b" 814 by blast 815 816lemma singleton_insert_inj_eq [iff]: "{b} = insert a A \<longleftrightarrow> a = b \<and> A \<subseteq> {b}" 817 by blast 818 819lemma singleton_insert_inj_eq' [iff]: "insert a A = {b} \<longleftrightarrow> a = b \<and> A \<subseteq> {b}" 820 by blast 821 822lemma subset_singletonD: "A \<subseteq> {x} \<Longrightarrow> A = {} \<or> A = {x}" 823 by fast 824 825lemma subset_singleton_iff: "X \<subseteq> {a} \<longleftrightarrow> X = {} \<or> X = {a}" 826 by blast 827 828lemma singleton_conv [simp]: "{x. x = a} = {a}" 829 by blast 830 831lemma singleton_conv2 [simp]: "{x. a = x} = {a}" 832 by blast 833 834lemma Diff_single_insert: "A - {x} \<subseteq> B \<Longrightarrow> A \<subseteq> insert x B" 835 by blast 836 837lemma subset_Diff_insert: "A \<subseteq> B - insert x C \<longleftrightarrow> A \<subseteq> B - C \<and> x \<notin> A" 838 by blast 839 840lemma doubleton_eq_iff: "{a, b} = {c, d} \<longleftrightarrow> a = c \<and> b = d \<or> a = d \<and> b = c" 841 by (blast elim: equalityE) 842 843lemma Un_singleton_iff: "A \<union> B = {x} \<longleftrightarrow> A = {} \<and> B = {x} \<or> A = {x} \<and> B = {} \<or> A = {x} \<and> B = {x}" 844 by auto 845 846lemma singleton_Un_iff: "{x} = A \<union> B \<longleftrightarrow> A = {} \<and> B = {x} \<or> A = {x} \<and> B = {} \<or> A = {x} \<and> B = {x}" 847 by auto 848 849 850subsubsection \<open>Image of a set under a function\<close> 851 852text \<open>Frequently \<open>b\<close> does not have the syntactic form of \<open>f x\<close>.\<close> 853 854definition image :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a set \<Rightarrow> 'b set" (infixr "`" 90) 855 where "f ` A = {y. \<exists>x\<in>A. y = f x}" 856 857lemma image_eqI [simp, intro]: "b = f x \<Longrightarrow> x \<in> A \<Longrightarrow> b \<in> f ` A" 858 unfolding image_def by blast 859 860lemma imageI: "x \<in> A \<Longrightarrow> f x \<in> f ` A" 861 by (rule image_eqI) (rule refl) 862 863lemma rev_image_eqI: "x \<in> A \<Longrightarrow> b = f x \<Longrightarrow> b \<in> f ` A" 864 \<comment> \<open>This version's more effective when we already have the required \<open>x\<close>.\<close> 865 by (rule image_eqI) 866 867lemma imageE [elim!]: 868 assumes "b \<in> (\<lambda>x. f x) ` A" \<comment> \<open>The eta-expansion gives variable-name preservation.\<close> 869 obtains x where "b = f x" and "x \<in> A" 870 using assms unfolding image_def by blast 871 872lemma Compr_image_eq: "{x \<in> f ` A. P x} = f ` {x \<in> A. P (f x)}" 873 by auto 874 875lemma image_Un: "f ` (A \<union> B) = f ` A \<union> f ` B" 876 by blast 877 878lemma image_iff: "z \<in> f ` A \<longleftrightarrow> (\<exists>x\<in>A. z = f x)" 879 by blast 880 881lemma image_subsetI: "(\<And>x. x \<in> A \<Longrightarrow> f x \<in> B) \<Longrightarrow> f ` A \<subseteq> B" 882 \<comment> \<open>Replaces the three steps \<open>subsetI\<close>, \<open>imageE\<close>, 883 \<open>hypsubst\<close>, but breaks too many existing proofs.\<close> 884 by blast 885 886lemma image_subset_iff: "f ` A \<subseteq> B \<longleftrightarrow> (\<forall>x\<in>A. f x \<in> B)" 887 \<comment> \<open>This rewrite rule would confuse users if made default.\<close> 888 by blast 889 890lemma subset_imageE: 891 assumes "B \<subseteq> f ` A" 892 obtains C where "C \<subseteq> A" and "B = f ` C" 893proof - 894 from assms have "B = f ` {a \<in> A. f a \<in> B}" by fast 895 moreover have "{a \<in> A. f a \<in> B} \<subseteq> A" by blast 896 ultimately show thesis by (blast intro: that) 897qed 898 899lemma subset_image_iff: "B \<subseteq> f ` A \<longleftrightarrow> (\<exists>AA\<subseteq>A. B = f ` AA)" 900 by (blast elim: subset_imageE) 901 902lemma image_ident [simp]: "(\<lambda>x. x) ` Y = Y" 903 by blast 904 905lemma image_empty [simp]: "f ` {} = {}" 906 by blast 907 908lemma image_insert [simp]: "f ` insert a B = insert (f a) (f ` B)" 909 by blast 910 911lemma image_constant: "x \<in> A \<Longrightarrow> (\<lambda>x. c) ` A = {c}" 912 by auto 913 914lemma image_constant_conv: "(\<lambda>x. c) ` A = (if A = {} then {} else {c})" 915 by auto 916 917lemma image_image: "f ` (g ` A) = (\<lambda>x. f (g x)) ` A" 918 by blast 919 920lemma insert_image [simp]: "x \<in> A \<Longrightarrow> insert (f x) (f ` A) = f ` A" 921 by blast 922 923lemma image_is_empty [iff]: "f ` A = {} \<longleftrightarrow> A = {}" 924 by blast 925 926lemma empty_is_image [iff]: "{} = f ` A \<longleftrightarrow> A = {}" 927 by blast 928 929lemma image_Collect: "f ` {x. P x} = {f x | x. P x}" 930 \<comment> \<open>NOT suitable as a default simp rule: the RHS isn't simpler than the LHS, 931 with its implicit quantifier and conjunction. Also image enjoys better 932 equational properties than does the RHS.\<close> 933 by blast 934 935lemma if_image_distrib [simp]: 936 "(\<lambda>x. if P x then f x else g x) ` S = f ` (S \<inter> {x. P x}) \<union> g ` (S \<inter> {x. \<not> P x})" 937 by auto 938 939lemma image_cong: "M = N \<Longrightarrow> (\<And>x. x \<in> N \<Longrightarrow> f x = g x) \<Longrightarrow> f ` M = g ` N" 940 by (simp add: image_def) 941 942lemma image_Int_subset: "f ` (A \<inter> B) \<subseteq> f ` A \<inter> f ` B" 943 by blast 944 945lemma image_diff_subset: "f ` A - f ` B \<subseteq> f ` (A - B)" 946 by blast 947 948lemma Setcompr_eq_image: "{f x |x. x \<in> A} = f ` A" 949 by blast 950 951lemma setcompr_eq_image: "{f x |x. P x} = f ` {x. P x}" 952 by auto 953 954lemma ball_imageD: "\<forall>x\<in>f ` A. P x \<Longrightarrow> \<forall>x\<in>A. P (f x)" 955 by simp 956 957lemma bex_imageD: "\<exists>x\<in>f ` A. P x \<Longrightarrow> \<exists>x\<in>A. P (f x)" 958 by auto 959 960lemma image_add_0 [simp]: "(+) (0::'a::comm_monoid_add) ` S = S" 961 by auto 962 963 964text \<open>\<^medskip> Range of a function -- just an abbreviation for image!\<close> 965 966abbreviation range :: "('a \<Rightarrow> 'b) \<Rightarrow> 'b set" \<comment> \<open>of function\<close> 967 where "range f \<equiv> f ` UNIV" 968 969lemma range_eqI: "b = f x \<Longrightarrow> b \<in> range f" 970 by simp 971 972lemma rangeI: "f x \<in> range f" 973 by simp 974 975lemma rangeE [elim?]: "b \<in> range (\<lambda>x. f x) \<Longrightarrow> (\<And>x. b = f x \<Longrightarrow> P) \<Longrightarrow> P" 976 by (rule imageE) 977 978lemma full_SetCompr_eq: "{u. \<exists>x. u = f x} = range f" 979 by auto 980 981lemma range_composition: "range (\<lambda>x. f (g x)) = f ` range g" 982 by auto 983 984lemma range_eq_singletonD: "range f = {a} \<Longrightarrow> f x = a" 985 by auto 986 987 988subsubsection \<open>Some rules with \<open>if\<close>\<close> 989 990text \<open>Elimination of \<open>{x. \<dots> \<and> x = t \<and> \<dots>}\<close>.\<close> 991 992lemma Collect_conv_if: "{x. x = a \<and> P x} = (if P a then {a} else {})" 993 by auto 994 995lemma Collect_conv_if2: "{x. a = x \<and> P x} = (if P a then {a} else {})" 996 by auto 997 998text \<open> 999 Rewrite rules for boolean case-splitting: faster than \<open>if_split [split]\<close>. 1000\<close> 1001 1002lemma if_split_eq1: "(if Q then x else y) = b \<longleftrightarrow> (Q \<longrightarrow> x = b) \<and> (\<not> Q \<longrightarrow> y = b)" 1003 by (rule if_split) 1004 1005lemma if_split_eq2: "a = (if Q then x else y) \<longleftrightarrow> (Q \<longrightarrow> a = x) \<and> (\<not> Q \<longrightarrow> a = y)" 1006 by (rule if_split) 1007 1008text \<open> 1009 Split ifs on either side of the membership relation. 1010 Not for \<open>[simp]\<close> -- can cause goals to blow up! 1011\<close> 1012 1013lemma if_split_mem1: "(if Q then x else y) \<in> b \<longleftrightarrow> (Q \<longrightarrow> x \<in> b) \<and> (\<not> Q \<longrightarrow> y \<in> b)" 1014 by (rule if_split) 1015 1016lemma if_split_mem2: "(a \<in> (if Q then x else y)) \<longleftrightarrow> (Q \<longrightarrow> a \<in> x) \<and> (\<not> Q \<longrightarrow> a \<in> y)" 1017 by (rule if_split [where P = "\<lambda>S. a \<in> S"]) 1018 1019lemmas split_ifs = if_bool_eq_conj if_split_eq1 if_split_eq2 if_split_mem1 if_split_mem2 1020 1021(*Would like to add these, but the existing code only searches for the 1022 outer-level constant, which in this case is just Set.member; we instead need 1023 to use term-nets to associate patterns with rules. Also, if a rule fails to 1024 apply, then the formula should be kept. 1025 [("uminus", Compl_iff RS iffD1), ("minus", [Diff_iff RS iffD1]), 1026 ("Int", [IntD1,IntD2]), 1027 ("Collect", [CollectD]), ("Inter", [InterD]), ("INTER", [INT_D])] 1028 *) 1029 1030 1031subsection \<open>Further operations and lemmas\<close> 1032 1033subsubsection \<open>The ``proper subset'' relation\<close> 1034 1035lemma psubsetI [intro!]: "A \<subseteq> B \<Longrightarrow> A \<noteq> B \<Longrightarrow> A \<subset> B" 1036 unfolding less_le by blast 1037 1038lemma psubsetE [elim!]: "A \<subset> B \<Longrightarrow> (A \<subseteq> B \<Longrightarrow> \<not> B \<subseteq> A \<Longrightarrow> R) \<Longrightarrow> R" 1039 unfolding less_le by blast 1040 1041lemma psubset_insert_iff: 1042 "A \<subset> insert x B \<longleftrightarrow> (if x \<in> B then A \<subset> B else if x \<in> A then A - {x} \<subset> B else A \<subseteq> B)" 1043 by (auto simp add: less_le subset_insert_iff) 1044 1045lemma psubset_eq: "A \<subset> B \<longleftrightarrow> A \<subseteq> B \<and> A \<noteq> B" 1046 by (simp only: less_le) 1047 1048lemma psubset_imp_subset: "A \<subset> B \<Longrightarrow> A \<subseteq> B" 1049 by (simp add: psubset_eq) 1050 1051lemma psubset_trans: "A \<subset> B \<Longrightarrow> B \<subset> C \<Longrightarrow> A \<subset> C" 1052 unfolding less_le by (auto dest: subset_antisym) 1053 1054lemma psubsetD: "A \<subset> B \<Longrightarrow> c \<in> A \<Longrightarrow> c \<in> B" 1055 unfolding less_le by (auto dest: subsetD) 1056 1057lemma psubset_subset_trans: "A \<subset> B \<Longrightarrow> B \<subseteq> C \<Longrightarrow> A \<subset> C" 1058 by (auto simp add: psubset_eq) 1059 1060lemma subset_psubset_trans: "A \<subseteq> B \<Longrightarrow> B \<subset> C \<Longrightarrow> A \<subset> C" 1061 by (auto simp add: psubset_eq) 1062 1063lemma psubset_imp_ex_mem: "A \<subset> B \<Longrightarrow> \<exists>b. b \<in> B - A" 1064 unfolding less_le by blast 1065 1066lemma atomize_ball: "(\<And>x. x \<in> A \<Longrightarrow> P x) \<equiv> Trueprop (\<forall>x\<in>A. P x)" 1067 by (simp only: Ball_def atomize_all atomize_imp) 1068 1069lemmas [symmetric, rulify] = atomize_ball 1070 and [symmetric, defn] = atomize_ball 1071 1072lemma image_Pow_mono: "f ` A \<subseteq> B \<Longrightarrow> image f ` Pow A \<subseteq> Pow B" 1073 by blast 1074 1075lemma image_Pow_surj: "f ` A = B \<Longrightarrow> image f ` Pow A = Pow B" 1076 by (blast elim: subset_imageE) 1077 1078 1079subsubsection \<open>Derived rules involving subsets.\<close> 1080 1081text \<open>\<open>insert\<close>.\<close> 1082 1083lemma subset_insertI: "B \<subseteq> insert a B" 1084 by (rule subsetI) (erule insertI2) 1085 1086lemma subset_insertI2: "A \<subseteq> B \<Longrightarrow> A \<subseteq> insert b B" 1087 by blast 1088 1089lemma subset_insert: "x \<notin> A \<Longrightarrow> A \<subseteq> insert x B \<longleftrightarrow> A \<subseteq> B" 1090 by blast 1091 1092 1093text \<open>\<^medskip> Finite Union -- the least upper bound of two sets.\<close> 1094 1095lemma Un_upper1: "A \<subseteq> A \<union> B" 1096 by (fact sup_ge1) 1097 1098lemma Un_upper2: "B \<subseteq> A \<union> B" 1099 by (fact sup_ge2) 1100 1101lemma Un_least: "A \<subseteq> C \<Longrightarrow> B \<subseteq> C \<Longrightarrow> A \<union> B \<subseteq> C" 1102 by (fact sup_least) 1103 1104 1105text \<open>\<^medskip> Finite Intersection -- the greatest lower bound of two sets.\<close> 1106 1107lemma Int_lower1: "A \<inter> B \<subseteq> A" 1108 by (fact inf_le1) 1109 1110lemma Int_lower2: "A \<inter> B \<subseteq> B" 1111 by (fact inf_le2) 1112 1113lemma Int_greatest: "C \<subseteq> A \<Longrightarrow> C \<subseteq> B \<Longrightarrow> C \<subseteq> A \<inter> B" 1114 by (fact inf_greatest) 1115 1116 1117text \<open>\<^medskip> Set difference.\<close> 1118 1119lemma Diff_subset: "A - B \<subseteq> A" 1120 by blast 1121 1122lemma Diff_subset_conv: "A - B \<subseteq> C \<longleftrightarrow> A \<subseteq> B \<union> C" 1123 by blast 1124 1125 1126subsubsection \<open>Equalities involving union, intersection, inclusion, etc.\<close> 1127 1128text \<open>\<open>{}\<close>.\<close> 1129 1130lemma Collect_const [simp]: "{s. P} = (if P then UNIV else {})" 1131 \<comment> \<open>supersedes \<open>Collect_False_empty\<close>\<close> 1132 by auto 1133 1134lemma subset_empty [simp]: "A \<subseteq> {} \<longleftrightarrow> A = {}" 1135 by (fact bot_unique) 1136 1137lemma not_psubset_empty [iff]: "\<not> (A < {})" 1138 by (fact not_less_bot) (* FIXME: already simp *) 1139 1140lemma Collect_empty_eq [simp]: "Collect P = {} \<longleftrightarrow> (\<forall>x. \<not> P x)" 1141 by blast 1142 1143lemma empty_Collect_eq [simp]: "{} = Collect P \<longleftrightarrow> (\<forall>x. \<not> P x)" 1144 by blast 1145 1146lemma Collect_neg_eq: "{x. \<not> P x} = - {x. P x}" 1147 by blast 1148 1149lemma Collect_disj_eq: "{x. P x \<or> Q x} = {x. P x} \<union> {x. Q x}" 1150 by blast 1151 1152lemma Collect_imp_eq: "{x. P x \<longrightarrow> Q x} = - {x. P x} \<union> {x. Q x}" 1153 by blast 1154 1155lemma Collect_conj_eq: "{x. P x \<and> Q x} = {x. P x} \<inter> {x. Q x}" 1156 by blast 1157 1158lemma Collect_mono_iff: "Collect P \<subseteq> Collect Q \<longleftrightarrow> (\<forall>x. P x \<longrightarrow> Q x)" 1159 by blast 1160 1161 1162text \<open>\<^medskip> \<open>insert\<close>.\<close> 1163 1164lemma insert_is_Un: "insert a A = {a} \<union> A" 1165 \<comment> \<open>NOT SUITABLE FOR REWRITING since \<open>{a} \<equiv> insert a {}\<close>\<close> 1166 by blast 1167 1168lemma insert_not_empty [simp]: "insert a A \<noteq> {}" 1169 and empty_not_insert [simp]: "{} \<noteq> insert a A" 1170 by blast+ 1171 1172lemma insert_absorb: "a \<in> A \<Longrightarrow> insert a A = A" 1173 \<comment> \<open>\<open>[simp]\<close> causes recursive calls when there are nested inserts\<close> 1174 \<comment> \<open>with \<^emph>\<open>quadratic\<close> running time\<close> 1175 by blast 1176 1177lemma insert_absorb2 [simp]: "insert x (insert x A) = insert x A" 1178 by blast 1179 1180lemma insert_commute: "insert x (insert y A) = insert y (insert x A)" 1181 by blast 1182 1183lemma insert_subset [simp]: "insert x A \<subseteq> B \<longleftrightarrow> x \<in> B \<and> A \<subseteq> B" 1184 by blast 1185 1186lemma mk_disjoint_insert: "a \<in> A \<Longrightarrow> \<exists>B. A = insert a B \<and> a \<notin> B" 1187 \<comment> \<open>use new \<open>B\<close> rather than \<open>A - {a}\<close> to avoid infinite unfolding\<close> 1188 by (rule exI [where x = "A - {a}"]) blast 1189 1190lemma insert_Collect: "insert a (Collect P) = {u. u \<noteq> a \<longrightarrow> P u}" 1191 by auto 1192 1193lemma insert_inter_insert [simp]: "insert a A \<inter> insert a B = insert a (A \<inter> B)" 1194 by blast 1195 1196lemma insert_disjoint [simp]: 1197 "insert a A \<inter> B = {} \<longleftrightarrow> a \<notin> B \<and> A \<inter> B = {}" 1198 "{} = insert a A \<inter> B \<longleftrightarrow> a \<notin> B \<and> {} = A \<inter> B" 1199 by auto 1200 1201lemma disjoint_insert [simp]: 1202 "B \<inter> insert a A = {} \<longleftrightarrow> a \<notin> B \<and> B \<inter> A = {}" 1203 "{} = A \<inter> insert b B \<longleftrightarrow> b \<notin> A \<and> {} = A \<inter> B" 1204 by auto 1205 1206 1207text \<open>\<^medskip> \<open>Int\<close>\<close> 1208 1209lemma Int_absorb: "A \<inter> A = A" 1210 by (fact inf_idem) (* already simp *) 1211 1212lemma Int_left_absorb: "A \<inter> (A \<inter> B) = A \<inter> B" 1213 by (fact inf_left_idem) 1214 1215lemma Int_commute: "A \<inter> B = B \<inter> A" 1216 by (fact inf_commute) 1217 1218lemma Int_left_commute: "A \<inter> (B \<inter> C) = B \<inter> (A \<inter> C)" 1219 by (fact inf_left_commute) 1220 1221lemma Int_assoc: "(A \<inter> B) \<inter> C = A \<inter> (B \<inter> C)" 1222 by (fact inf_assoc) 1223 1224lemmas Int_ac = Int_assoc Int_left_absorb Int_commute Int_left_commute 1225 \<comment> \<open>Intersection is an AC-operator\<close> 1226 1227lemma Int_absorb1: "B \<subseteq> A \<Longrightarrow> A \<inter> B = B" 1228 by (fact inf_absorb2) 1229 1230lemma Int_absorb2: "A \<subseteq> B \<Longrightarrow> A \<inter> B = A" 1231 by (fact inf_absorb1) 1232 1233lemma Int_empty_left: "{} \<inter> B = {}" 1234 by (fact inf_bot_left) (* already simp *) 1235 1236lemma Int_empty_right: "A \<inter> {} = {}" 1237 by (fact inf_bot_right) (* already simp *) 1238 1239lemma disjoint_eq_subset_Compl: "A \<inter> B = {} \<longleftrightarrow> A \<subseteq> - B" 1240 by blast 1241 1242lemma disjoint_iff_not_equal: "A \<inter> B = {} \<longleftrightarrow> (\<forall>x\<in>A. \<forall>y\<in>B. x \<noteq> y)" 1243 by blast 1244 1245lemma Int_UNIV_left: "UNIV \<inter> B = B" 1246 by (fact inf_top_left) (* already simp *) 1247 1248lemma Int_UNIV_right: "A \<inter> UNIV = A" 1249 by (fact inf_top_right) (* already simp *) 1250 1251lemma Int_Un_distrib: "A \<inter> (B \<union> C) = (A \<inter> B) \<union> (A \<inter> C)" 1252 by (fact inf_sup_distrib1) 1253 1254lemma Int_Un_distrib2: "(B \<union> C) \<inter> A = (B \<inter> A) \<union> (C \<inter> A)" 1255 by (fact inf_sup_distrib2) 1256 1257lemma Int_UNIV [simp]: "A \<inter> B = UNIV \<longleftrightarrow> A = UNIV \<and> B = UNIV" 1258 by (fact inf_eq_top_iff) (* already simp *) 1259 1260lemma Int_subset_iff [simp]: "C \<subseteq> A \<inter> B \<longleftrightarrow> C \<subseteq> A \<and> C \<subseteq> B" 1261 by (fact le_inf_iff) 1262 1263lemma Int_Collect: "x \<in> A \<inter> {x. P x} \<longleftrightarrow> x \<in> A \<and> P x" 1264 by blast 1265 1266 1267text \<open>\<^medskip> \<open>Un\<close>.\<close> 1268 1269lemma Un_absorb: "A \<union> A = A" 1270 by (fact sup_idem) (* already simp *) 1271 1272lemma Un_left_absorb: "A \<union> (A \<union> B) = A \<union> B" 1273 by (fact sup_left_idem) 1274 1275lemma Un_commute: "A \<union> B = B \<union> A" 1276 by (fact sup_commute) 1277 1278lemma Un_left_commute: "A \<union> (B \<union> C) = B \<union> (A \<union> C)" 1279 by (fact sup_left_commute) 1280 1281lemma Un_assoc: "(A \<union> B) \<union> C = A \<union> (B \<union> C)" 1282 by (fact sup_assoc) 1283 1284lemmas Un_ac = Un_assoc Un_left_absorb Un_commute Un_left_commute 1285 \<comment> \<open>Union is an AC-operator\<close> 1286 1287lemma Un_absorb1: "A \<subseteq> B \<Longrightarrow> A \<union> B = B" 1288 by (fact sup_absorb2) 1289 1290lemma Un_absorb2: "B \<subseteq> A \<Longrightarrow> A \<union> B = A" 1291 by (fact sup_absorb1) 1292 1293lemma Un_empty_left: "{} \<union> B = B" 1294 by (fact sup_bot_left) (* already simp *) 1295 1296lemma Un_empty_right: "A \<union> {} = A" 1297 by (fact sup_bot_right) (* already simp *) 1298 1299lemma Un_UNIV_left: "UNIV \<union> B = UNIV" 1300 by (fact sup_top_left) (* already simp *) 1301 1302lemma Un_UNIV_right: "A \<union> UNIV = UNIV" 1303 by (fact sup_top_right) (* already simp *) 1304 1305lemma Un_insert_left [simp]: "(insert a B) \<union> C = insert a (B \<union> C)" 1306 by blast 1307 1308lemma Un_insert_right [simp]: "A \<union> (insert a B) = insert a (A \<union> B)" 1309 by blast 1310 1311lemma Int_insert_left: "(insert a B) \<inter> C = (if a \<in> C then insert a (B \<inter> C) else B \<inter> C)" 1312 by auto 1313 1314lemma Int_insert_left_if0 [simp]: "a \<notin> C \<Longrightarrow> (insert a B) \<inter> C = B \<inter> C" 1315 by auto 1316 1317lemma Int_insert_left_if1 [simp]: "a \<in> C \<Longrightarrow> (insert a B) \<inter> C = insert a (B \<inter> C)" 1318 by auto 1319 1320lemma Int_insert_right: "A \<inter> (insert a B) = (if a \<in> A then insert a (A \<inter> B) else A \<inter> B)" 1321 by auto 1322 1323lemma Int_insert_right_if0 [simp]: "a \<notin> A \<Longrightarrow> A \<inter> (insert a B) = A \<inter> B" 1324 by auto 1325 1326lemma Int_insert_right_if1 [simp]: "a \<in> A \<Longrightarrow> A \<inter> (insert a B) = insert a (A \<inter> B)" 1327 by auto 1328 1329lemma Un_Int_distrib: "A \<union> (B \<inter> C) = (A \<union> B) \<inter> (A \<union> C)" 1330 by (fact sup_inf_distrib1) 1331 1332lemma Un_Int_distrib2: "(B \<inter> C) \<union> A = (B \<union> A) \<inter> (C \<union> A)" 1333 by (fact sup_inf_distrib2) 1334 1335lemma Un_Int_crazy: "(A \<inter> B) \<union> (B \<inter> C) \<union> (C \<inter> A) = (A \<union> B) \<inter> (B \<union> C) \<inter> (C \<union> A)" 1336 by blast 1337 1338lemma subset_Un_eq: "A \<subseteq> B \<longleftrightarrow> A \<union> B = B" 1339 by (fact le_iff_sup) 1340 1341lemma Un_empty [iff]: "A \<union> B = {} \<longleftrightarrow> A = {} \<and> B = {}" 1342 by (fact sup_eq_bot_iff) (* FIXME: already simp *) 1343 1344lemma Un_subset_iff [simp]: "A \<union> B \<subseteq> C \<longleftrightarrow> A \<subseteq> C \<and> B \<subseteq> C" 1345 by (fact le_sup_iff) 1346 1347lemma Un_Diff_Int: "(A - B) \<union> (A \<inter> B) = A" 1348 by blast 1349 1350lemma Diff_Int2: "A \<inter> C - B \<inter> C = A \<inter> C - B" 1351 by blast 1352 1353 1354text \<open>\<^medskip> Set complement\<close> 1355 1356lemma Compl_disjoint [simp]: "A \<inter> - A = {}" 1357 by (fact inf_compl_bot) 1358 1359lemma Compl_disjoint2 [simp]: "- A \<inter> A = {}" 1360 by (fact compl_inf_bot) 1361 1362lemma Compl_partition: "A \<union> - A = UNIV" 1363 by (fact sup_compl_top) 1364 1365lemma Compl_partition2: "- A \<union> A = UNIV" 1366 by (fact compl_sup_top) 1367 1368lemma double_complement: "- (-A) = A" for A :: "'a set" 1369 by (fact double_compl) (* already simp *) 1370 1371lemma Compl_Un: "- (A \<union> B) = (- A) \<inter> (- B)" 1372 by (fact compl_sup) (* already simp *) 1373 1374lemma Compl_Int: "- (A \<inter> B) = (- A) \<union> (- B)" 1375 by (fact compl_inf) (* already simp *) 1376 1377lemma subset_Compl_self_eq: "A \<subseteq> - A \<longleftrightarrow> A = {}" 1378 by blast 1379 1380lemma Un_Int_assoc_eq: "(A \<inter> B) \<union> C = A \<inter> (B \<union> C) \<longleftrightarrow> C \<subseteq> A" 1381 \<comment> \<open>Halmos, Naive Set Theory, page 16.\<close> 1382 by blast 1383 1384lemma Compl_UNIV_eq: "- UNIV = {}" 1385 by (fact compl_top_eq) (* already simp *) 1386 1387lemma Compl_empty_eq: "- {} = UNIV" 1388 by (fact compl_bot_eq) (* already simp *) 1389 1390lemma Compl_subset_Compl_iff [iff]: "- A \<subseteq> - B \<longleftrightarrow> B \<subseteq> A" 1391 by (fact compl_le_compl_iff) (* FIXME: already simp *) 1392 1393lemma Compl_eq_Compl_iff [iff]: "- A = - B \<longleftrightarrow> A = B" 1394 for A B :: "'a set" 1395 by (fact compl_eq_compl_iff) (* FIXME: already simp *) 1396 1397lemma Compl_insert: "- insert x A = (- A) - {x}" 1398 by blast 1399 1400text \<open>\<^medskip> Bounded quantifiers. 1401 1402 The following are not added to the default simpset because 1403 (a) they duplicate the body and (b) there are no similar rules for \<open>Int\<close>. 1404\<close> 1405 1406lemma ball_Un: "(\<forall>x \<in> A \<union> B. P x) \<longleftrightarrow> (\<forall>x\<in>A. P x) \<and> (\<forall>x\<in>B. P x)" 1407 by blast 1408 1409lemma bex_Un: "(\<exists>x \<in> A \<union> B. P x) \<longleftrightarrow> (\<exists>x\<in>A. P x) \<or> (\<exists>x\<in>B. P x)" 1410 by blast 1411 1412 1413text \<open>\<^medskip> Set difference.\<close> 1414 1415lemma Diff_eq: "A - B = A \<inter> (- B)" 1416 by blast 1417 1418lemma Diff_eq_empty_iff [simp]: "A - B = {} \<longleftrightarrow> A \<subseteq> B" 1419 by blast 1420 1421lemma Diff_cancel [simp]: "A - A = {}" 1422 by blast 1423 1424lemma Diff_idemp [simp]: "(A - B) - B = A - B" 1425 for A B :: "'a set" 1426 by blast 1427 1428lemma Diff_triv: "A \<inter> B = {} \<Longrightarrow> A - B = A" 1429 by (blast elim: equalityE) 1430 1431lemma empty_Diff [simp]: "{} - A = {}" 1432 by blast 1433 1434lemma Diff_empty [simp]: "A - {} = A" 1435 by blast 1436 1437lemma Diff_UNIV [simp]: "A - UNIV = {}" 1438 by blast 1439 1440lemma Diff_insert0 [simp]: "x \<notin> A \<Longrightarrow> A - insert x B = A - B" 1441 by blast 1442 1443lemma Diff_insert: "A - insert a B = A - B - {a}" 1444 \<comment> \<open>NOT SUITABLE FOR REWRITING since \<open>{a} \<equiv> insert a 0\<close>\<close> 1445 by blast 1446 1447lemma Diff_insert2: "A - insert a B = A - {a} - B" 1448 \<comment> \<open>NOT SUITABLE FOR REWRITING since \<open>{a} \<equiv> insert a 0\<close>\<close> 1449 by blast 1450 1451lemma insert_Diff_if: "insert x A - B = (if x \<in> B then A - B else insert x (A - B))" 1452 by auto 1453 1454lemma insert_Diff1 [simp]: "x \<in> B \<Longrightarrow> insert x A - B = A - B" 1455 by blast 1456 1457lemma insert_Diff_single[simp]: "insert a (A - {a}) = insert a A" 1458 by blast 1459 1460lemma insert_Diff: "a \<in> A \<Longrightarrow> insert a (A - {a}) = A" 1461 by blast 1462 1463lemma Diff_insert_absorb: "x \<notin> A \<Longrightarrow> (insert x A) - {x} = A" 1464 by auto 1465 1466lemma Diff_disjoint [simp]: "A \<inter> (B - A) = {}" 1467 by blast 1468 1469lemma Diff_partition: "A \<subseteq> B \<Longrightarrow> A \<union> (B - A) = B" 1470 by blast 1471 1472lemma double_diff: "A \<subseteq> B \<Longrightarrow> B \<subseteq> C \<Longrightarrow> B - (C - A) = A" 1473 by blast 1474 1475lemma Un_Diff_cancel [simp]: "A \<union> (B - A) = A \<union> B" 1476 by blast 1477 1478lemma Un_Diff_cancel2 [simp]: "(B - A) \<union> A = B \<union> A" 1479 by blast 1480 1481lemma Diff_Un: "A - (B \<union> C) = (A - B) \<inter> (A - C)" 1482 by blast 1483 1484lemma Diff_Int: "A - (B \<inter> C) = (A - B) \<union> (A - C)" 1485 by blast 1486 1487lemma Diff_Diff_Int: "A - (A - B) = A \<inter> B" 1488 by blast 1489 1490lemma Un_Diff: "(A \<union> B) - C = (A - C) \<union> (B - C)" 1491 by blast 1492 1493lemma Int_Diff: "(A \<inter> B) - C = A \<inter> (B - C)" 1494 by blast 1495 1496lemma Diff_Int_distrib: "C \<inter> (A - B) = (C \<inter> A) - (C \<inter> B)" 1497 by blast 1498 1499lemma Diff_Int_distrib2: "(A - B) \<inter> C = (A \<inter> C) - (B \<inter> C)" 1500 by blast 1501 1502lemma Diff_Compl [simp]: "A - (- B) = A \<inter> B" 1503 by auto 1504 1505lemma Compl_Diff_eq [simp]: "- (A - B) = - A \<union> B" 1506 by blast 1507 1508lemma subset_Compl_singleton [simp]: "A \<subseteq> - {b} \<longleftrightarrow> b \<notin> A" 1509 by blast 1510 1511text \<open>\<^medskip> Quantification over type @{typ bool}.\<close> 1512 1513lemma bool_induct: "P True \<Longrightarrow> P False \<Longrightarrow> P x" 1514 by (cases x) auto 1515 1516lemma all_bool_eq: "(\<forall>b. P b) \<longleftrightarrow> P True \<and> P False" 1517 by (auto intro: bool_induct) 1518 1519lemma bool_contrapos: "P x \<Longrightarrow> \<not> P False \<Longrightarrow> P True" 1520 by (cases x) auto 1521 1522lemma ex_bool_eq: "(\<exists>b. P b) \<longleftrightarrow> P True \<or> P False" 1523 by (auto intro: bool_contrapos) 1524 1525lemma UNIV_bool: "UNIV = {False, True}" 1526 by (auto intro: bool_induct) 1527 1528text \<open>\<^medskip> \<open>Pow\<close>\<close> 1529 1530lemma Pow_empty [simp]: "Pow {} = {{}}" 1531 by (auto simp add: Pow_def) 1532 1533lemma Pow_singleton_iff [simp]: "Pow X = {Y} \<longleftrightarrow> X = {} \<and> Y = {}" 1534 by blast (* somewhat slow *) 1535 1536lemma Pow_insert: "Pow (insert a A) = Pow A \<union> (insert a ` Pow A)" 1537 by (blast intro: image_eqI [where ?x = "u - {a}" for u]) 1538 1539lemma Pow_Compl: "Pow (- A) = {- B | B. A \<in> Pow B}" 1540 by (blast intro: exI [where ?x = "- u" for u]) 1541 1542lemma Pow_UNIV [simp]: "Pow UNIV = UNIV" 1543 by blast 1544 1545lemma Un_Pow_subset: "Pow A \<union> Pow B \<subseteq> Pow (A \<union> B)" 1546 by blast 1547 1548lemma Pow_Int_eq [simp]: "Pow (A \<inter> B) = Pow A \<inter> Pow B" 1549 by blast 1550 1551 1552text \<open>\<^medskip> Miscellany.\<close> 1553 1554lemma set_eq_subset: "A = B \<longleftrightarrow> A \<subseteq> B \<and> B \<subseteq> A" 1555 by blast 1556 1557lemma subset_iff: "A \<subseteq> B \<longleftrightarrow> (\<forall>t. t \<in> A \<longrightarrow> t \<in> B)" 1558 by blast 1559 1560lemma subset_iff_psubset_eq: "A \<subseteq> B \<longleftrightarrow> A \<subset> B \<or> A = B" 1561 unfolding less_le by blast 1562 1563lemma all_not_in_conv [simp]: "(\<forall>x. x \<notin> A) \<longleftrightarrow> A = {}" 1564 by blast 1565 1566lemma ex_in_conv: "(\<exists>x. x \<in> A) \<longleftrightarrow> A \<noteq> {}" 1567 by blast 1568 1569lemma ball_simps [simp, no_atp]: 1570 "\<And>A P Q. (\<forall>x\<in>A. P x \<or> Q) \<longleftrightarrow> ((\<forall>x\<in>A. P x) \<or> Q)" 1571 "\<And>A P Q. (\<forall>x\<in>A. P \<or> Q x) \<longleftrightarrow> (P \<or> (\<forall>x\<in>A. Q x))" 1572 "\<And>A P Q. (\<forall>x\<in>A. P \<longrightarrow> Q x) \<longleftrightarrow> (P \<longrightarrow> (\<forall>x\<in>A. Q x))" 1573 "\<And>A P Q. (\<forall>x\<in>A. P x \<longrightarrow> Q) \<longleftrightarrow> ((\<exists>x\<in>A. P x) \<longrightarrow> Q)" 1574 "\<And>P. (\<forall>x\<in>{}. P x) \<longleftrightarrow> True" 1575 "\<And>P. (\<forall>x\<in>UNIV. P x) \<longleftrightarrow> (\<forall>x. P x)" 1576 "\<And>a B P. (\<forall>x\<in>insert a B. P x) \<longleftrightarrow> (P a \<and> (\<forall>x\<in>B. P x))" 1577 "\<And>P Q. (\<forall>x\<in>Collect Q. P x) \<longleftrightarrow> (\<forall>x. Q x \<longrightarrow> P x)" 1578 "\<And>A P f. (\<forall>x\<in>f`A. P x) \<longleftrightarrow> (\<forall>x\<in>A. P (f x))" 1579 "\<And>A P. (\<not> (\<forall>x\<in>A. P x)) \<longleftrightarrow> (\<exists>x\<in>A. \<not> P x)" 1580 by auto 1581 1582lemma bex_simps [simp, no_atp]: 1583 "\<And>A P Q. (\<exists>x\<in>A. P x \<and> Q) \<longleftrightarrow> ((\<exists>x\<in>A. P x) \<and> Q)" 1584 "\<And>A P Q. (\<exists>x\<in>A. P \<and> Q x) \<longleftrightarrow> (P \<and> (\<exists>x\<in>A. Q x))" 1585 "\<And>P. (\<exists>x\<in>{}. P x) \<longleftrightarrow> False" 1586 "\<And>P. (\<exists>x\<in>UNIV. P x) \<longleftrightarrow> (\<exists>x. P x)" 1587 "\<And>a B P. (\<exists>x\<in>insert a B. P x) \<longleftrightarrow> (P a \<or> (\<exists>x\<in>B. P x))" 1588 "\<And>P Q. (\<exists>x\<in>Collect Q. P x) \<longleftrightarrow> (\<exists>x. Q x \<and> P x)" 1589 "\<And>A P f. (\<exists>x\<in>f`A. P x) \<longleftrightarrow> (\<exists>x\<in>A. P (f x))" 1590 "\<And>A P. (\<not>(\<exists>x\<in>A. P x)) \<longleftrightarrow> (\<forall>x\<in>A. \<not> P x)" 1591 by auto 1592 1593 1594subsubsection \<open>Monotonicity of various operations\<close> 1595 1596lemma image_mono: "A \<subseteq> B \<Longrightarrow> f ` A \<subseteq> f ` B" 1597 by blast 1598 1599lemma Pow_mono: "A \<subseteq> B \<Longrightarrow> Pow A \<subseteq> Pow B" 1600 by blast 1601 1602lemma insert_mono: "C \<subseteq> D \<Longrightarrow> insert a C \<subseteq> insert a D" 1603 by blast 1604 1605lemma Un_mono: "A \<subseteq> C \<Longrightarrow> B \<subseteq> D \<Longrightarrow> A \<union> B \<subseteq> C \<union> D" 1606 by (fact sup_mono) 1607 1608lemma Int_mono: "A \<subseteq> C \<Longrightarrow> B \<subseteq> D \<Longrightarrow> A \<inter> B \<subseteq> C \<inter> D" 1609 by (fact inf_mono) 1610 1611lemma Diff_mono: "A \<subseteq> C \<Longrightarrow> D \<subseteq> B \<Longrightarrow> A - B \<subseteq> C - D" 1612 by blast 1613 1614lemma Compl_anti_mono: "A \<subseteq> B \<Longrightarrow> - B \<subseteq> - A" 1615 by (fact compl_mono) 1616 1617text \<open>\<^medskip> Monotonicity of implications.\<close> 1618 1619lemma in_mono: "A \<subseteq> B \<Longrightarrow> x \<in> A \<longrightarrow> x \<in> B" 1620 by (rule impI) (erule subsetD) 1621 1622lemma conj_mono: "P1 \<longrightarrow> Q1 \<Longrightarrow> P2 \<longrightarrow> Q2 \<Longrightarrow> (P1 \<and> P2) \<longrightarrow> (Q1 \<and> Q2)" 1623 by iprover 1624 1625lemma disj_mono: "P1 \<longrightarrow> Q1 \<Longrightarrow> P2 \<longrightarrow> Q2 \<Longrightarrow> (P1 \<or> P2) \<longrightarrow> (Q1 \<or> Q2)" 1626 by iprover 1627 1628lemma imp_mono: "Q1 \<longrightarrow> P1 \<Longrightarrow> P2 \<longrightarrow> Q2 \<Longrightarrow> (P1 \<longrightarrow> P2) \<longrightarrow> (Q1 \<longrightarrow> Q2)" 1629 by iprover 1630 1631lemma imp_refl: "P \<longrightarrow> P" .. 1632 1633lemma not_mono: "Q \<longrightarrow> P \<Longrightarrow> \<not> P \<longrightarrow> \<not> Q" 1634 by iprover 1635 1636lemma ex_mono: "(\<And>x. P x \<longrightarrow> Q x) \<Longrightarrow> (\<exists>x. P x) \<longrightarrow> (\<exists>x. Q x)" 1637 by iprover 1638 1639lemma all_mono: "(\<And>x. P x \<longrightarrow> Q x) \<Longrightarrow> (\<forall>x. P x) \<longrightarrow> (\<forall>x. Q x)" 1640 by iprover 1641 1642lemma Collect_mono: "(\<And>x. P x \<longrightarrow> Q x) \<Longrightarrow> Collect P \<subseteq> Collect Q" 1643 by blast 1644 1645lemma Int_Collect_mono: "A \<subseteq> B \<Longrightarrow> (\<And>x. x \<in> A \<Longrightarrow> P x \<longrightarrow> Q x) \<Longrightarrow> A \<inter> Collect P \<subseteq> B \<inter> Collect Q" 1646 by blast 1647 1648lemmas basic_monos = 1649 subset_refl imp_refl disj_mono conj_mono ex_mono Collect_mono in_mono 1650 1651lemma eq_to_mono: "a = b \<Longrightarrow> c = d \<Longrightarrow> b \<longrightarrow> d \<Longrightarrow> a \<longrightarrow> c" 1652 by iprover 1653 1654 1655subsubsection \<open>Inverse image of a function\<close> 1656 1657definition vimage :: "('a \<Rightarrow> 'b) \<Rightarrow> 'b set \<Rightarrow> 'a set" (infixr "-`" 90) 1658 where "f -` B \<equiv> {x. f x \<in> B}" 1659 1660lemma vimage_eq [simp]: "a \<in> f -` B \<longleftrightarrow> f a \<in> B" 1661 unfolding vimage_def by blast 1662 1663lemma vimage_singleton_eq: "a \<in> f -` {b} \<longleftrightarrow> f a = b" 1664 by simp 1665 1666lemma vimageI [intro]: "f a = b \<Longrightarrow> b \<in> B \<Longrightarrow> a \<in> f -` B" 1667 unfolding vimage_def by blast 1668 1669lemma vimageI2: "f a \<in> A \<Longrightarrow> a \<in> f -` A" 1670 unfolding vimage_def by fast 1671 1672lemma vimageE [elim!]: "a \<in> f -` B \<Longrightarrow> (\<And>x. f a = x \<Longrightarrow> x \<in> B \<Longrightarrow> P) \<Longrightarrow> P" 1673 unfolding vimage_def by blast 1674 1675lemma vimageD: "a \<in> f -` A \<Longrightarrow> f a \<in> A" 1676 unfolding vimage_def by fast 1677 1678lemma vimage_empty [simp]: "f -` {} = {}" 1679 by blast 1680 1681lemma vimage_Compl: "f -` (- A) = - (f -` A)" 1682 by blast 1683 1684lemma vimage_Un [simp]: "f -` (A \<union> B) = (f -` A) \<union> (f -` B)" 1685 by blast 1686 1687lemma vimage_Int [simp]: "f -` (A \<inter> B) = (f -` A) \<inter> (f -` B)" 1688 by fast 1689 1690lemma vimage_Collect_eq [simp]: "f -` Collect P = {y. P (f y)}" 1691 by blast 1692 1693lemma vimage_Collect: "(\<And>x. P (f x) = Q x) \<Longrightarrow> f -` (Collect P) = Collect Q" 1694 by blast 1695 1696lemma vimage_insert: "f -` (insert a B) = (f -` {a}) \<union> (f -` B)" 1697 \<comment> \<open>NOT suitable for rewriting because of the recurrence of \<open>{a}\<close>.\<close> 1698 by blast 1699 1700lemma vimage_Diff: "f -` (A - B) = (f -` A) - (f -` B)" 1701 by blast 1702 1703lemma vimage_UNIV [simp]: "f -` UNIV = UNIV" 1704 by blast 1705 1706lemma vimage_mono: "A \<subseteq> B \<Longrightarrow> f -` A \<subseteq> f -` B" 1707 \<comment> \<open>monotonicity\<close> 1708 by blast 1709 1710lemma vimage_image_eq: "f -` (f ` A) = {y. \<exists>x\<in>A. f x = f y}" 1711 by (blast intro: sym) 1712 1713lemma image_vimage_subset: "f ` (f -` A) \<subseteq> A" 1714 by blast 1715 1716lemma image_vimage_eq [simp]: "f ` (f -` A) = A \<inter> range f" 1717 by blast 1718 1719lemma image_subset_iff_subset_vimage: "f ` A \<subseteq> B \<longleftrightarrow> A \<subseteq> f -` B" 1720 by blast 1721 1722lemma vimage_const [simp]: "((\<lambda>x. c) -` A) = (if c \<in> A then UNIV else {})" 1723 by auto 1724 1725lemma vimage_if [simp]: "((\<lambda>x. if x \<in> B then c else d) -` A) = 1726 (if c \<in> A then (if d \<in> A then UNIV else B) 1727 else if d \<in> A then - B else {})" 1728 by (auto simp add: vimage_def) 1729 1730lemma vimage_inter_cong: "(\<And> w. w \<in> S \<Longrightarrow> f w = g w) \<Longrightarrow> f -` y \<inter> S = g -` y \<inter> S" 1731 by auto 1732 1733lemma vimage_ident [simp]: "(\<lambda>x. x) -` Y = Y" 1734 by blast 1735 1736 1737subsubsection \<open>Singleton sets\<close> 1738 1739definition is_singleton :: "'a set \<Rightarrow> bool" 1740 where "is_singleton A \<longleftrightarrow> (\<exists>x. A = {x})" 1741 1742lemma is_singletonI [simp, intro!]: "is_singleton {x}" 1743 unfolding is_singleton_def by simp 1744 1745lemma is_singletonI': "A \<noteq> {} \<Longrightarrow> (\<And>x y. x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow> x = y) \<Longrightarrow> is_singleton A" 1746 unfolding is_singleton_def by blast 1747 1748lemma is_singletonE: "is_singleton A \<Longrightarrow> (\<And>x. A = {x} \<Longrightarrow> P) \<Longrightarrow> P" 1749 unfolding is_singleton_def by blast 1750 1751 1752subsubsection \<open>Getting the contents of a singleton set\<close> 1753 1754definition the_elem :: "'a set \<Rightarrow> 'a" 1755 where "the_elem X = (THE x. X = {x})" 1756 1757lemma the_elem_eq [simp]: "the_elem {x} = x" 1758 by (simp add: the_elem_def) 1759 1760lemma is_singleton_the_elem: "is_singleton A \<longleftrightarrow> A = {the_elem A}" 1761 by (auto simp: is_singleton_def) 1762 1763lemma the_elem_image_unique: 1764 assumes "A \<noteq> {}" 1765 and *: "\<And>y. y \<in> A \<Longrightarrow> f y = f x" 1766 shows "the_elem (f ` A) = f x" 1767 unfolding the_elem_def 1768proof (rule the1_equality) 1769 from \<open>A \<noteq> {}\<close> obtain y where "y \<in> A" by auto 1770 with * have "f x = f y" by simp 1771 with \<open>y \<in> A\<close> have "f x \<in> f ` A" by blast 1772 with * show "f ` A = {f x}" by auto 1773 then show "\<exists>!x. f ` A = {x}" by auto 1774qed 1775 1776 1777subsubsection \<open>Least value operator\<close> 1778 1779lemma Least_mono: "mono f \<Longrightarrow> \<exists>x\<in>S. \<forall>y\<in>S. x \<le> y \<Longrightarrow> (LEAST y. y \<in> f ` S) = f (LEAST x. x \<in> S)" 1780 for f :: "'a::order \<Rightarrow> 'b::order" 1781 \<comment> \<open>Courtesy of Stephan Merz\<close> 1782 apply clarify 1783 apply (erule_tac P = "\<lambda>x. x \<in> S" in LeastI2_order) 1784 apply fast 1785 apply (rule LeastI2_order) 1786 apply (auto elim: monoD intro!: order_antisym) 1787 done 1788 1789 1790subsubsection \<open>Monad operation\<close> 1791 1792definition bind :: "'a set \<Rightarrow> ('a \<Rightarrow> 'b set) \<Rightarrow> 'b set" 1793 where "bind A f = {x. \<exists>B \<in> f`A. x \<in> B}" 1794 1795hide_const (open) bind 1796 1797lemma bind_bind: "Set.bind (Set.bind A B) C = Set.bind A (\<lambda>x. Set.bind (B x) C)" 1798 for A :: "'a set" 1799 by (auto simp: bind_def) 1800 1801lemma empty_bind [simp]: "Set.bind {} f = {}" 1802 by (simp add: bind_def) 1803 1804lemma nonempty_bind_const: "A \<noteq> {} \<Longrightarrow> Set.bind A (\<lambda>_. B) = B" 1805 by (auto simp: bind_def) 1806 1807lemma bind_const: "Set.bind A (\<lambda>_. B) = (if A = {} then {} else B)" 1808 by (auto simp: bind_def) 1809 1810lemma bind_singleton_conv_image: "Set.bind A (\<lambda>x. {f x}) = f ` A" 1811 by (auto simp: bind_def) 1812 1813 1814subsubsection \<open>Operations for execution\<close> 1815 1816definition is_empty :: "'a set \<Rightarrow> bool" 1817 where [code_abbrev]: "is_empty A \<longleftrightarrow> A = {}" 1818 1819hide_const (open) is_empty 1820 1821definition remove :: "'a \<Rightarrow> 'a set \<Rightarrow> 'a set" 1822 where [code_abbrev]: "remove x A = A - {x}" 1823 1824hide_const (open) remove 1825 1826lemma member_remove [simp]: "x \<in> Set.remove y A \<longleftrightarrow> x \<in> A \<and> x \<noteq> y" 1827 by (simp add: remove_def) 1828 1829definition filter :: "('a \<Rightarrow> bool) \<Rightarrow> 'a set \<Rightarrow> 'a set" 1830 where [code_abbrev]: "filter P A = {a \<in> A. P a}" 1831 1832hide_const (open) filter 1833 1834lemma member_filter [simp]: "x \<in> Set.filter P A \<longleftrightarrow> x \<in> A \<and> P x" 1835 by (simp add: filter_def) 1836 1837instantiation set :: (equal) equal 1838begin 1839 1840definition "HOL.equal A B \<longleftrightarrow> A \<subseteq> B \<and> B \<subseteq> A" 1841 1842instance by standard (auto simp add: equal_set_def) 1843 1844end 1845 1846 1847text \<open>Misc\<close> 1848 1849definition pairwise :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a set \<Rightarrow> bool" 1850 where "pairwise R S \<longleftrightarrow> (\<forall>x \<in> S. \<forall>y \<in> S. x \<noteq> y \<longrightarrow> R x y)" 1851 1852lemma pairwiseI [intro?]: 1853 "pairwise R S" if "\<And>x y. x \<in> S \<Longrightarrow> y \<in> S \<Longrightarrow> x \<noteq> y \<Longrightarrow> R x y" 1854 using that by (simp add: pairwise_def) 1855 1856lemma pairwiseD: 1857 "R x y" and "R y x" 1858 if "pairwise R S" "x \<in> S" and "y \<in> S" and "x \<noteq> y" 1859 using that by (simp_all add: pairwise_def) 1860 1861lemma pairwise_empty [simp]: "pairwise P {}" 1862 by (simp add: pairwise_def) 1863 1864lemma pairwise_singleton [simp]: "pairwise P {A}" 1865 by (simp add: pairwise_def) 1866 1867lemma pairwise_insert: 1868 "pairwise r (insert x s) \<longleftrightarrow> (\<forall>y. y \<in> s \<and> y \<noteq> x \<longrightarrow> r x y \<and> r y x) \<and> pairwise r s" 1869 by (force simp: pairwise_def) 1870 1871lemma pairwise_subset: "pairwise P S \<Longrightarrow> T \<subseteq> S \<Longrightarrow> pairwise P T" 1872 by (force simp: pairwise_def) 1873 1874lemma pairwise_mono: "\<lbrakk>pairwise P A; \<And>x y. P x y \<Longrightarrow> Q x y; B \<subseteq> A\<rbrakk> \<Longrightarrow> pairwise Q B" 1875 by (fastforce simp: pairwise_def) 1876 1877lemma pairwise_imageI: 1878 "pairwise P (f ` A)" 1879 if "\<And>x y. x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow> x \<noteq> y \<Longrightarrow> f x \<noteq> f y \<Longrightarrow> P (f x) (f y)" 1880 using that by (auto intro: pairwiseI) 1881 1882lemma pairwise_image: "pairwise r (f ` s) \<longleftrightarrow> pairwise (\<lambda>x y. (f x \<noteq> f y) \<longrightarrow> r (f x) (f y)) s" 1883 by (force simp: pairwise_def) 1884 1885definition disjnt :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" 1886 where "disjnt A B \<longleftrightarrow> A \<inter> B = {}" 1887 1888lemma disjnt_self_iff_empty [simp]: "disjnt S S \<longleftrightarrow> S = {}" 1889 by (auto simp: disjnt_def) 1890 1891lemma disjnt_iff: "disjnt A B \<longleftrightarrow> (\<forall>x. \<not> (x \<in> A \<and> x \<in> B))" 1892 by (force simp: disjnt_def) 1893 1894lemma disjnt_sym: "disjnt A B \<Longrightarrow> disjnt B A" 1895 using disjnt_iff by blast 1896 1897lemma disjnt_empty1 [simp]: "disjnt {} A" and disjnt_empty2 [simp]: "disjnt A {}" 1898 by (auto simp: disjnt_def) 1899 1900lemma disjnt_insert1 [simp]: "disjnt (insert a X) Y \<longleftrightarrow> a \<notin> Y \<and> disjnt X Y" 1901 by (simp add: disjnt_def) 1902 1903lemma disjnt_insert2 [simp]: "disjnt Y (insert a X) \<longleftrightarrow> a \<notin> Y \<and> disjnt Y X" 1904 by (simp add: disjnt_def) 1905 1906lemma disjnt_subset1 : "\<lbrakk>disjnt X Y; Z \<subseteq> X\<rbrakk> \<Longrightarrow> disjnt Z Y" 1907 by (auto simp: disjnt_def) 1908 1909lemma disjnt_subset2 : "\<lbrakk>disjnt X Y; Z \<subseteq> Y\<rbrakk> \<Longrightarrow> disjnt X Z" 1910 by (auto simp: disjnt_def) 1911 1912lemma disjoint_image_subset: "\<lbrakk>pairwise disjnt \<A>; \<And>X. X \<in> \<A> \<Longrightarrow> f X \<subseteq> X\<rbrakk> \<Longrightarrow> pairwise disjnt (f `\<A>)" 1913 unfolding disjnt_def pairwise_def by fast 1914 1915lemma Int_emptyI: "(\<And>x. x \<in> A \<Longrightarrow> x \<in> B \<Longrightarrow> False) \<Longrightarrow> A \<inter> B = {}" 1916 by blast 1917 1918lemma in_image_insert_iff: 1919 assumes "\<And>C. C \<in> B \<Longrightarrow> x \<notin> C" 1920 shows "A \<in> insert x ` B \<longleftrightarrow> x \<in> A \<and> A - {x} \<in> B" (is "?P \<longleftrightarrow> ?Q") 1921proof 1922 assume ?P then show ?Q 1923 using assms by auto 1924next 1925 assume ?Q 1926 then have "x \<in> A" and "A - {x} \<in> B" 1927 by simp_all 1928 from \<open>A - {x} \<in> B\<close> have "insert x (A - {x}) \<in> insert x ` B" 1929 by (rule imageI) 1930 also from \<open>x \<in> A\<close> 1931 have "insert x (A - {x}) = A" 1932 by auto 1933 finally show ?P . 1934qed 1935 1936hide_const (open) member not_member 1937 1938lemmas equalityI = subset_antisym 1939 1940ML \<open> 1941val Ball_def = @{thm Ball_def} 1942val Bex_def = @{thm Bex_def} 1943val CollectD = @{thm CollectD} 1944val CollectE = @{thm CollectE} 1945val CollectI = @{thm CollectI} 1946val Collect_conj_eq = @{thm Collect_conj_eq} 1947val Collect_mem_eq = @{thm Collect_mem_eq} 1948val IntD1 = @{thm IntD1} 1949val IntD2 = @{thm IntD2} 1950val IntE = @{thm IntE} 1951val IntI = @{thm IntI} 1952val Int_Collect = @{thm Int_Collect} 1953val UNIV_I = @{thm UNIV_I} 1954val UNIV_witness = @{thm UNIV_witness} 1955val UnE = @{thm UnE} 1956val UnI1 = @{thm UnI1} 1957val UnI2 = @{thm UnI2} 1958val ballE = @{thm ballE} 1959val ballI = @{thm ballI} 1960val bexCI = @{thm bexCI} 1961val bexE = @{thm bexE} 1962val bexI = @{thm bexI} 1963val bex_triv = @{thm bex_triv} 1964val bspec = @{thm bspec} 1965val contra_subsetD = @{thm contra_subsetD} 1966val equalityCE = @{thm equalityCE} 1967val equalityD1 = @{thm equalityD1} 1968val equalityD2 = @{thm equalityD2} 1969val equalityE = @{thm equalityE} 1970val equalityI = @{thm equalityI} 1971val imageE = @{thm imageE} 1972val imageI = @{thm imageI} 1973val image_Un = @{thm image_Un} 1974val image_insert = @{thm image_insert} 1975val insert_commute = @{thm insert_commute} 1976val insert_iff = @{thm insert_iff} 1977val mem_Collect_eq = @{thm mem_Collect_eq} 1978val rangeE = @{thm rangeE} 1979val rangeI = @{thm rangeI} 1980val range_eqI = @{thm range_eqI} 1981val subsetCE = @{thm subsetCE} 1982val subsetD = @{thm subsetD} 1983val subsetI = @{thm subsetI} 1984val subset_refl = @{thm subset_refl} 1985val subset_trans = @{thm subset_trans} 1986val vimageD = @{thm vimageD} 1987val vimageE = @{thm vimageE} 1988val vimageI = @{thm vimageI} 1989val vimageI2 = @{thm vimageI2} 1990val vimage_Collect = @{thm vimage_Collect} 1991val vimage_Int = @{thm vimage_Int} 1992val vimage_Un = @{thm vimage_Un} 1993\<close> 1994 1995end 1996