src/HOL/Set.thy
changeset 12897 f4d10ad0ea7b
parent 12633 ad9277743664
child 12937 0c4fd7529467
     1.1 --- a/src/HOL/Set.thy	Fri Feb 15 20:43:44 2002 +0100
     1.2 +++ b/src/HOL/Set.thy	Sat Feb 16 20:59:34 2002 +0100
     1.3 @@ -6,8 +6,7 @@
     1.4  
     1.5  header {* Set theory for higher-order logic *}
     1.6  
     1.7 -theory Set = HOL
     1.8 -files ("subset.ML") ("equalities.ML") ("mono.ML"):
     1.9 +theory Set = HOL:
    1.10  
    1.11  text {* A set in HOL is simply a predicate. *}
    1.12  
    1.13 @@ -339,7 +338,7 @@
    1.14  
    1.15  subsubsection {* Subsets *}
    1.16  
    1.17 -lemma subsetI [intro!]: "(!!x. x:A ==> x:B) ==> A <= B"
    1.18 +lemma subsetI [intro!]: "(!!x. x:A ==> x:B) ==> A \<subseteq> B"
    1.19    by (simp add: subset_def)
    1.20  
    1.21  text {*
    1.22 @@ -364,13 +363,13 @@
    1.23    Blast.overloaded (\"image\", domain_type);
    1.24  "
    1.25  
    1.26 -lemma subsetD [elim]: "A <= B ==> c:A ==> c:B"
    1.27 +lemma subsetD [elim]: "A \<subseteq> B ==> c \<in> A ==> c \<in> B"
    1.28    -- {* Rule in Modus Ponens style. *}
    1.29    by (unfold subset_def) blast
    1.30  
    1.31  declare subsetD [intro?] -- FIXME
    1.32  
    1.33 -lemma rev_subsetD: "c:A ==> A <= B ==> c:B"
    1.34 +lemma rev_subsetD: "c \<in> A ==> A \<subseteq> B ==> c \<in> B"
    1.35    -- {* The same, with reversed premises for use with @{text erule} --
    1.36        cf @{text rev_mp}. *}
    1.37    by (rule subsetD)
    1.38 @@ -378,7 +377,7 @@
    1.39  declare rev_subsetD [intro?] -- FIXME
    1.40  
    1.41  text {*
    1.42 -  \medskip Converts @{prop "A <= B"} to @{prop "x:A ==> x:B"}.
    1.43 +  \medskip Converts @{prop "A \<subseteq> B"} to @{prop "x \<in> A ==> x \<in> B"}.
    1.44  *}
    1.45  
    1.46  ML {*
    1.47 @@ -386,13 +385,13 @@
    1.48    in fun impOfSubs th = th RSN (2, rev_subsetD) end;
    1.49  *}
    1.50  
    1.51 -lemma subsetCE [elim]: "A <= B ==> (c~:A ==> P) ==> (c:B ==> P) ==> P"
    1.52 +lemma subsetCE [elim]: "A \<subseteq>  B ==> (c \<notin> A ==> P) ==> (c \<in> B ==> P) ==> P"
    1.53    -- {* Classical elimination rule. *}
    1.54    by (unfold subset_def) blast
    1.55  
    1.56  text {*
    1.57 -  \medskip Takes assumptions @{prop "A <= B"}; @{prop "c:A"} and
    1.58 -  creates the assumption @{prop "c:B"}.
    1.59 +  \medskip Takes assumptions @{prop "A \<subseteq> B"}; @{prop "c \<in> A"} and
    1.60 +  creates the assumption @{prop "c \<in> B"}.
    1.61  *}
    1.62  
    1.63  ML {*
    1.64 @@ -400,46 +399,46 @@
    1.65    in fun set_mp_tac i = etac subsetCE i THEN mp_tac i end;
    1.66  *}
    1.67  
    1.68 -lemma contra_subsetD: "A <= B ==> c ~: B ==> c ~: A"
    1.69 +lemma contra_subsetD: "A \<subseteq> B ==> c \<notin> B ==> c \<notin> A"
    1.70    by blast
    1.71  
    1.72 -lemma subset_refl: "A <= (A::'a set)"
    1.73 +lemma subset_refl: "A \<subseteq> A"
    1.74    by fast
    1.75  
    1.76 -lemma subset_trans: "A <= B ==> B <= C ==> A <= (C::'a set)"
    1.77 +lemma subset_trans: "A \<subseteq> B ==> B \<subseteq> C ==> A \<subseteq> C"
    1.78    by blast
    1.79  
    1.80  
    1.81  subsubsection {* Equality *}
    1.82  
    1.83 -lemma subset_antisym [intro!]: "A <= B ==> B <= A ==> A = (B::'a set)"
    1.84 +lemma subset_antisym [intro!]: "A \<subseteq> B ==> B \<subseteq> A ==> A = B"
    1.85    -- {* Anti-symmetry of the subset relation. *}
    1.86 -  by (rule set_ext) (blast intro: subsetD)
    1.87 -
    1.88 -lemmas equalityI = subset_antisym
    1.89 +  by (rules intro: set_ext subsetD)
    1.90 +
    1.91 +lemmas equalityI [intro!] = subset_antisym
    1.92  
    1.93  text {*
    1.94    \medskip Equality rules from ZF set theory -- are they appropriate
    1.95    here?
    1.96  *}
    1.97  
    1.98 -lemma equalityD1: "A = B ==> A <= (B::'a set)"
    1.99 +lemma equalityD1: "A = B ==> A \<subseteq> B"
   1.100    by (simp add: subset_refl)
   1.101  
   1.102 -lemma equalityD2: "A = B ==> B <= (A::'a set)"
   1.103 +lemma equalityD2: "A = B ==> B \<subseteq> A"
   1.104    by (simp add: subset_refl)
   1.105  
   1.106  text {*
   1.107    \medskip Be careful when adding this to the claset as @{text
   1.108    subset_empty} is in the simpset: @{prop "A = {}"} goes to @{prop "{}
   1.109 -  <= A"} and @{prop "A <= {}"} and then back to @{prop "A = {}"}!
   1.110 +  \<subseteq> A"} and @{prop "A \<subseteq> {}"} and then back to @{prop "A = {}"}!
   1.111  *}
   1.112  
   1.113 -lemma equalityE: "A = B ==> (A <= B ==> B <= (A::'a set) ==> P) ==> P"
   1.114 +lemma equalityE: "A = B ==> (A \<subseteq> B ==> B \<subseteq> A ==> P) ==> P"
   1.115    by (simp add: subset_refl)
   1.116  
   1.117  lemma equalityCE [elim]:
   1.118 -    "A = B ==> (c:A ==> c:B ==> P) ==> (c~:A ==> c~:B ==> P) ==> P"
   1.119 +    "A = B ==> (c \<in> A ==> c \<in> B ==> P) ==> (c \<notin> A ==> c \<notin> B ==> P) ==> P"
   1.120    by blast
   1.121  
   1.122  text {*
   1.123 @@ -466,7 +465,7 @@
   1.124  lemma UNIV_witness [intro?]: "EX x. x : UNIV"
   1.125    by simp
   1.126  
   1.127 -lemma subset_UNIV: "A <= UNIV"
   1.128 +lemma subset_UNIV: "A \<subseteq> UNIV"
   1.129    by (rule subsetI) (rule UNIV_I)
   1.130  
   1.131  text {*
   1.132 @@ -490,14 +489,14 @@
   1.133  lemma emptyE [elim!]: "a : {} ==> P"
   1.134    by simp
   1.135  
   1.136 -lemma empty_subsetI [iff]: "{} <= A"
   1.137 +lemma empty_subsetI [iff]: "{} \<subseteq> A"
   1.138      -- {* One effect is to delete the ASSUMPTION @{prop "{} <= A"} *}
   1.139    by blast
   1.140  
   1.141 -lemma equals0I: "(!!y. y:A ==> False) ==> A = {}"
   1.142 +lemma equals0I: "(!!y. y \<in> A ==> False) ==> A = {}"
   1.143    by blast
   1.144  
   1.145 -lemma equals0D: "A={} ==> a ~: A"
   1.146 +lemma equals0D: "A = {} ==> a \<notin> A"
   1.147      -- {* Use for reasoning about disjointness: @{prop "A Int B = {}"} *}
   1.148    by blast
   1.149  
   1.150 @@ -513,28 +512,28 @@
   1.151  
   1.152  subsubsection {* The Powerset operator -- Pow *}
   1.153  
   1.154 -lemma Pow_iff [iff]: "(A : Pow B) = (A <= B)"
   1.155 +lemma Pow_iff [iff]: "(A \<in> Pow B) = (A \<subseteq> B)"
   1.156    by (simp add: Pow_def)
   1.157  
   1.158 -lemma PowI: "A <= B ==> A : Pow B"
   1.159 +lemma PowI: "A \<subseteq> B ==> A \<in> Pow B"
   1.160    by (simp add: Pow_def)
   1.161  
   1.162 -lemma PowD: "A : Pow B ==> A <= B"
   1.163 +lemma PowD: "A \<in> Pow B ==> A \<subseteq> B"
   1.164    by (simp add: Pow_def)
   1.165  
   1.166 -lemma Pow_bottom: "{}: Pow B"
   1.167 +lemma Pow_bottom: "{} \<in> Pow B"
   1.168    by simp
   1.169  
   1.170 -lemma Pow_top: "A : Pow A"
   1.171 +lemma Pow_top: "A \<in> Pow A"
   1.172    by (simp add: subset_refl)
   1.173  
   1.174  
   1.175  subsubsection {* Set complement *}
   1.176  
   1.177 -lemma Compl_iff [simp]: "(c : -A) = (c~:A)"
   1.178 +lemma Compl_iff [simp]: "(c \<in> -A) = (c \<notin> A)"
   1.179    by (unfold Compl_def) blast
   1.180  
   1.181 -lemma ComplI [intro!]: "(c:A ==> False) ==> c : -A"
   1.182 +lemma ComplI [intro!]: "(c \<in> A ==> False) ==> c \<in> -A"
   1.183    by (unfold Compl_def) blast
   1.184  
   1.185  text {*
   1.186 @@ -625,7 +624,7 @@
   1.187    -- {* Classical introduction rule. *}
   1.188    by auto
   1.189  
   1.190 -lemma subset_insert_iff: "(A <= insert x B) = (if x:A then A - {x} <= B else A <= B)"
   1.191 +lemma subset_insert_iff: "(A \<subseteq> insert x B) = (if x:A then A - {x} \<subseteq> B else A \<subseteq> B)"
   1.192    by auto
   1.193  
   1.194  
   1.195 @@ -646,13 +645,13 @@
   1.196  lemma singleton_inject [dest!]: "{a} = {b} ==> a = b"
   1.197    by blast
   1.198  
   1.199 -lemma singleton_insert_inj_eq [iff]: "({b} = insert a A) = (a = b & A <= {b})"
   1.200 +lemma singleton_insert_inj_eq [iff]: "({b} = insert a A) = (a = b & A \<subseteq> {b})"
   1.201    by blast
   1.202  
   1.203 -lemma singleton_insert_inj_eq' [iff]: "(insert a A = {b}) = (a = b & A <= {b})"
   1.204 +lemma singleton_insert_inj_eq' [iff]: "(insert a A = {b}) = (a = b & A \<subseteq> {b})"
   1.205    by blast
   1.206  
   1.207 -lemma subset_singletonD: "A <= {x} ==> A={} | A = {x}"
   1.208 +lemma subset_singletonD: "A \<subseteq> {x} ==> A = {} | A = {x}"
   1.209    by fast
   1.210  
   1.211  lemma singleton_conv [simp]: "{x. x = a} = {a}"
   1.212 @@ -661,7 +660,7 @@
   1.213  lemma singleton_conv2 [simp]: "{x. a = x} = {a}"
   1.214    by blast
   1.215  
   1.216 -lemma diff_single_insert: "A - {x} <= B ==> x : A ==> A <= insert x B"
   1.217 +lemma diff_single_insert: "A - {x} \<subseteq> B ==> x \<in> A ==> A \<subseteq> insert x B"
   1.218    by blast
   1.219  
   1.220  
   1.221 @@ -772,18 +771,18 @@
   1.222  lemma image_iff: "(z : f`A) = (EX x:A. z = f x)"
   1.223    by blast
   1.224  
   1.225 -lemma image_subset_iff: "(f`A <= B) = (ALL x:A. f x: B)"
   1.226 +lemma image_subset_iff: "(f`A \<subseteq> B) = (\<forall>x\<in>A. f x \<in> B)"
   1.227    -- {* This rewrite rule would confuse users if made default. *}
   1.228    by blast
   1.229  
   1.230 -lemma subset_image_iff: "(B <= f ` A) = (EX AA. AA <= A & B = f ` AA)"
   1.231 +lemma subset_image_iff: "(B \<subseteq> f`A) = (EX AA. AA \<subseteq> A & B = f`AA)"
   1.232    apply safe
   1.233     prefer 2 apply fast
   1.234    apply (rule_tac x = "{a. a : A & f a : B}" in exI)
   1.235    apply fast
   1.236    done
   1.237  
   1.238 -lemma image_subsetI: "(!!x. x:A ==> f x : B) ==> f`A <= B"
   1.239 +lemma image_subsetI: "(!!x. x \<in> A ==> f x \<in> B) ==> f`A \<subseteq> B"
   1.240    -- {* Replaces the three steps @{text subsetI}, @{text imageE},
   1.241      @{text hypsubst}, but breaks too many existing proofs. *}
   1.242    by blast
   1.243 @@ -792,13 +791,13 @@
   1.244    \medskip Range of a function -- just a translation for image!
   1.245  *}
   1.246  
   1.247 -lemma range_eqI: "b = f x ==> b : range f"
   1.248 +lemma range_eqI: "b = f x ==> b \<in> range f"
   1.249    by simp
   1.250  
   1.251 -lemma rangeI: "f x : range f"
   1.252 +lemma rangeI: "f x \<in> range f"
   1.253    by simp
   1.254  
   1.255 -lemma rangeE [elim?]: "b : range (%x. f x) ==> (!!x. b = f x ==> P) ==> P"
   1.256 +lemma rangeE [elim?]: "b \<in> range (\<lambda>x. f x) ==> (!!x. b = f x ==> P) ==> P"
   1.257    by blast
   1.258  
   1.259  
   1.260 @@ -852,32 +851,30 @@
   1.261  
   1.262  subsubsection {* The ``proper subset'' relation *}
   1.263  
   1.264 -lemma psubsetI [intro!]: "(A::'a set) <= B ==> A ~= B ==> A < B"
   1.265 +lemma psubsetI [intro!]: "A \<subseteq> B ==> A \<noteq> B ==> A \<subset> B"
   1.266    by (unfold psubset_def) blast
   1.267  
   1.268  lemma psubset_insert_iff:
   1.269 -  "(A < insert x B) = (if x:B then A < B else if x:A then A - {x} < B else A <= B)"
   1.270 -  apply (simp add: psubset_def subset_insert_iff)
   1.271 -  apply blast
   1.272 -  done
   1.273 -
   1.274 -lemma psubset_eq: "((A::'a set) < B) = (A <= B & A ~= B)"
   1.275 +  "(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)"
   1.276 +  by (auto simp add: psubset_def subset_insert_iff)
   1.277 +
   1.278 +lemma psubset_eq: "(A \<subset> B) = (A \<subseteq> B & A \<noteq> B)"
   1.279    by (simp only: psubset_def)
   1.280  
   1.281 -lemma psubset_imp_subset: "(A::'a set) < B ==> A <= B"
   1.282 +lemma psubset_imp_subset: "A \<subset> B ==> A \<subseteq> B"
   1.283    by (simp add: psubset_eq)
   1.284  
   1.285 -lemma psubset_subset_trans: "(A::'a set) < B ==> B <= C ==> A < C"
   1.286 +lemma psubset_subset_trans: "A \<subset> B ==> B \<subseteq> C ==> A \<subset> C"
   1.287    by (auto simp add: psubset_eq)
   1.288  
   1.289 -lemma subset_psubset_trans: "(A::'a set) <= B ==> B < C ==> A < C"
   1.290 +lemma subset_psubset_trans: "A \<subseteq> B ==> B \<subset> C ==> A \<subset> C"
   1.291    by (auto simp add: psubset_eq)
   1.292  
   1.293 -lemma psubset_imp_ex_mem: "A < B ==> EX b. b : (B - A)"
   1.294 +lemma psubset_imp_ex_mem: "A \<subset> B ==> \<exists>b. b \<in> (B - A)"
   1.295    by (unfold psubset_def) blast
   1.296  
   1.297  lemma atomize_ball:
   1.298 -    "(!!x. x:A ==> P x) == Trueprop (ALL x:A. P x)"
   1.299 +    "(!!x. x \<in> A ==> P x) == Trueprop (\<forall>x\<in>A. P x)"
   1.300    by (simp only: Ball_def atomize_all atomize_imp)
   1.301  
   1.302  declare atomize_ball [symmetric, rulify]
   1.303 @@ -885,9 +882,898 @@
   1.304  
   1.305  subsection {* Further set-theory lemmas *}
   1.306  
   1.307 -use "subset.ML"
   1.308 -use "equalities.ML"
   1.309 -use "mono.ML"
   1.310 +subsubsection {* Derived rules involving subsets. *}
   1.311 +
   1.312 +text {* @{text insert}. *}
   1.313 +
   1.314 +lemma subset_insertI: "B \<subseteq> insert a B"
   1.315 +  apply (rule subsetI)
   1.316 +  apply (erule insertI2)
   1.317 +  done
   1.318 +
   1.319 +lemma subset_insert: "x \<notin> A ==> (A \<subseteq> insert x B) = (A \<subseteq> B)"
   1.320 +  by blast
   1.321 +
   1.322 +
   1.323 +text {* \medskip Big Union -- least upper bound of a set. *}
   1.324 +
   1.325 +lemma Union_upper: "B \<in> A ==> B \<subseteq> Union A"
   1.326 +  by (rules intro: subsetI UnionI)
   1.327 +
   1.328 +lemma Union_least: "(!!X. X \<in> A ==> X \<subseteq> C) ==> Union A \<subseteq> C"
   1.329 +  by (rules intro: subsetI elim: UnionE dest: subsetD)
   1.330 +
   1.331 +
   1.332 +text {* \medskip General union. *}
   1.333 +
   1.334 +lemma UN_upper: "a \<in> A ==> B a \<subseteq> (\<Union>x\<in>A. B x)"
   1.335 +  by blast
   1.336 +
   1.337 +lemma UN_least: "(!!x. x \<in> A ==> B x \<subseteq> C) ==> (\<Union>x\<in>A. B x) \<subseteq> C"
   1.338 +  by (rules intro: subsetI elim: UN_E dest: subsetD)
   1.339 +
   1.340 +
   1.341 +text {* \medskip Big Intersection -- greatest lower bound of a set. *}
   1.342 +
   1.343 +lemma Inter_lower: "B \<in> A ==> Inter A \<subseteq> B"
   1.344 +  by blast
   1.345 +
   1.346 +lemma Inter_greatest: "(!!X. X \<in> A ==> C \<subseteq> X) ==> C \<subseteq> Inter A"
   1.347 +  by (rules intro: InterI subsetI dest: subsetD)
   1.348 +
   1.349 +lemma INT_lower: "a \<in> A ==> (\<Inter>x\<in>A. B x) \<subseteq> B a"
   1.350 +  by blast
   1.351 +
   1.352 +lemma INT_greatest: "(!!x. x \<in> A ==> C \<subseteq> B x) ==> C \<subseteq> (\<Inter>x\<in>A. B x)"
   1.353 +  by (rules intro: INT_I subsetI dest: subsetD)
   1.354 +
   1.355 +
   1.356 +text {* \medskip Finite Union -- the least upper bound of two sets. *}
   1.357 +
   1.358 +lemma Un_upper1: "A \<subseteq> A \<union> B"
   1.359 +  by blast
   1.360 +
   1.361 +lemma Un_upper2: "B \<subseteq> A \<union> B"
   1.362 +  by blast
   1.363 +
   1.364 +lemma Un_least: "A \<subseteq> C ==> B \<subseteq> C ==> A \<union> B \<subseteq> C"
   1.365 +  by blast
   1.366 +
   1.367 +
   1.368 +text {* \medskip Finite Intersection -- the greatest lower bound of two sets. *}
   1.369 +
   1.370 +lemma Int_lower1: "A \<inter> B \<subseteq> A"
   1.371 +  by blast
   1.372 +
   1.373 +lemma Int_lower2: "A \<inter> B \<subseteq> B"
   1.374 +  by blast
   1.375 +
   1.376 +lemma Int_greatest: "C \<subseteq> A ==> C \<subseteq> B ==> C \<subseteq> A \<inter> B"
   1.377 +  by blast
   1.378 +
   1.379 +
   1.380 +text {* \medskip Set difference. *}
   1.381 +
   1.382 +lemma Diff_subset: "A - B \<subseteq> A"
   1.383 +  by blast
   1.384 +
   1.385 +
   1.386 +text {* \medskip Monotonicity. *}
   1.387 +
   1.388 +lemma mono_Un: "mono f ==> f A \<union> f B \<subseteq> f (A \<union> B)"
   1.389 +  apply (rule Un_least)
   1.390 +   apply (erule Un_upper1 [THEN [2] monoD])
   1.391 +  apply (erule Un_upper2 [THEN [2] monoD])
   1.392 +  done
   1.393 +
   1.394 +lemma mono_Int: "mono f ==> f (A \<inter> B) \<subseteq> f A \<inter> f B"
   1.395 +  apply (rule Int_greatest)
   1.396 +   apply (erule Int_lower1 [THEN [2] monoD])
   1.397 +  apply (erule Int_lower2 [THEN [2] monoD])
   1.398 +  done
   1.399 +
   1.400 +
   1.401 +subsubsection {* Equalities involving union, intersection, inclusion, etc. *}
   1.402 +
   1.403 +text {* @{text "{}"}. *}
   1.404 +
   1.405 +lemma Collect_const [simp]: "{s. P} = (if P then UNIV else {})"
   1.406 +  -- {* supersedes @{text "Collect_False_empty"} *}
   1.407 +  by auto
   1.408 +
   1.409 +lemma subset_empty [simp]: "(A \<subseteq> {}) = (A = {})"
   1.410 +  by blast
   1.411 +
   1.412 +lemma not_psubset_empty [iff]: "\<not> (A < {})"
   1.413 +  by (unfold psubset_def) blast
   1.414 +
   1.415 +lemma Collect_empty_eq [simp]: "(Collect P = {}) = (\<forall>x. \<not> P x)"
   1.416 +  by auto
   1.417 +
   1.418 +lemma Collect_neg_eq: "{x. \<not> P x} = - {x. P x}"
   1.419 +  by blast
   1.420 +
   1.421 +lemma Collect_disj_eq: "{x. P x | Q x} = {x. P x} \<union> {x. Q x}"
   1.422 +  by blast
   1.423 +
   1.424 +lemma Collect_conj_eq: "{x. P x & Q x} = {x. P x} \<inter> {x. Q x}"
   1.425 +  by blast
   1.426 +
   1.427 +lemma Collect_all_eq: "{x. \<forall>y. P x y} = (\<Inter>y. {x. P x y})"
   1.428 +  by blast
   1.429 +
   1.430 +lemma Collect_ball_eq: "{x. \<forall>y\<in>A. P x y} = (\<Inter>y\<in>A. {x. P x y})"
   1.431 +  by blast
   1.432 +
   1.433 +lemma Collect_ex_eq: "{x. \<exists>y. P x y} = (\<Union>y. {x. P x y})"
   1.434 +  by blast
   1.435 +
   1.436 +lemma Collect_bex_eq: "{x. \<exists>y\<in>A. P x y} = (\<Union>y\<in>A. {x. P x y})"
   1.437 +  by blast
   1.438 +
   1.439 +
   1.440 +text {* \medskip @{text insert}. *}
   1.441 +
   1.442 +lemma insert_is_Un: "insert a A = {a} Un A"
   1.443 +  -- {* NOT SUITABLE FOR REWRITING since @{text "{a} == insert a {}"} *}
   1.444 +  by blast
   1.445 +
   1.446 +lemma insert_not_empty [simp]: "insert a A \<noteq> {}"
   1.447 +  by blast
   1.448 +
   1.449 +lemmas empty_not_insert [simp] = insert_not_empty [symmetric, standard]
   1.450 +
   1.451 +lemma insert_absorb: "a \<in> A ==> insert a A = A"
   1.452 +  -- {* @{text "[simp]"} causes recursive calls when there are nested inserts *}
   1.453 +  -- {* with \emph{quadratic} running time *}
   1.454 +  by blast
   1.455 +
   1.456 +lemma insert_absorb2 [simp]: "insert x (insert x A) = insert x A"
   1.457 +  by blast
   1.458 +
   1.459 +lemma insert_commute: "insert x (insert y A) = insert y (insert x A)"
   1.460 +  by blast
   1.461 +
   1.462 +lemma insert_subset [simp]: "(insert x A \<subseteq> B) = (x \<in> B & A \<subseteq> B)"
   1.463 +  by blast
   1.464 +
   1.465 +lemma mk_disjoint_insert: "a \<in> A ==> \<exists>B. A = insert a B & a \<notin> B"
   1.466 +  -- {* use new @{text B} rather than @{text "A - {a}"} to avoid infinite unfolding *}
   1.467 +  apply (rule_tac x = "A - {a}" in exI)
   1.468 +  apply blast
   1.469 +  done
   1.470 +
   1.471 +lemma insert_Collect: "insert a (Collect P) = {u. u \<noteq> a --> P u}"
   1.472 +  by auto
   1.473 +
   1.474 +lemma UN_insert_distrib: "u \<in> A ==> (\<Union>x\<in>A. insert a (B x)) = insert a (\<Union>x\<in>A. B x)"
   1.475 +  by blast
   1.476 +
   1.477 +
   1.478 +text {* \medskip @{text image}. *}
   1.479 +
   1.480 +lemma image_empty [simp]: "f`{} = {}"
   1.481 +  by blast
   1.482 +
   1.483 +lemma image_insert [simp]: "f ` insert a B = insert (f a) (f`B)"
   1.484 +  by blast
   1.485 +
   1.486 +lemma image_constant: "x \<in> A ==> (\<lambda>x. c) ` A = {c}"
   1.487 +  by blast
   1.488 +
   1.489 +lemma image_image: "f ` (g ` A) = (\<lambda>x. f (g x)) ` A"
   1.490 +  by blast
   1.491 +
   1.492 +lemma insert_image [simp]: "x \<in> A ==> insert (f x) (f`A) = f`A"
   1.493 +  by blast
   1.494 +
   1.495 +lemma image_is_empty [iff]: "(f`A = {}) = (A = {})"
   1.496 +  by blast
   1.497 +
   1.498 +lemma image_Collect: "f ` {x. P x} = {f x | x. P x}"
   1.499 +  -- {* NOT suitable as a default simprule: the RHS isn't simpler than the LHS, *}
   1.500 +  -- {* with its implicit quantifier and conjunction.  Also image enjoys better *}
   1.501 +  -- {* equational properties than does the RHS. *}
   1.502 +  by blast
   1.503 +
   1.504 +lemma if_image_distrib [simp]:
   1.505 +  "(\<lambda>x. if P x then f x else g x) ` S
   1.506 +    = (f ` (S \<inter> {x. P x})) \<union> (g ` (S \<inter> {x. \<not> P x}))"
   1.507 +  by (auto simp add: image_def)
   1.508 +
   1.509 +lemma image_cong: "M = N ==> (!!x. x \<in> N ==> f x = g x) ==> f`M = g`N"
   1.510 +  by (simp add: image_def)
   1.511 +
   1.512 +
   1.513 +text {* \medskip @{text range}. *}
   1.514 +
   1.515 +lemma full_SetCompr_eq: "{u. \<exists>x. u = f x} = range f"
   1.516 +  by auto
   1.517 +
   1.518 +lemma range_composition [simp]: "range (\<lambda>x. f (g x)) = f`range g"
   1.519 +  apply (subst image_image)
   1.520 +  apply simp
   1.521 +  done
   1.522 +
   1.523 +
   1.524 +text {* \medskip @{text Int} *}
   1.525 +
   1.526 +lemma Int_absorb [simp]: "A \<inter> A = A"
   1.527 +  by blast
   1.528 +
   1.529 +lemma Int_left_absorb: "A \<inter> (A \<inter> B) = A \<inter> B"
   1.530 +  by blast
   1.531 +
   1.532 +lemma Int_commute: "A \<inter> B = B \<inter> A"
   1.533 +  by blast
   1.534 +
   1.535 +lemma Int_left_commute: "A \<inter> (B \<inter> C) = B \<inter> (A \<inter> C)"
   1.536 +  by blast
   1.537 +
   1.538 +lemma Int_assoc: "(A \<inter> B) \<inter> C = A \<inter> (B \<inter> C)"
   1.539 +  by blast
   1.540 +
   1.541 +lemmas Int_ac = Int_assoc Int_left_absorb Int_commute Int_left_commute
   1.542 +  -- {* Intersection is an AC-operator *}
   1.543 +
   1.544 +lemma Int_absorb1: "B \<subseteq> A ==> A \<inter> B = B"
   1.545 +  by blast
   1.546 +
   1.547 +lemma Int_absorb2: "A \<subseteq> B ==> A \<inter> B = A"
   1.548 +  by blast
   1.549 +
   1.550 +lemma Int_empty_left [simp]: "{} \<inter> B = {}"
   1.551 +  by blast
   1.552 +
   1.553 +lemma Int_empty_right [simp]: "A \<inter> {} = {}"
   1.554 +  by blast
   1.555 +
   1.556 +lemma disjoint_eq_subset_Compl: "(A \<inter> B = {}) = (A \<subseteq> -B)"
   1.557 +  by blast
   1.558 +
   1.559 +lemma disjoint_iff_not_equal: "(A \<inter> B = {}) = (\<forall>x\<in>A. \<forall>y\<in>B. x \<noteq> y)"
   1.560 +  by blast
   1.561 +
   1.562 +lemma Int_UNIV_left [simp]: "UNIV \<inter> B = B"
   1.563 +  by blast
   1.564 +
   1.565 +lemma Int_UNIV_right [simp]: "A \<inter> UNIV = A"
   1.566 +  by blast
   1.567 +
   1.568 +lemma Int_eq_Inter: "A \<inter> B = \<Inter>{A, B}"
   1.569 +  by blast
   1.570 +
   1.571 +lemma Int_Un_distrib: "A \<inter> (B \<union> C) = (A \<inter> B) \<union> (A \<inter> C)"
   1.572 +  by blast
   1.573 +
   1.574 +lemma Int_Un_distrib2: "(B \<union> C) \<inter> A = (B \<inter> A) \<union> (C \<inter> A)"
   1.575 +  by blast
   1.576 +
   1.577 +lemma Int_UNIV [simp]: "(A \<inter> B = UNIV) = (A = UNIV & B = UNIV)"
   1.578 +  by blast
   1.579 +
   1.580 +lemma Int_subset_iff: "(C \<subseteq> A \<inter> B) = (C \<subseteq> A & C \<subseteq> B)"
   1.581 +  by blast
   1.582 +
   1.583 +lemma Int_Collect: "(x \<in> A \<inter> {x. P x}) = (x \<in> A & P x)"
   1.584 +  by blast
   1.585 +
   1.586 +
   1.587 +text {* \medskip @{text Un}. *}
   1.588 +
   1.589 +lemma Un_absorb [simp]: "A \<union> A = A"
   1.590 +  by blast
   1.591 +
   1.592 +lemma Un_left_absorb: "A \<union> (A \<union> B) = A \<union> B"
   1.593 +  by blast
   1.594 +
   1.595 +lemma Un_commute: "A \<union> B = B \<union> A"
   1.596 +  by blast
   1.597 +
   1.598 +lemma Un_left_commute: "A \<union> (B \<union> C) = B \<union> (A \<union> C)"
   1.599 +  by blast
   1.600 +
   1.601 +lemma Un_assoc: "(A \<union> B) \<union> C = A \<union> (B \<union> C)"
   1.602 +  by blast
   1.603 +
   1.604 +lemmas Un_ac = Un_assoc Un_left_absorb Un_commute Un_left_commute
   1.605 +  -- {* Union is an AC-operator *}
   1.606 +
   1.607 +lemma Un_absorb1: "A \<subseteq> B ==> A \<union> B = B"
   1.608 +  by blast
   1.609 +
   1.610 +lemma Un_absorb2: "B \<subseteq> A ==> A \<union> B = A"
   1.611 +  by blast
   1.612 +
   1.613 +lemma Un_empty_left [simp]: "{} \<union> B = B"
   1.614 +  by blast
   1.615 +
   1.616 +lemma Un_empty_right [simp]: "A \<union> {} = A"
   1.617 +  by blast
   1.618 +
   1.619 +lemma Un_UNIV_left [simp]: "UNIV \<union> B = UNIV"
   1.620 +  by blast
   1.621 +
   1.622 +lemma Un_UNIV_right [simp]: "A \<union> UNIV = UNIV"
   1.623 +  by blast
   1.624 +
   1.625 +lemma Un_eq_Union: "A \<union> B = \<Union>{A, B}"
   1.626 +  by blast
   1.627 +
   1.628 +lemma Un_insert_left [simp]: "(insert a B) \<union> C = insert a (B \<union> C)"
   1.629 +  by blast
   1.630 +
   1.631 +lemma Un_insert_right [simp]: "A \<union> (insert a B) = insert a (A \<union> B)"
   1.632 +  by blast
   1.633 +
   1.634 +lemma Int_insert_left:
   1.635 +    "(insert a B) Int C = (if a \<in> C then insert a (B \<inter> C) else B \<inter> C)"
   1.636 +  by auto
   1.637 +
   1.638 +lemma Int_insert_right:
   1.639 +    "A \<inter> (insert a B) = (if a \<in> A then insert a (A \<inter> B) else A \<inter> B)"
   1.640 +  by auto
   1.641 +
   1.642 +lemma Un_Int_distrib: "A \<union> (B \<inter> C) = (A \<union> B) \<inter> (A \<union> C)"
   1.643 +  by blast
   1.644 +
   1.645 +lemma Un_Int_distrib2: "(B \<inter> C) \<union> A = (B \<union> A) \<inter> (C \<union> A)"
   1.646 +  by blast
   1.647 +
   1.648 +lemma Un_Int_crazy:
   1.649 +    "(A \<inter> B) \<union> (B \<inter> C) \<union> (C \<inter> A) = (A \<union> B) \<inter> (B \<union> C) \<inter> (C \<union> A)"
   1.650 +  by blast
   1.651 +
   1.652 +lemma subset_Un_eq: "(A \<subseteq> B) = (A \<union> B = B)"
   1.653 +  by blast
   1.654 +
   1.655 +lemma Un_empty [iff]: "(A \<union> B = {}) = (A = {} & B = {})"
   1.656 +  by blast
   1.657 +
   1.658 +lemma Un_subset_iff: "(A \<union> B \<subseteq> C) = (A \<subseteq> C & B \<subseteq> C)"
   1.659 +  by blast
   1.660 +
   1.661 +lemma Un_Diff_Int: "(A - B) \<union> (A \<inter> B) = A"
   1.662 +  by blast
   1.663 +
   1.664 +
   1.665 +text {* \medskip Set complement *}
   1.666 +
   1.667 +lemma Compl_disjoint [simp]: "A \<inter> -A = {}"
   1.668 +  by blast
   1.669 +
   1.670 +lemma Compl_disjoint2 [simp]: "-A \<inter> A = {}"
   1.671 +  by blast
   1.672 +
   1.673 +lemma Compl_partition: "A \<union> (-A) = UNIV"
   1.674 +  by blast
   1.675 +
   1.676 +lemma double_complement [simp]: "- (-A) = (A::'a set)"
   1.677 +  by blast
   1.678 +
   1.679 +lemma Compl_Un [simp]: "-(A \<union> B) = (-A) \<inter> (-B)"
   1.680 +  by blast
   1.681 +
   1.682 +lemma Compl_Int [simp]: "-(A \<inter> B) = (-A) \<union> (-B)"
   1.683 +  by blast
   1.684 +
   1.685 +lemma Compl_UN [simp]: "-(\<Union>x\<in>A. B x) = (\<Inter>x\<in>A. -B x)"
   1.686 +  by blast
   1.687 +
   1.688 +lemma Compl_INT [simp]: "-(\<Inter>x\<in>A. B x) = (\<Union>x\<in>A. -B x)"
   1.689 +  by blast
   1.690 +
   1.691 +lemma subset_Compl_self_eq: "(A \<subseteq> -A) = (A = {})"
   1.692 +  by blast
   1.693 +
   1.694 +lemma Un_Int_assoc_eq: "((A \<inter> B) \<union> C = A \<inter> (B \<union> C)) = (C \<subseteq> A)"
   1.695 +  -- {* Halmos, Naive Set Theory, page 16. *}
   1.696 +  by blast
   1.697 +
   1.698 +lemma Compl_UNIV_eq [simp]: "-UNIV = {}"
   1.699 +  by blast
   1.700 +
   1.701 +lemma Compl_empty_eq [simp]: "-{} = UNIV"
   1.702 +  by blast
   1.703 +
   1.704 +lemma Compl_subset_Compl_iff [iff]: "(-A \<subseteq> -B) = (B \<subseteq> A)"
   1.705 +  by blast
   1.706 +
   1.707 +lemma Compl_eq_Compl_iff [iff]: "(-A = -B) = (A = (B::'a set))"
   1.708 +  by blast
   1.709 +
   1.710 +
   1.711 +text {* \medskip @{text Union}. *}
   1.712 +
   1.713 +lemma Union_empty [simp]: "Union({}) = {}"
   1.714 +  by blast
   1.715 +
   1.716 +lemma Union_UNIV [simp]: "Union UNIV = UNIV"
   1.717 +  by blast
   1.718 +
   1.719 +lemma Union_insert [simp]: "Union (insert a B) = a \<union> \<Union>B"
   1.720 +  by blast
   1.721 +
   1.722 +lemma Union_Un_distrib [simp]: "\<Union>(A Un B) = \<Union>A \<union> \<Union>B"
   1.723 +  by blast
   1.724 +
   1.725 +lemma Union_Int_subset: "\<Union>(A \<inter> B) \<subseteq> \<Union>A \<inter> \<Union>B"
   1.726 +  by blast
   1.727 +
   1.728 +lemma Union_empty_conv [iff]: "(\<Union>A = {}) = (\<forall>x\<in>A. x = {})"
   1.729 +  by auto
   1.730 +
   1.731 +lemma Union_disjoint: "(\<Union>C \<inter> A = {}) = (\<forall>B\<in>C. B \<inter> A = {})"
   1.732 +  by blast
   1.733 +
   1.734 +
   1.735 +text {* \medskip @{text Inter}. *}
   1.736 +
   1.737 +lemma Inter_empty [simp]: "\<Inter>{} = UNIV"
   1.738 +  by blast
   1.739 +
   1.740 +lemma Inter_UNIV [simp]: "\<Inter>UNIV = {}"
   1.741 +  by blast
   1.742 +
   1.743 +lemma Inter_insert [simp]: "\<Inter>(insert a B) = a \<inter> \<Inter>B"
   1.744 +  by blast
   1.745 +
   1.746 +lemma Inter_Un_subset: "\<Inter>A \<union> \<Inter>B \<subseteq> \<Inter>(A \<inter> B)"
   1.747 +  by blast
   1.748 +
   1.749 +lemma Inter_Un_distrib: "\<Inter>(A \<union> B) = \<Inter>A \<inter> \<Inter>B"
   1.750 +  by blast
   1.751 +
   1.752 +
   1.753 +text {*
   1.754 +  \medskip @{text UN} and @{text INT}.
   1.755 +
   1.756 +  Basic identities: *}
   1.757 +
   1.758 +lemma UN_empty [simp]: "(\<Union>x\<in>{}. B x) = {}"
   1.759 +  by blast
   1.760 +
   1.761 +lemma UN_empty2 [simp]: "(\<Union>x\<in>A. {}) = {}"
   1.762 +  by blast
   1.763 +
   1.764 +lemma UN_singleton [simp]: "(\<Union>x\<in>A. {x}) = A"
   1.765 +  by blast
   1.766 +
   1.767 +lemma UN_absorb: "k \<in> I ==> A k \<union> (\<Union>i\<in>I. A i) = (\<Union>i\<in>I. A i)"
   1.768 +  by blast
   1.769 +
   1.770 +lemma INT_empty [simp]: "(\<Inter>x\<in>{}. B x) = UNIV"
   1.771 +  by blast
   1.772 +
   1.773 +lemma INT_absorb: "k \<in> I ==> A k \<inter> (\<Inter>i\<in>I. A i) = (\<Inter>i\<in>I. A i)"
   1.774 +  by blast
   1.775 +
   1.776 +lemma UN_insert [simp]: "(\<Union>x\<in>insert a A. B x) = B a \<union> UNION A B"
   1.777 +  by blast
   1.778 +
   1.779 +lemma UN_Un: "(\<Union>i \<in> A \<union> B. M i) = (\<Union>i\<in>A. M i) \<union> (\<Union>i\<in>B. M i)"
   1.780 +  by blast
   1.781 +
   1.782 +lemma UN_UN_flatten: "(\<Union>x \<in> (\<Union>y\<in>A. B y). C x) = (\<Union>y\<in>A. \<Union>x\<in>B y. C x)"
   1.783 +  by blast
   1.784 +
   1.785 +lemma UN_subset_iff: "((\<Union>i\<in>I. A i) \<subseteq> B) = (\<forall>i\<in>I. A i \<subseteq> B)"
   1.786 +  by blast
   1.787 +
   1.788 +lemma INT_subset_iff: "(B \<subseteq> (\<Inter>i\<in>I. A i)) = (\<forall>i\<in>I. B \<subseteq> A i)"
   1.789 +  by blast
   1.790 +
   1.791 +lemma INT_insert [simp]: "(\<Inter>x \<in> insert a A. B x) = B a \<inter> INTER A B"
   1.792 +  by blast
   1.793 +
   1.794 +lemma INT_Un: "(\<Inter>i \<in> A \<union> B. M i) = (\<Inter>i \<in> A. M i) \<inter> (\<Inter>i\<in>B. M i)"
   1.795 +  by blast
   1.796 +
   1.797 +lemma INT_insert_distrib:
   1.798 +    "u \<in> A ==> (\<Inter>x\<in>A. insert a (B x)) = insert a (\<Inter>x\<in>A. B x)"
   1.799 +  by blast
   1.800 +
   1.801 +lemma Union_image_eq [simp]: "\<Union>(B`A) = (\<Union>x\<in>A. B x)"
   1.802 +  by blast
   1.803 +
   1.804 +lemma image_Union: "f ` \<Union>S = (\<Union>x\<in>S. f ` x)"
   1.805 +  by blast
   1.806 +
   1.807 +lemma Inter_image_eq [simp]: "\<Inter>(B`A) = (\<Inter>x\<in>A. B x)"
   1.808 +  by blast
   1.809 +
   1.810 +lemma UN_constant [simp]: "(\<Union>y\<in>A. c) = (if A = {} then {} else c)"
   1.811 +  by auto
   1.812 +
   1.813 +lemma INT_constant [simp]: "(\<Inter>y\<in>A. c) = (if A = {} then UNIV else c)"
   1.814 +  by auto
   1.815 +
   1.816 +lemma UN_eq: "(\<Union>x\<in>A. B x) = \<Union>({Y. \<exists>x\<in>A. Y = B x})"
   1.817 +  by blast
   1.818 +
   1.819 +lemma INT_eq: "(\<Inter>x\<in>A. B x) = \<Inter>({Y. \<exists>x\<in>A. Y = B x})"
   1.820 +  -- {* Look: it has an \emph{existential} quantifier *}
   1.821 +  by blast
   1.822 +
   1.823 +lemma UN_empty3 [iff]: "(UNION A B = {}) = (\<forall>x\<in>A. B x = {})"
   1.824 +  by auto
   1.825 +
   1.826 +
   1.827 +text {* \medskip Distributive laws: *}
   1.828 +
   1.829 +lemma Int_Union: "A \<inter> \<Union>B = (\<Union>C\<in>B. A \<inter> C)"
   1.830 +  by blast
   1.831 +
   1.832 +lemma Int_Union2: "\<Union>B \<inter> A = (\<Union>C\<in>B. C \<inter> A)"
   1.833 +  by blast
   1.834 +
   1.835 +lemma Un_Union_image: "(\<Union>x\<in>C. A x \<union> B x) = \<Union>(A`C) \<union> \<Union>(B`C)"
   1.836 +  -- {* Devlin, Fundamentals of Contemporary Set Theory, page 12, exercise 5: *}
   1.837 +  -- {* Union of a family of unions *}
   1.838 +  by blast
   1.839 +
   1.840 +lemma UN_Un_distrib: "(\<Union>i\<in>I. A i \<union> B i) = (\<Union>i\<in>I. A i) \<union> (\<Union>i\<in>I. B i)"
   1.841 +  -- {* Equivalent version *}
   1.842 +  by blast
   1.843 +
   1.844 +lemma Un_Inter: "A \<union> \<Inter>B = (\<Inter>C\<in>B. A \<union> C)"
   1.845 +  by blast
   1.846 +
   1.847 +lemma Int_Inter_image: "(\<Inter>x\<in>C. A x \<inter> B x) = \<Inter>(A`C) \<inter> \<Inter>(B`C)"
   1.848 +  by blast
   1.849 +
   1.850 +lemma INT_Int_distrib: "(\<Inter>i\<in>I. A i \<inter> B i) = (\<Inter>i\<in>I. A i) \<inter> (\<Inter>i\<in>I. B i)"
   1.851 +  -- {* Equivalent version *}
   1.852 +  by blast
   1.853 +
   1.854 +lemma Int_UN_distrib: "B \<inter> (\<Union>i\<in>I. A i) = (\<Union>i\<in>I. B \<inter> A i)"
   1.855 +  -- {* Halmos, Naive Set Theory, page 35. *}
   1.856 +  by blast
   1.857 +
   1.858 +lemma Un_INT_distrib: "B \<union> (\<Inter>i\<in>I. A i) = (\<Inter>i\<in>I. B \<union> A i)"
   1.859 +  by blast
   1.860 +
   1.861 +lemma Int_UN_distrib2: "(\<Union>i\<in>I. A i) \<inter> (\<Union>j\<in>J. B j) = (\<Union>i\<in>I. \<Union>j\<in>J. A i \<inter> B j)"
   1.862 +  by blast
   1.863 +
   1.864 +lemma Un_INT_distrib2: "(\<Inter>i\<in>I. A i) \<union> (\<Inter>j\<in>J. B j) = (\<Inter>i\<in>I. \<Inter>j\<in>J. A i \<union> B j)"
   1.865 +  by blast
   1.866 +
   1.867 +
   1.868 +text {* \medskip Bounded quantifiers.
   1.869 +
   1.870 +  The following are not added to the default simpset because
   1.871 +  (a) they duplicate the body and (b) there are no similar rules for @{text Int}. *}
   1.872 +
   1.873 +lemma ball_Un: "(\<forall>x \<in> A \<union> B. P x) = ((\<forall>x\<in>A. P x) & (\<forall>x\<in>B. P x))"
   1.874 +  by blast
   1.875 +
   1.876 +lemma bex_Un: "(\<exists>x \<in> A \<union> B. P x) = ((\<exists>x\<in>A. P x) | (\<exists>x\<in>B. P x))"
   1.877 +  by blast
   1.878 +
   1.879 +lemma ball_UN: "(\<forall>z \<in> UNION A B. P z) = (\<forall>x\<in>A. \<forall>z \<in> B x. P z)"
   1.880 +  by blast
   1.881 +
   1.882 +lemma bex_UN: "(\<exists>z \<in> UNION A B. P z) = (\<exists>x\<in>A. \<exists>z\<in>B x. P z)"
   1.883 +  by blast
   1.884 +
   1.885 +
   1.886 +text {* \medskip Set difference. *}
   1.887 +
   1.888 +lemma Diff_eq: "A - B = A \<inter> (-B)"
   1.889 +  by blast
   1.890 +
   1.891 +lemma Diff_eq_empty_iff [simp]: "(A - B = {}) = (A \<subseteq> B)"
   1.892 +  by blast
   1.893 +
   1.894 +lemma Diff_cancel [simp]: "A - A = {}"
   1.895 +  by blast
   1.896 +
   1.897 +lemma Diff_triv: "A \<inter> B = {} ==> A - B = A"
   1.898 +  by (blast elim: equalityE)
   1.899 +
   1.900 +lemma empty_Diff [simp]: "{} - A = {}"
   1.901 +  by blast
   1.902 +
   1.903 +lemma Diff_empty [simp]: "A - {} = A"
   1.904 +  by blast
   1.905 +
   1.906 +lemma Diff_UNIV [simp]: "A - UNIV = {}"
   1.907 +  by blast
   1.908 +
   1.909 +lemma Diff_insert0 [simp]: "x \<notin> A ==> A - insert x B = A - B"
   1.910 +  by blast
   1.911 +
   1.912 +lemma Diff_insert: "A - insert a B = A - B - {a}"
   1.913 +  -- {* NOT SUITABLE FOR REWRITING since @{text "{a} == insert a 0"} *}
   1.914 +  by blast
   1.915 +
   1.916 +lemma Diff_insert2: "A - insert a B = A - {a} - B"
   1.917 +  -- {* NOT SUITABLE FOR REWRITING since @{text "{a} == insert a 0"} *}
   1.918 +  by blast
   1.919 +
   1.920 +lemma insert_Diff_if: "insert x A - B = (if x \<in> B then A - B else insert x (A - B))"
   1.921 +  by auto
   1.922 +
   1.923 +lemma insert_Diff1 [simp]: "x \<in> B ==> insert x A - B = A - B"
   1.924 +  by blast
   1.925 +
   1.926 +lemma insert_Diff: "a \<in> A ==> insert a (A - {a}) = A"
   1.927 +  by blast
   1.928 +
   1.929 +lemma Diff_insert_absorb: "x \<notin> A ==> (insert x A) - {x} = A"
   1.930 +  by auto
   1.931 +
   1.932 +lemma Diff_disjoint [simp]: "A \<inter> (B - A) = {}"
   1.933 +  by blast
   1.934 +
   1.935 +lemma Diff_partition: "A \<subseteq> B ==> A \<union> (B - A) = B"
   1.936 +  by blast
   1.937 +
   1.938 +lemma double_diff: "A \<subseteq> B ==> B \<subseteq> C ==> B - (C - A) = A"
   1.939 +  by blast
   1.940 +
   1.941 +lemma Un_Diff_cancel [simp]: "A \<union> (B - A) = A \<union> B"
   1.942 +  by blast
   1.943 +
   1.944 +lemma Un_Diff_cancel2 [simp]: "(B - A) \<union> A = B \<union> A"
   1.945 +  by blast
   1.946 +
   1.947 +lemma Diff_Un: "A - (B \<union> C) = (A - B) \<inter> (A - C)"
   1.948 +  by blast
   1.949 +
   1.950 +lemma Diff_Int: "A - (B \<inter> C) = (A - B) \<union> (A - C)"
   1.951 +  by blast
   1.952 +
   1.953 +lemma Un_Diff: "(A \<union> B) - C = (A - C) \<union> (B - C)"
   1.954 +  by blast
   1.955 +
   1.956 +lemma Int_Diff: "(A \<inter> B) - C = A \<inter> (B - C)"
   1.957 +  by blast
   1.958 +
   1.959 +lemma Diff_Int_distrib: "C \<inter> (A - B) = (C \<inter> A) - (C \<inter> B)"
   1.960 +  by blast
   1.961 +
   1.962 +lemma Diff_Int_distrib2: "(A - B) \<inter> C = (A \<inter> C) - (B \<inter> C)"
   1.963 +  by blast
   1.964 +
   1.965 +lemma Diff_Compl [simp]: "A - (- B) = A \<inter> B"
   1.966 +  by auto
   1.967 +
   1.968 +lemma Compl_Diff_eq [simp]: "- (A - B) = -A \<union> B"
   1.969 +  by blast
   1.970 +
   1.971 +
   1.972 +text {* \medskip Quantification over type @{typ bool}. *}
   1.973 +
   1.974 +lemma all_bool_eq: "(\<forall>b::bool. P b) = (P True & P False)"
   1.975 +  apply auto
   1.976 +  apply (tactic {* case_tac "b" 1 *})
   1.977 +   apply auto
   1.978 +  done
   1.979 +
   1.980 +lemma bool_induct: "P True \<Longrightarrow> P False \<Longrightarrow> P x"
   1.981 +  by (rule conjI [THEN all_bool_eq [THEN iffD2], THEN spec])
   1.982 +
   1.983 +lemma ex_bool_eq: "(\<exists>b::bool. P b) = (P True | P False)"
   1.984 +  apply auto
   1.985 +  apply (tactic {* case_tac "b" 1 *})
   1.986 +   apply auto
   1.987 +  done
   1.988 +
   1.989 +lemma Un_eq_UN: "A \<union> B = (\<Union>b. if b then A else B)"
   1.990 +  by (auto simp add: split_if_mem2)
   1.991 +
   1.992 +lemma UN_bool_eq: "(\<Union>b::bool. A b) = (A True \<union> A False)"
   1.993 +  apply auto
   1.994 +  apply (tactic {* case_tac "b" 1 *})
   1.995 +   apply auto
   1.996 +  done
   1.997 +
   1.998 +lemma INT_bool_eq: "(\<Inter>b::bool. A b) = (A True \<inter> A False)"
   1.999 +  apply auto
  1.1000 +  apply (tactic {* case_tac "b" 1 *})
  1.1001 +  apply auto
  1.1002 +  done
  1.1003 +
  1.1004 +
  1.1005 +text {* \medskip @{text Pow} *}
  1.1006 +
  1.1007 +lemma Pow_empty [simp]: "Pow {} = {{}}"
  1.1008 +  by (auto simp add: Pow_def)
  1.1009 +
  1.1010 +lemma Pow_insert: "Pow (insert a A) = Pow A \<union> (insert a ` Pow A)"
  1.1011 +  by (blast intro: image_eqI [where ?x = "u - {a}", standard])
  1.1012 +
  1.1013 +lemma Pow_Compl: "Pow (- A) = {-B | B. A \<in> Pow B}"
  1.1014 +  by (blast intro: exI [where ?x = "- u", standard])
  1.1015 +
  1.1016 +lemma Pow_UNIV [simp]: "Pow UNIV = UNIV"
  1.1017 +  by blast
  1.1018 +
  1.1019 +lemma Un_Pow_subset: "Pow A \<union> Pow B \<subseteq> Pow (A \<union> B)"
  1.1020 +  by blast
  1.1021 +
  1.1022 +lemma UN_Pow_subset: "(\<Union>x\<in>A. Pow (B x)) \<subseteq> Pow (\<Union>x\<in>A. B x)"
  1.1023 +  by blast
  1.1024 +
  1.1025 +lemma subset_Pow_Union: "A \<subseteq> Pow (\<Union>A)"
  1.1026 +  by blast
  1.1027 +
  1.1028 +lemma Union_Pow_eq [simp]: "\<Union>(Pow A) = A"
  1.1029 +  by blast
  1.1030 +
  1.1031 +lemma Pow_Int_eq [simp]: "Pow (A \<inter> B) = Pow A \<inter> Pow B"
  1.1032 +  by blast
  1.1033 +
  1.1034 +lemma Pow_INT_eq: "Pow (\<Inter>x\<in>A. B x) = (\<Inter>x\<in>A. Pow (B x))"
  1.1035 +  by blast
  1.1036 +
  1.1037 +
  1.1038 +text {* \medskip Miscellany. *}
  1.1039 +
  1.1040 +lemma set_eq_subset: "(A = B) = (A \<subseteq> B & B \<subseteq> A)"
  1.1041 +  by blast
  1.1042 +
  1.1043 +lemma subset_iff: "(A \<subseteq> B) = (\<forall>t. t \<in> A --> t \<in> B)"
  1.1044 +  by blast
  1.1045 +
  1.1046 +lemma subset_iff_psubset_eq: "(A \<subseteq> B) = ((A \<subset> B) | (A = B))"
  1.1047 +  by (unfold psubset_def) blast
  1.1048 +
  1.1049 +lemma all_not_in_conv [iff]: "(\<forall>x. x \<notin> A) = (A = {})"
  1.1050 +  by blast
  1.1051 +
  1.1052 +lemma distinct_lemma: "f x \<noteq> f y ==> x \<noteq> y"
  1.1053 +  by rules
  1.1054 +
  1.1055 +
  1.1056 +text {* \medskip Miniscoping: pushing in big Unions and Intersections. *}
  1.1057 +
  1.1058 +lemma UN_simps [simp]:
  1.1059 +  "!!a B C. (UN x:C. insert a (B x)) = (if C={} then {} else insert a (UN x:C. B x))"
  1.1060 +  "!!A B C. (UN x:C. A x Un B)   = ((if C={} then {} else (UN x:C. A x) Un B))"
  1.1061 +  "!!A B C. (UN x:C. A Un B x)   = ((if C={} then {} else A Un (UN x:C. B x)))"
  1.1062 +  "!!A B C. (UN x:C. A x Int B)  = ((UN x:C. A x) Int B)"
  1.1063 +  "!!A B C. (UN x:C. A Int B x)  = (A Int (UN x:C. B x))"
  1.1064 +  "!!A B C. (UN x:C. A x - B)    = ((UN x:C. A x) - B)"
  1.1065 +  "!!A B C. (UN x:C. A - B x)    = (A - (INT x:C. B x))"
  1.1066 +  "!!A B. (UN x: Union A. B x) = (UN y:A. UN x:y. B x)"
  1.1067 +  "!!A B C. (UN z: UNION A B. C z) = (UN  x:A. UN z: B(x). C z)"
  1.1068 +  "!!A B f. (UN x:f`A. B x)     = (UN a:A. B (f a))"
  1.1069 +  by auto
  1.1070 +
  1.1071 +lemma INT_simps [simp]:
  1.1072 +  "!!A B C. (INT x:C. A x Int B) = (if C={} then UNIV else (INT x:C. A x) Int B)"
  1.1073 +  "!!A B C. (INT x:C. A Int B x) = (if C={} then UNIV else A Int (INT x:C. B x))"
  1.1074 +  "!!A B C. (INT x:C. A x - B)   = (if C={} then UNIV else (INT x:C. A x) - B)"
  1.1075 +  "!!A B C. (INT x:C. A - B x)   = (if C={} then UNIV else A - (UN x:C. B x))"
  1.1076 +  "!!a B C. (INT x:C. insert a (B x)) = insert a (INT x:C. B x)"
  1.1077 +  "!!A B C. (INT x:C. A x Un B)  = ((INT x:C. A x) Un B)"
  1.1078 +  "!!A B C. (INT x:C. A Un B x)  = (A Un (INT x:C. B x))"
  1.1079 +  "!!A B. (INT x: Union A. B x) = (INT y:A. INT x:y. B x)"
  1.1080 +  "!!A B C. (INT z: UNION A B. C z) = (INT x:A. INT z: B(x). C z)"
  1.1081 +  "!!A B f. (INT x:f`A. B x)    = (INT a:A. B (f a))"
  1.1082 +  by auto
  1.1083 +
  1.1084 +lemma ball_simps [simp]:
  1.1085 +  "!!A P Q. (ALL x:A. P x | Q) = ((ALL x:A. P x) | Q)"
  1.1086 +  "!!A P Q. (ALL x:A. P | Q x) = (P | (ALL x:A. Q x))"
  1.1087 +  "!!A P Q. (ALL x:A. P --> Q x) = (P --> (ALL x:A. Q x))"
  1.1088 +  "!!A P Q. (ALL x:A. P x --> Q) = ((EX x:A. P x) --> Q)"
  1.1089 +  "!!P. (ALL x:{}. P x) = True"
  1.1090 +  "!!P. (ALL x:UNIV. P x) = (ALL x. P x)"
  1.1091 +  "!!a B P. (ALL x:insert a B. P x) = (P a & (ALL x:B. P x))"
  1.1092 +  "!!A P. (ALL x:Union A. P x) = (ALL y:A. ALL x:y. P x)"
  1.1093 +  "!!A B P. (ALL x: UNION A B. P x) = (ALL a:A. ALL x: B a. P x)"
  1.1094 +  "!!P Q. (ALL x:Collect Q. P x) = (ALL x. Q x --> P x)"
  1.1095 +  "!!A P f. (ALL x:f`A. P x) = (ALL x:A. P (f x))"
  1.1096 +  "!!A P. (~(ALL x:A. P x)) = (EX x:A. ~P x)"
  1.1097 +  by auto
  1.1098 +
  1.1099 +lemma bex_simps [simp]:
  1.1100 +  "!!A P Q. (EX x:A. P x & Q) = ((EX x:A. P x) & Q)"
  1.1101 +  "!!A P Q. (EX x:A. P & Q x) = (P & (EX x:A. Q x))"
  1.1102 +  "!!P. (EX x:{}. P x) = False"
  1.1103 +  "!!P. (EX x:UNIV. P x) = (EX x. P x)"
  1.1104 +  "!!a B P. (EX x:insert a B. P x) = (P(a) | (EX x:B. P x))"
  1.1105 +  "!!A P. (EX x:Union A. P x) = (EX y:A. EX x:y. P x)"
  1.1106 +  "!!A B P. (EX x: UNION A B. P x) = (EX a:A. EX x:B a. P x)"
  1.1107 +  "!!P Q. (EX x:Collect Q. P x) = (EX x. Q x & P x)"
  1.1108 +  "!!A P f. (EX x:f`A. P x) = (EX x:A. P (f x))"
  1.1109 +  "!!A P. (~(EX x:A. P x)) = (ALL x:A. ~P x)"
  1.1110 +  by auto
  1.1111 +
  1.1112 +lemma ball_conj_distrib:
  1.1113 +  "(ALL x:A. P x & Q x) = ((ALL x:A. P x) & (ALL x:A. Q x))"
  1.1114 +  by blast
  1.1115 +
  1.1116 +lemma bex_disj_distrib:
  1.1117 +  "(EX x:A. P x | Q x) = ((EX x:A. P x) | (EX x:A. Q x))"
  1.1118 +  by blast
  1.1119 +
  1.1120 +
  1.1121 +subsubsection {* Monotonicity of various operations *}
  1.1122 +
  1.1123 +lemma image_mono: "A \<subseteq> B ==> f`A \<subseteq> f`B"
  1.1124 +  by blast
  1.1125 +
  1.1126 +lemma Pow_mono: "A \<subseteq> B ==> Pow A \<subseteq> Pow B"
  1.1127 +  by blast
  1.1128 +
  1.1129 +lemma Union_mono: "A \<subseteq> B ==> \<Union>A \<subseteq> \<Union>B"
  1.1130 +  by blast
  1.1131 +
  1.1132 +lemma Inter_anti_mono: "B \<subseteq> A ==> \<Inter>A \<subseteq> \<Inter>B"
  1.1133 +  by blast
  1.1134 +
  1.1135 +lemma UN_mono:
  1.1136 +  "A \<subseteq> B ==> (!!x. x \<in> A ==> f x \<subseteq> g x) ==>
  1.1137 +    (\<Union>x\<in>A. f x) \<subseteq> (\<Union>x\<in>B. g x)"
  1.1138 +  by (blast dest: subsetD)
  1.1139 +
  1.1140 +lemma INT_anti_mono:
  1.1141 +  "B \<subseteq> A ==> (!!x. x \<in> A ==> f x \<subseteq> g x) ==>
  1.1142 +    (\<Inter>x\<in>A. f x) \<subseteq> (\<Inter>x\<in>A. g x)"
  1.1143 +  -- {* The last inclusion is POSITIVE! *}
  1.1144 +  by (blast dest: subsetD)
  1.1145 +
  1.1146 +lemma insert_mono: "C \<subseteq> D ==> insert a C \<subseteq> insert a D"
  1.1147 +  by blast
  1.1148 +
  1.1149 +lemma Un_mono: "A \<subseteq> C ==> B \<subseteq> D ==> A \<union> B \<subseteq> C \<union> D"
  1.1150 +  by blast
  1.1151 +
  1.1152 +lemma Int_mono: "A \<subseteq> C ==> B \<subseteq> D ==> A \<inter> B \<subseteq> C \<inter> D"
  1.1153 +  by blast
  1.1154 +
  1.1155 +lemma Diff_mono: "A \<subseteq> C ==> D \<subseteq> B ==> A - B \<subseteq> C - D"
  1.1156 +  by blast
  1.1157 +
  1.1158 +lemma Compl_anti_mono: "A \<subseteq> B ==> -B \<subseteq> -A"
  1.1159 +  by blast
  1.1160 +
  1.1161 +text {* \medskip Monotonicity of implications. *}
  1.1162 +
  1.1163 +lemma in_mono: "A \<subseteq> B ==> x \<in> A --> x \<in> B"
  1.1164 +  apply (rule impI)
  1.1165 +  apply (erule subsetD)
  1.1166 +  apply assumption
  1.1167 +  done
  1.1168 +
  1.1169 +lemma conj_mono: "P1 --> Q1 ==> P2 --> Q2 ==> (P1 & P2) --> (Q1 & Q2)"
  1.1170 +  by rules
  1.1171 +
  1.1172 +lemma disj_mono: "P1 --> Q1 ==> P2 --> Q2 ==> (P1 | P2) --> (Q1 | Q2)"
  1.1173 +  by rules
  1.1174 +
  1.1175 +lemma imp_mono: "Q1 --> P1 ==> P2 --> Q2 ==> (P1 --> P2) --> (Q1 --> Q2)"
  1.1176 +  by rules
  1.1177 +
  1.1178 +lemma imp_refl: "P --> P" ..
  1.1179 +
  1.1180 +lemma ex_mono: "(!!x. P x --> Q x) ==> (EX x. P x) --> (EX x. Q x)"
  1.1181 +  by rules
  1.1182 +
  1.1183 +lemma all_mono: "(!!x. P x --> Q x) ==> (ALL x. P x) --> (ALL x. Q x)"
  1.1184 +  by rules
  1.1185 +
  1.1186 +lemma Collect_mono: "(!!x. P x --> Q x) ==> Collect P \<subseteq> Collect Q"
  1.1187 +  by blast
  1.1188 +
  1.1189 +lemma Int_Collect_mono:
  1.1190 +    "A \<subseteq> B ==> (!!x. x \<in> A ==> P x --> Q x) ==> A \<inter> Collect P \<subseteq> B \<inter> Collect Q"
  1.1191 +  by blast
  1.1192 +
  1.1193 +lemmas basic_monos =
  1.1194 +  subset_refl imp_refl disj_mono conj_mono
  1.1195 +  ex_mono Collect_mono in_mono
  1.1196 +
  1.1197 +lemma eq_to_mono: "a = b ==> c = d ==> b --> d ==> a --> c"
  1.1198 +  by rules
  1.1199 +
  1.1200 +lemma eq_to_mono2: "a = b ==> c = d ==> ~ b --> ~ d ==> ~ a --> ~ c"
  1.1201 +  by rules
  1.1202  
  1.1203  lemma Least_mono:
  1.1204    "mono (f::'a::order => 'b::order) ==> EX x:S. ALL y:S. x <= y
  1.1205 @@ -972,7 +1858,7 @@
  1.1206    -- {* NOT suitable for rewriting *}
  1.1207    by blast
  1.1208  
  1.1209 -lemma vimage_mono: "A <= B ==> f -` A <= f -` B"
  1.1210 +lemma vimage_mono: "A \<subseteq> B ==> f -` A \<subseteq> f -` B"
  1.1211    -- {* monotonicity *}
  1.1212    by blast
  1.1213  
  1.1214 @@ -985,10 +1871,10 @@
  1.1215  lemma back_subst: "P a ==> a = b ==> P b"
  1.1216    by (rule subst)
  1.1217  
  1.1218 -lemma set_rev_mp: "x:A ==> A <= B ==> x:B"
  1.1219 +lemma set_rev_mp: "x:A ==> A \<subseteq> B ==> x:B"
  1.1220    by (rule subsetD)
  1.1221  
  1.1222 -lemma set_mp: "A <= B ==> x:A ==> x:B"
  1.1223 +lemma set_mp: "A \<subseteq> B ==> x:A ==> x:B"
  1.1224    by (rule subsetD)
  1.1225  
  1.1226  lemma order_neq_le_trans: "a ~= b ==> (a::'a::order) <= b ==> a < b"