src/HOL/Set.thy
author haftmann
Mon Jul 20 11:47:17 2009 +0200 (2009-07-20)
changeset 32081 1b7a901e2edc
parent 32078 1c14f77201d4
child 32082 90d03908b3d7
permissions -rw-r--r--
refined outline structure
     1 (*  Title:      HOL/Set.thy
     2     Author:     Tobias Nipkow, Lawrence C Paulson and Markus Wenzel
     3 *)
     4 
     5 header {* Set theory for higher-order logic *}
     6 
     7 theory Set
     8 imports Lattices
     9 begin
    10 
    11 subsection {* Sets as predicates *}
    12 
    13 global
    14 
    15 types 'a set = "'a => bool"
    16 
    17 consts
    18   Collect       :: "('a => bool) => 'a set"              -- "comprehension"
    19   "op :"        :: "'a => 'a set => bool"                -- "membership"
    20 
    21 local
    22 
    23 notation
    24   "op :"  ("op :") and
    25   "op :"  ("(_/ : _)" [50, 51] 50)
    26 
    27 defs
    28   mem_def [code]: "x : S == S x"
    29   Collect_def [code]: "Collect P == P"
    30 
    31 abbreviation
    32   "not_mem x A == ~ (x : A)" -- "non-membership"
    33 
    34 notation
    35   not_mem  ("op ~:") and
    36   not_mem  ("(_/ ~: _)" [50, 51] 50)
    37 
    38 notation (xsymbols)
    39   "op :"  ("op \<in>") and
    40   "op :"  ("(_/ \<in> _)" [50, 51] 50) and
    41   not_mem  ("op \<notin>") and
    42   not_mem  ("(_/ \<notin> _)" [50, 51] 50)
    43 
    44 notation (HTML output)
    45   "op :"  ("op \<in>") and
    46   "op :"  ("(_/ \<in> _)" [50, 51] 50) and
    47   not_mem  ("op \<notin>") and
    48   not_mem  ("(_/ \<notin> _)" [50, 51] 50)
    49 
    50 text {* Set comprehensions *}
    51 
    52 syntax
    53   "@Coll"       :: "pttrn => bool => 'a set"              ("(1{_./ _})")
    54 
    55 translations
    56   "{x. P}"      == "Collect (%x. P)"
    57 
    58 syntax
    59   "@SetCompr"   :: "'a => idts => bool => 'a set"         ("(1{_ |/_./ _})")
    60   "@Collect"    :: "idt => 'a set => bool => 'a set"      ("(1{_ :/ _./ _})")
    61 
    62 syntax (xsymbols)
    63   "@Collect"    :: "idt => 'a set => bool => 'a set"      ("(1{_ \<in>/ _./ _})")
    64 
    65 translations
    66   "{x:A. P}"    => "{x. x:A & P}"
    67 
    68 lemma mem_Collect_eq [iff]: "(a : {x. P(x)}) = P(a)"
    69   by (simp add: Collect_def mem_def)
    70 
    71 lemma Collect_mem_eq [simp]: "{x. x:A} = A"
    72   by (simp add: Collect_def mem_def)
    73 
    74 lemma CollectI: "P(a) ==> a : {x. P(x)}"
    75   by simp
    76 
    77 lemma CollectD: "a : {x. P(x)} ==> P(a)"
    78   by simp
    79 
    80 lemma Collect_cong: "(!!x. P x = Q x) ==> {x. P(x)} = {x. Q(x)}"
    81   by simp
    82 
    83 lemmas CollectE = CollectD [elim_format]
    84 
    85 text {* Set enumerations *}
    86 
    87 definition empty :: "'a set" ("{}") where
    88   "empty \<equiv> {x. False}"
    89 
    90 definition insert :: "'a \<Rightarrow> 'a set \<Rightarrow> 'a set" where
    91   insert_compr: "insert a B = {x. x = a \<or> x \<in> B}"
    92 
    93 syntax
    94   "@Finset"     :: "args => 'a set"                       ("{(_)}")
    95 
    96 translations
    97   "{x, xs}"     == "CONST insert x {xs}"
    98   "{x}"         == "CONST insert x {}"
    99 
   100 
   101 subsection {* Subsets and bounded quantifiers *}
   102 
   103 abbreviation
   104   subset :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where
   105   "subset \<equiv> less"
   106 
   107 abbreviation
   108   subset_eq :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where
   109   "subset_eq \<equiv> less_eq"
   110 
   111 notation (output)
   112   subset  ("op <") and
   113   subset  ("(_/ < _)" [50, 51] 50) and
   114   subset_eq  ("op <=") and
   115   subset_eq  ("(_/ <= _)" [50, 51] 50)
   116 
   117 notation (xsymbols)
   118   subset  ("op \<subset>") and
   119   subset  ("(_/ \<subset> _)" [50, 51] 50) and
   120   subset_eq  ("op \<subseteq>") and
   121   subset_eq  ("(_/ \<subseteq> _)" [50, 51] 50)
   122 
   123 notation (HTML output)
   124   subset  ("op \<subset>") and
   125   subset  ("(_/ \<subset> _)" [50, 51] 50) and
   126   subset_eq  ("op \<subseteq>") and
   127   subset_eq  ("(_/ \<subseteq> _)" [50, 51] 50)
   128 
   129 abbreviation (input)
   130   supset :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where
   131   "supset \<equiv> greater"
   132 
   133 abbreviation (input)
   134   supset_eq :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where
   135   "supset_eq \<equiv> greater_eq"
   136 
   137 notation (xsymbols)
   138   supset  ("op \<supset>") and
   139   supset  ("(_/ \<supset> _)" [50, 51] 50) and
   140   supset_eq  ("op \<supseteq>") and
   141   supset_eq  ("(_/ \<supseteq> _)" [50, 51] 50)
   142 
   143 global
   144 
   145 consts
   146   Ball          :: "'a set => ('a => bool) => bool"      -- "bounded universal quantifiers"
   147   Bex           :: "'a set => ('a => bool) => bool"      -- "bounded existential quantifiers"
   148   Bex1          :: "'a set => ('a => bool) => bool"      -- "bounded unique existential quantifiers"
   149 
   150 local
   151 
   152 defs
   153   Ball_def:     "Ball A P       == ALL x. x:A --> P(x)"
   154   Bex_def:      "Bex A P        == EX x. x:A & P(x)"
   155   Bex1_def:     "Bex1 A P       == EX! x. x:A & P(x)"
   156 
   157 syntax
   158   "_Ball"       :: "pttrn => 'a set => bool => bool"      ("(3ALL _:_./ _)" [0, 0, 10] 10)
   159   "_Bex"        :: "pttrn => 'a set => bool => bool"      ("(3EX _:_./ _)" [0, 0, 10] 10)
   160   "_Bex1"       :: "pttrn => 'a set => bool => bool"      ("(3EX! _:_./ _)" [0, 0, 10] 10)
   161   "_Bleast"     :: "id => 'a set => bool => 'a"           ("(3LEAST _:_./ _)" [0, 0, 10] 10)
   162 
   163 syntax (HOL)
   164   "_Ball"       :: "pttrn => 'a set => bool => bool"      ("(3! _:_./ _)" [0, 0, 10] 10)
   165   "_Bex"        :: "pttrn => 'a set => bool => bool"      ("(3? _:_./ _)" [0, 0, 10] 10)
   166   "_Bex1"       :: "pttrn => 'a set => bool => bool"      ("(3?! _:_./ _)" [0, 0, 10] 10)
   167 
   168 syntax (xsymbols)
   169   "_Ball"       :: "pttrn => 'a set => bool => bool"      ("(3\<forall>_\<in>_./ _)" [0, 0, 10] 10)
   170   "_Bex"        :: "pttrn => 'a set => bool => bool"      ("(3\<exists>_\<in>_./ _)" [0, 0, 10] 10)
   171   "_Bex1"       :: "pttrn => 'a set => bool => bool"      ("(3\<exists>!_\<in>_./ _)" [0, 0, 10] 10)
   172   "_Bleast"     :: "id => 'a set => bool => 'a"           ("(3LEAST_\<in>_./ _)" [0, 0, 10] 10)
   173 
   174 syntax (HTML output)
   175   "_Ball"       :: "pttrn => 'a set => bool => bool"      ("(3\<forall>_\<in>_./ _)" [0, 0, 10] 10)
   176   "_Bex"        :: "pttrn => 'a set => bool => bool"      ("(3\<exists>_\<in>_./ _)" [0, 0, 10] 10)
   177   "_Bex1"       :: "pttrn => 'a set => bool => bool"      ("(3\<exists>!_\<in>_./ _)" [0, 0, 10] 10)
   178 
   179 translations
   180   "ALL x:A. P"  == "Ball A (%x. P)"
   181   "EX x:A. P"   == "Bex A (%x. P)"
   182   "EX! x:A. P"  == "Bex1 A (%x. P)"
   183   "LEAST x:A. P" => "LEAST x. x:A & P"
   184 
   185 syntax (output)
   186   "_setlessAll" :: "[idt, 'a, bool] => bool"  ("(3ALL _<_./ _)"  [0, 0, 10] 10)
   187   "_setlessEx"  :: "[idt, 'a, bool] => bool"  ("(3EX _<_./ _)"  [0, 0, 10] 10)
   188   "_setleAll"   :: "[idt, 'a, bool] => bool"  ("(3ALL _<=_./ _)" [0, 0, 10] 10)
   189   "_setleEx"    :: "[idt, 'a, bool] => bool"  ("(3EX _<=_./ _)" [0, 0, 10] 10)
   190   "_setleEx1"   :: "[idt, 'a, bool] => bool"  ("(3EX! _<=_./ _)" [0, 0, 10] 10)
   191 
   192 syntax (xsymbols)
   193   "_setlessAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<subset>_./ _)"  [0, 0, 10] 10)
   194   "_setlessEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<subset>_./ _)"  [0, 0, 10] 10)
   195   "_setleAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<subseteq>_./ _)" [0, 0, 10] 10)
   196   "_setleEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<subseteq>_./ _)" [0, 0, 10] 10)
   197   "_setleEx1"   :: "[idt, 'a, bool] => bool"   ("(3\<exists>!_\<subseteq>_./ _)" [0, 0, 10] 10)
   198 
   199 syntax (HOL output)
   200   "_setlessAll" :: "[idt, 'a, bool] => bool"   ("(3! _<_./ _)"  [0, 0, 10] 10)
   201   "_setlessEx"  :: "[idt, 'a, bool] => bool"   ("(3? _<_./ _)"  [0, 0, 10] 10)
   202   "_setleAll"   :: "[idt, 'a, bool] => bool"   ("(3! _<=_./ _)" [0, 0, 10] 10)
   203   "_setleEx"    :: "[idt, 'a, bool] => bool"   ("(3? _<=_./ _)" [0, 0, 10] 10)
   204   "_setleEx1"   :: "[idt, 'a, bool] => bool"   ("(3?! _<=_./ _)" [0, 0, 10] 10)
   205 
   206 syntax (HTML output)
   207   "_setlessAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<subset>_./ _)"  [0, 0, 10] 10)
   208   "_setlessEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<subset>_./ _)"  [0, 0, 10] 10)
   209   "_setleAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<subseteq>_./ _)" [0, 0, 10] 10)
   210   "_setleEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<subseteq>_./ _)" [0, 0, 10] 10)
   211   "_setleEx1"   :: "[idt, 'a, bool] => bool"   ("(3\<exists>!_\<subseteq>_./ _)" [0, 0, 10] 10)
   212 
   213 translations
   214  "\<forall>A\<subset>B. P"   =>  "ALL A. A \<subset> B --> P"
   215  "\<exists>A\<subset>B. P"   =>  "EX A. A \<subset> B & P"
   216  "\<forall>A\<subseteq>B. P"   =>  "ALL A. A \<subseteq> B --> P"
   217  "\<exists>A\<subseteq>B. P"   =>  "EX A. A \<subseteq> B & P"
   218  "\<exists>!A\<subseteq>B. P"  =>  "EX! A. A \<subseteq> B & P"
   219 
   220 print_translation {*
   221 let
   222   val Type (set_type, _) = @{typ "'a set"};
   223   val All_binder = Syntax.binder_name @{const_syntax "All"};
   224   val Ex_binder = Syntax.binder_name @{const_syntax "Ex"};
   225   val impl = @{const_syntax "op -->"};
   226   val conj = @{const_syntax "op &"};
   227   val sbset = @{const_syntax "subset"};
   228   val sbset_eq = @{const_syntax "subset_eq"};
   229 
   230   val trans =
   231    [((All_binder, impl, sbset), "_setlessAll"),
   232     ((All_binder, impl, sbset_eq), "_setleAll"),
   233     ((Ex_binder, conj, sbset), "_setlessEx"),
   234     ((Ex_binder, conj, sbset_eq), "_setleEx")];
   235 
   236   fun mk v v' c n P =
   237     if v = v' andalso not (Term.exists_subterm (fn Free (x, _) => x = v | _ => false) n)
   238     then Syntax.const c $ Syntax.mark_bound v' $ n $ P else raise Match;
   239 
   240   fun tr' q = (q,
   241     fn [Const ("_bound", _) $ Free (v, Type (T, _)), Const (c, _) $ (Const (d, _) $ (Const ("_bound", _) $ Free (v', _)) $ n) $ P] =>
   242          if T = (set_type) then case AList.lookup (op =) trans (q, c, d)
   243           of NONE => raise Match
   244            | SOME l => mk v v' l n P
   245          else raise Match
   246      | _ => raise Match);
   247 in
   248   [tr' All_binder, tr' Ex_binder]
   249 end
   250 *}
   251 
   252 
   253 text {*
   254   \medskip Translate between @{text "{e | x1...xn. P}"} and @{text
   255   "{u. EX x1..xn. u = e & P}"}; @{text "{y. EX x1..xn. y = e & P}"} is
   256   only translated if @{text "[0..n] subset bvs(e)"}.
   257 *}
   258 
   259 parse_translation {*
   260   let
   261     val ex_tr = snd (mk_binder_tr ("EX ", "Ex"));
   262 
   263     fun nvars (Const ("_idts", _) $ _ $ idts) = nvars idts + 1
   264       | nvars _ = 1;
   265 
   266     fun setcompr_tr [e, idts, b] =
   267       let
   268         val eq = Syntax.const "op =" $ Bound (nvars idts) $ e;
   269         val P = Syntax.const "op &" $ eq $ b;
   270         val exP = ex_tr [idts, P];
   271       in Syntax.const "Collect" $ Term.absdummy (dummyT, exP) end;
   272 
   273   in [("@SetCompr", setcompr_tr)] end;
   274 *}
   275 
   276 (* To avoid eta-contraction of body: *)
   277 print_translation {*
   278 let
   279   fun btr' syn [A, Abs abs] =
   280     let val (x, t) = atomic_abs_tr' abs
   281     in Syntax.const syn $ x $ A $ t end
   282 in [(@{const_syntax Ball}, btr' "_Ball"), (@{const_syntax Bex}, btr' "_Bex")] end
   283 *}
   284 
   285 print_translation {*
   286 let
   287   val ex_tr' = snd (mk_binder_tr' ("Ex", "DUMMY"));
   288 
   289   fun setcompr_tr' [Abs (abs as (_, _, P))] =
   290     let
   291       fun check (Const ("Ex", _) $ Abs (_, _, P), n) = check (P, n + 1)
   292         | check (Const ("op &", _) $ (Const ("op =", _) $ Bound m $ e) $ P, n) =
   293             n > 0 andalso m = n andalso not (loose_bvar1 (P, n)) andalso
   294             ((0 upto (n - 1)) subset add_loose_bnos (e, 0, []))
   295         | check _ = false
   296 
   297         fun tr' (_ $ abs) =
   298           let val _ $ idts $ (_ $ (_ $ _ $ e) $ Q) = ex_tr' [abs]
   299           in Syntax.const "@SetCompr" $ e $ idts $ Q end;
   300     in if check (P, 0) then tr' P
   301        else let val (x as _ $ Free(xN,_), t) = atomic_abs_tr' abs
   302                 val M = Syntax.const "@Coll" $ x $ t
   303             in case t of
   304                  Const("op &",_)
   305                    $ (Const("op :",_) $ (Const("_bound",_) $ Free(yN,_)) $ A)
   306                    $ P =>
   307                    if xN=yN then Syntax.const "@Collect" $ x $ A $ P else M
   308                | _ => M
   309             end
   310     end;
   311   in [("Collect", setcompr_tr')] end;
   312 *}
   313 
   314 lemma ballI [intro!]: "(!!x. x:A ==> P x) ==> ALL x:A. P x"
   315   by (simp add: Ball_def)
   316 
   317 lemmas strip = impI allI ballI
   318 
   319 lemma bspec [dest?]: "ALL x:A. P x ==> x:A ==> P x"
   320   by (simp add: Ball_def)
   321 
   322 lemma ballE [elim]: "ALL x:A. P x ==> (P x ==> Q) ==> (x ~: A ==> Q) ==> Q"
   323   by (unfold Ball_def) blast
   324 
   325 ML {* bind_thm ("rev_ballE", Thm.permute_prems 1 1 @{thm ballE}) *}
   326 
   327 text {*
   328   \medskip This tactic takes assumptions @{prop "ALL x:A. P x"} and
   329   @{prop "a:A"}; creates assumption @{prop "P a"}.
   330 *}
   331 
   332 ML {*
   333   fun ball_tac i = etac @{thm ballE} i THEN contr_tac (i + 1)
   334 *}
   335 
   336 text {*
   337   Gives better instantiation for bound:
   338 *}
   339 
   340 declaration {* fn _ =>
   341   Classical.map_cs (fn cs => cs addbefore ("bspec", datac @{thm bspec} 1))
   342 *}
   343 
   344 lemma bexI [intro]: "P x ==> x:A ==> EX x:A. P x"
   345   -- {* Normally the best argument order: @{prop "P x"} constrains the
   346     choice of @{prop "x:A"}. *}
   347   by (unfold Bex_def) blast
   348 
   349 lemma rev_bexI [intro?]: "x:A ==> P x ==> EX x:A. P x"
   350   -- {* The best argument order when there is only one @{prop "x:A"}. *}
   351   by (unfold Bex_def) blast
   352 
   353 lemma bexCI: "(ALL x:A. ~P x ==> P a) ==> a:A ==> EX x:A. P x"
   354   by (unfold Bex_def) blast
   355 
   356 lemma bexE [elim!]: "EX x:A. P x ==> (!!x. x:A ==> P x ==> Q) ==> Q"
   357   by (unfold Bex_def) blast
   358 
   359 lemma ball_triv [simp]: "(ALL x:A. P) = ((EX x. x:A) --> P)"
   360   -- {* Trival rewrite rule. *}
   361   by (simp add: Ball_def)
   362 
   363 lemma bex_triv [simp]: "(EX x:A. P) = ((EX x. x:A) & P)"
   364   -- {* Dual form for existentials. *}
   365   by (simp add: Bex_def)
   366 
   367 lemma bex_triv_one_point1 [simp]: "(EX x:A. x = a) = (a:A)"
   368   by blast
   369 
   370 lemma bex_triv_one_point2 [simp]: "(EX x:A. a = x) = (a:A)"
   371   by blast
   372 
   373 lemma bex_one_point1 [simp]: "(EX x:A. x = a & P x) = (a:A & P a)"
   374   by blast
   375 
   376 lemma bex_one_point2 [simp]: "(EX x:A. a = x & P x) = (a:A & P a)"
   377   by blast
   378 
   379 lemma ball_one_point1 [simp]: "(ALL x:A. x = a --> P x) = (a:A --> P a)"
   380   by blast
   381 
   382 lemma ball_one_point2 [simp]: "(ALL x:A. a = x --> P x) = (a:A --> P a)"
   383   by blast
   384 
   385 ML {*
   386   local
   387     val unfold_bex_tac = unfold_tac @{thms "Bex_def"};
   388     fun prove_bex_tac ss = unfold_bex_tac ss THEN Quantifier1.prove_one_point_ex_tac;
   389     val rearrange_bex = Quantifier1.rearrange_bex prove_bex_tac;
   390 
   391     val unfold_ball_tac = unfold_tac @{thms "Ball_def"};
   392     fun prove_ball_tac ss = unfold_ball_tac ss THEN Quantifier1.prove_one_point_all_tac;
   393     val rearrange_ball = Quantifier1.rearrange_ball prove_ball_tac;
   394   in
   395     val defBEX_regroup = Simplifier.simproc @{theory}
   396       "defined BEX" ["EX x:A. P x & Q x"] rearrange_bex;
   397     val defBALL_regroup = Simplifier.simproc @{theory}
   398       "defined BALL" ["ALL x:A. P x --> Q x"] rearrange_ball;
   399   end;
   400 
   401   Addsimprocs [defBALL_regroup, defBEX_regroup];
   402 *}
   403 
   404 text {* Congruence rules *}
   405 
   406 lemma ball_cong:
   407   "A = B ==> (!!x. x:B ==> P x = Q x) ==>
   408     (ALL x:A. P x) = (ALL x:B. Q x)"
   409   by (simp add: Ball_def)
   410 
   411 lemma strong_ball_cong [cong]:
   412   "A = B ==> (!!x. x:B =simp=> P x = Q x) ==>
   413     (ALL x:A. P x) = (ALL x:B. Q x)"
   414   by (simp add: simp_implies_def Ball_def)
   415 
   416 lemma bex_cong:
   417   "A = B ==> (!!x. x:B ==> P x = Q x) ==>
   418     (EX x:A. P x) = (EX x:B. Q x)"
   419   by (simp add: Bex_def cong: conj_cong)
   420 
   421 lemma strong_bex_cong [cong]:
   422   "A = B ==> (!!x. x:B =simp=> P x = Q x) ==>
   423     (EX x:A. P x) = (EX x:B. Q x)"
   424   by (simp add: simp_implies_def Bex_def cong: conj_cong)
   425 
   426 
   427 subsection {* Basic operations *}
   428 
   429 subsubsection {* Subsets *}
   430 
   431 lemma subsetI [atp,intro!]: "(!!x. x:A ==> x:B) ==> A \<subseteq> B"
   432   by (auto simp add: mem_def intro: predicate1I)
   433 
   434 text {*
   435   \medskip Map the type @{text "'a set => anything"} to just @{typ
   436   'a}; for overloading constants whose first argument has type @{typ
   437   "'a set"}.
   438 *}
   439 
   440 lemma subsetD [elim, intro?]: "A \<subseteq> B ==> c \<in> A ==> c \<in> B"
   441   -- {* Rule in Modus Ponens style. *}
   442   by (unfold mem_def) blast
   443 
   444 lemma rev_subsetD [intro?]: "c \<in> A ==> A \<subseteq> B ==> c \<in> B"
   445   -- {* The same, with reversed premises for use with @{text erule} --
   446       cf @{text rev_mp}. *}
   447   by (rule subsetD)
   448 
   449 text {*
   450   \medskip Converts @{prop "A \<subseteq> B"} to @{prop "x \<in> A ==> x \<in> B"}.
   451 *}
   452 
   453 ML {*
   454   fun impOfSubs th = th RSN (2, @{thm rev_subsetD})
   455 *}
   456 
   457 lemma subsetCE [elim]: "A \<subseteq>  B ==> (c \<notin> A ==> P) ==> (c \<in> B ==> P) ==> P"
   458   -- {* Classical elimination rule. *}
   459   by (unfold mem_def) blast
   460 
   461 lemma subset_eq: "A \<le> B = (\<forall>x\<in>A. x \<in> B)" by blast
   462 
   463 text {*
   464   \medskip Takes assumptions @{prop "A \<subseteq> B"}; @{prop "c \<in> A"} and
   465   creates the assumption @{prop "c \<in> B"}.
   466 *}
   467 
   468 ML {*
   469   fun set_mp_tac i = etac @{thm subsetCE} i THEN mp_tac i
   470 *}
   471 
   472 lemma contra_subsetD: "A \<subseteq> B ==> c \<notin> B ==> c \<notin> A"
   473   by blast
   474 
   475 lemma subset_refl [simp,atp]: "A \<subseteq> A"
   476   by (fact order_refl)
   477 
   478 lemma subset_trans: "A \<subseteq> B ==> B \<subseteq> C ==> A \<subseteq> C"
   479   by (fact order_trans)
   480 
   481 lemma set_rev_mp: "x:A ==> A \<subseteq> B ==> x:B"
   482   by (rule subsetD)
   483 
   484 lemma set_mp: "A \<subseteq> B ==> x:A ==> x:B"
   485   by (rule subsetD)
   486 
   487 lemmas basic_trans_rules [trans] =
   488   order_trans_rules set_rev_mp set_mp
   489 
   490 
   491 subsubsection {* Equality *}
   492 
   493 lemma set_ext: assumes prem: "(!!x. (x:A) = (x:B))" shows "A = B"
   494   apply (rule prem [THEN ext, THEN arg_cong, THEN box_equals])
   495    apply (rule Collect_mem_eq)
   496   apply (rule Collect_mem_eq)
   497   done
   498 
   499 (* Due to Brian Huffman *)
   500 lemma expand_set_eq: "(A = B) = (ALL x. (x:A) = (x:B))"
   501 by(auto intro:set_ext)
   502 
   503 lemma subset_antisym [intro!]: "A \<subseteq> B ==> B \<subseteq> A ==> A = B"
   504   -- {* Anti-symmetry of the subset relation. *}
   505   by (iprover intro: set_ext subsetD)
   506 
   507 text {*
   508   \medskip Equality rules from ZF set theory -- are they appropriate
   509   here?
   510 *}
   511 
   512 lemma equalityD1: "A = B ==> A \<subseteq> B"
   513   by (simp add: subset_refl)
   514 
   515 lemma equalityD2: "A = B ==> B \<subseteq> A"
   516   by (simp add: subset_refl)
   517 
   518 text {*
   519   \medskip Be careful when adding this to the claset as @{text
   520   subset_empty} is in the simpset: @{prop "A = {}"} goes to @{prop "{}
   521   \<subseteq> A"} and @{prop "A \<subseteq> {}"} and then back to @{prop "A = {}"}!
   522 *}
   523 
   524 lemma equalityE: "A = B ==> (A \<subseteq> B ==> B \<subseteq> A ==> P) ==> P"
   525   by (simp add: subset_refl)
   526 
   527 lemma equalityCE [elim]:
   528     "A = B ==> (c \<in> A ==> c \<in> B ==> P) ==> (c \<notin> A ==> c \<notin> B ==> P) ==> P"
   529   by blast
   530 
   531 lemma eqset_imp_iff: "A = B ==> (x : A) = (x : B)"
   532   by simp
   533 
   534 lemma eqelem_imp_iff: "x = y ==> (x : A) = (y : A)"
   535   by simp
   536 
   537 
   538 subsubsection {* The universal set -- UNIV *}
   539 
   540 definition UNIV :: "'a set" where
   541   "UNIV \<equiv> {x. True}"
   542 
   543 lemma UNIV_I [simp]: "x : UNIV"
   544   by (simp add: UNIV_def)
   545 
   546 declare UNIV_I [intro]  -- {* unsafe makes it less likely to cause problems *}
   547 
   548 lemma UNIV_witness [intro?]: "EX x. x : UNIV"
   549   by simp
   550 
   551 lemma subset_UNIV [simp]: "A \<subseteq> UNIV"
   552   by (rule subsetI) (rule UNIV_I)
   553 
   554 lemma top_set_eq: "top = UNIV"
   555   by (iprover intro!: subset_antisym subset_UNIV top_greatest)
   556 
   557 text {*
   558   \medskip Eta-contracting these two rules (to remove @{text P})
   559   causes them to be ignored because of their interaction with
   560   congruence rules.
   561 *}
   562 
   563 lemma ball_UNIV [simp]: "Ball UNIV P = All P"
   564   by (simp add: Ball_def)
   565 
   566 lemma bex_UNIV [simp]: "Bex UNIV P = Ex P"
   567   by (simp add: Bex_def)
   568 
   569 lemma UNIV_eq_I: "(\<And>x. x \<in> A) \<Longrightarrow> UNIV = A"
   570   by auto
   571 
   572 
   573 subsubsection {* The empty set *}
   574 
   575 lemma empty_iff [simp]: "(c : {}) = False"
   576   by (simp add: empty_def)
   577 
   578 lemma emptyE [elim!]: "a : {} ==> P"
   579   by simp
   580 
   581 lemma empty_subsetI [iff]: "{} \<subseteq> A"
   582     -- {* One effect is to delete the ASSUMPTION @{prop "{} <= A"} *}
   583   by blast
   584 
   585 lemma bot_set_eq: "bot = {}"
   586   by (iprover intro!: subset_antisym empty_subsetI bot_least)
   587 
   588 lemma equals0I: "(!!y. y \<in> A ==> False) ==> A = {}"
   589   by blast
   590 
   591 lemma equals0D: "A = {} ==> a \<notin> A"
   592     -- {* Use for reasoning about disjointness: @{prop "A Int B = {}"} *}
   593   by blast
   594 
   595 lemma ball_empty [simp]: "Ball {} P = True"
   596   by (simp add: Ball_def)
   597 
   598 lemma bex_empty [simp]: "Bex {} P = False"
   599   by (simp add: Bex_def)
   600 
   601 lemma UNIV_not_empty [iff]: "UNIV ~= {}"
   602   by (blast elim: equalityE)
   603 
   604 
   605 subsubsection {* The Powerset operator -- Pow *}
   606 
   607 definition Pow :: "'a set => 'a set set" where
   608   Pow_def: "Pow A = {B. B \<le> A}"
   609 
   610 lemma Pow_iff [iff]: "(A \<in> Pow B) = (A \<subseteq> B)"
   611   by (simp add: Pow_def)
   612 
   613 lemma PowI: "A \<subseteq> B ==> A \<in> Pow B"
   614   by (simp add: Pow_def)
   615 
   616 lemma PowD: "A \<in> Pow B ==> A \<subseteq> B"
   617   by (simp add: Pow_def)
   618 
   619 lemma Pow_bottom: "{} \<in> Pow B"
   620   by simp
   621 
   622 lemma Pow_top: "A \<in> Pow A"
   623   by (simp add: subset_refl)
   624 
   625 
   626 subsubsection {* Set complement *}
   627 
   628 lemma Compl_iff [simp]: "(c \<in> -A) = (c \<notin> A)"
   629   by (simp add: mem_def fun_Compl_def bool_Compl_def)
   630 
   631 lemma ComplI [intro!]: "(c \<in> A ==> False) ==> c \<in> -A"
   632   by (unfold mem_def fun_Compl_def bool_Compl_def) blast
   633 
   634 text {*
   635   \medskip This form, with negated conclusion, works well with the
   636   Classical prover.  Negated assumptions behave like formulae on the
   637   right side of the notional turnstile ... *}
   638 
   639 lemma ComplD [dest!]: "c : -A ==> c~:A"
   640   by (simp add: mem_def fun_Compl_def bool_Compl_def)
   641 
   642 lemmas ComplE = ComplD [elim_format]
   643 
   644 lemma Compl_eq: "- A = {x. ~ x : A}" by blast
   645 
   646 
   647 subsubsection {* Binary union -- Un *}
   648 
   649 definition Un :: "'a set \<Rightarrow> 'a set \<Rightarrow> 'a set" (infixl "Un" 65) where
   650   "A Un B \<equiv> {x. x \<in> A \<or> x \<in> B}"
   651 
   652 notation (xsymbols)
   653   "Un"  (infixl "\<union>" 65)
   654 
   655 notation (HTML output)
   656   "Un"  (infixl "\<union>" 65)
   657 
   658 lemma sup_set_eq: "sup A B = A \<union> B"
   659   by (simp add: sup_fun_eq sup_bool_eq Un_def Collect_def mem_def)
   660 
   661 lemma Un_iff [simp]: "(c : A Un B) = (c:A | c:B)"
   662   by (unfold Un_def) blast
   663 
   664 lemma UnI1 [elim?]: "c:A ==> c : A Un B"
   665   by simp
   666 
   667 lemma UnI2 [elim?]: "c:B ==> c : A Un B"
   668   by simp
   669 
   670 text {*
   671   \medskip Classical introduction rule: no commitment to @{prop A} vs
   672   @{prop B}.
   673 *}
   674 
   675 lemma UnCI [intro!]: "(c~:B ==> c:A) ==> c : A Un B"
   676   by auto
   677 
   678 lemma UnE [elim!]: "c : A Un B ==> (c:A ==> P) ==> (c:B ==> P) ==> P"
   679   by (unfold Un_def) blast
   680 
   681 lemma insert_def: "insert a B \<equiv> {x. x = a} \<union> B"
   682   by (simp add: Collect_def mem_def insert_compr Un_def)
   683 
   684 lemma mono_Un: "mono f \<Longrightarrow> f A \<union> f B \<subseteq> f (A \<union> B)"
   685   apply (fold sup_set_eq)
   686   apply (erule mono_sup)
   687   done
   688 
   689 
   690 subsubsection {* Binary intersection -- Int *}
   691 
   692 definition Int :: "'a set \<Rightarrow> 'a set \<Rightarrow> 'a set" (infixl "Int" 70) where
   693   "A Int B \<equiv> {x. x \<in> A \<and> x \<in> B}"
   694 
   695 notation (xsymbols)
   696   "Int"  (infixl "\<inter>" 70)
   697 
   698 notation (HTML output)
   699   "Int"  (infixl "\<inter>" 70)
   700 
   701 lemma inf_set_eq: "inf A B = A \<inter> B"
   702   by (simp add: inf_fun_eq inf_bool_eq Int_def Collect_def mem_def)
   703 
   704 lemma Int_iff [simp]: "(c : A Int B) = (c:A & c:B)"
   705   by (unfold Int_def) blast
   706 
   707 lemma IntI [intro!]: "c:A ==> c:B ==> c : A Int B"
   708   by simp
   709 
   710 lemma IntD1: "c : A Int B ==> c:A"
   711   by simp
   712 
   713 lemma IntD2: "c : A Int B ==> c:B"
   714   by simp
   715 
   716 lemma IntE [elim!]: "c : A Int B ==> (c:A ==> c:B ==> P) ==> P"
   717   by simp
   718 
   719 lemma mono_Int: "mono f \<Longrightarrow> f (A \<inter> B) \<subseteq> f A \<inter> f B"
   720   apply (fold inf_set_eq)
   721   apply (erule mono_inf)
   722   done
   723 
   724 
   725 subsubsection {* Set difference *}
   726 
   727 lemma Diff_iff [simp]: "(c : A - B) = (c:A & c~:B)"
   728   by (simp add: mem_def fun_diff_def bool_diff_def)
   729 
   730 lemma DiffI [intro!]: "c : A ==> c ~: B ==> c : A - B"
   731   by simp
   732 
   733 lemma DiffD1: "c : A - B ==> c : A"
   734   by simp
   735 
   736 lemma DiffD2: "c : A - B ==> c : B ==> P"
   737   by simp
   738 
   739 lemma DiffE [elim!]: "c : A - B ==> (c:A ==> c~:B ==> P) ==> P"
   740   by simp
   741 
   742 lemma set_diff_eq: "A - B = {x. x : A & ~ x : B}" by blast
   743 
   744 lemma Compl_eq_Diff_UNIV: "-A = (UNIV - A)"
   745 by blast
   746 
   747 
   748 subsubsection {* Augmenting a set -- @{const insert} *}
   749 
   750 lemma insert_iff [simp]: "(a : insert b A) = (a = b | a:A)"
   751   by (unfold insert_def) blast
   752 
   753 lemma insertI1: "a : insert a B"
   754   by simp
   755 
   756 lemma insertI2: "a : B ==> a : insert b B"
   757   by simp
   758 
   759 lemma insertE [elim!]: "a : insert b A ==> (a = b ==> P) ==> (a:A ==> P) ==> P"
   760   by (unfold insert_def) blast
   761 
   762 lemma insertCI [intro!]: "(a~:B ==> a = b) ==> a: insert b B"
   763   -- {* Classical introduction rule. *}
   764   by auto
   765 
   766 lemma subset_insert_iff: "(A \<subseteq> insert x B) = (if x:A then A - {x} \<subseteq> B else A \<subseteq> B)"
   767   by auto
   768 
   769 lemma set_insert:
   770   assumes "x \<in> A"
   771   obtains B where "A = insert x B" and "x \<notin> B"
   772 proof
   773   from assms show "A = insert x (A - {x})" by blast
   774 next
   775   show "x \<notin> A - {x}" by blast
   776 qed
   777 
   778 lemma insert_ident: "x ~: A ==> x ~: B ==> (insert x A = insert x B) = (A = B)"
   779 by auto
   780 
   781 subsubsection {* Singletons, using insert *}
   782 
   783 lemma singletonI [intro!,noatp]: "a : {a}"
   784     -- {* Redundant? But unlike @{text insertCI}, it proves the subgoal immediately! *}
   785   by (rule insertI1)
   786 
   787 lemma singletonD [dest!,noatp]: "b : {a} ==> b = a"
   788   by blast
   789 
   790 lemmas singletonE = singletonD [elim_format]
   791 
   792 lemma singleton_iff: "(b : {a}) = (b = a)"
   793   by blast
   794 
   795 lemma singleton_inject [dest!]: "{a} = {b} ==> a = b"
   796   by blast
   797 
   798 lemma singleton_insert_inj_eq [iff,noatp]:
   799      "({b} = insert a A) = (a = b & A \<subseteq> {b})"
   800   by blast
   801 
   802 lemma singleton_insert_inj_eq' [iff,noatp]:
   803      "(insert a A = {b}) = (a = b & A \<subseteq> {b})"
   804   by blast
   805 
   806 lemma subset_singletonD: "A \<subseteq> {x} ==> A = {} | A = {x}"
   807   by fast
   808 
   809 lemma singleton_conv [simp]: "{x. x = a} = {a}"
   810   by blast
   811 
   812 lemma singleton_conv2 [simp]: "{x. a = x} = {a}"
   813   by blast
   814 
   815 lemma diff_single_insert: "A - {x} \<subseteq> B ==> x \<in> A ==> A \<subseteq> insert x B"
   816   by blast
   817 
   818 lemma doubleton_eq_iff: "({a,b} = {c,d}) = (a=c & b=d | a=d & b=c)"
   819   by (blast elim: equalityE)
   820 
   821 
   822 subsubsection {* Image of a set under a function *}
   823 
   824 text {*
   825   Frequently @{term b} does not have the syntactic form of @{term "f x"}.
   826 *}
   827 
   828 definition image :: "('a => 'b) => 'a set => 'b set" (infixr "`" 90) where
   829   image_def [noatp]: "f ` A = {y. EX x:A. y = f(x)}"
   830 
   831 abbreviation
   832   range :: "('a => 'b) => 'b set" where -- "of function"
   833   "range f == f ` UNIV"
   834 
   835 lemma image_eqI [simp, intro]: "b = f x ==> x:A ==> b : f`A"
   836   by (unfold image_def) blast
   837 
   838 lemma imageI: "x : A ==> f x : f ` A"
   839   by (rule image_eqI) (rule refl)
   840 
   841 lemma rev_image_eqI: "x:A ==> b = f x ==> b : f`A"
   842   -- {* This version's more effective when we already have the
   843     required @{term x}. *}
   844   by (unfold image_def) blast
   845 
   846 lemma imageE [elim!]:
   847   "b : (%x. f x)`A ==> (!!x. b = f x ==> x:A ==> P) ==> P"
   848   -- {* The eta-expansion gives variable-name preservation. *}
   849   by (unfold image_def) blast
   850 
   851 lemma image_Un: "f`(A Un B) = f`A Un f`B"
   852   by blast
   853 
   854 lemma image_iff: "(z : f`A) = (EX x:A. z = f x)"
   855   by blast
   856 
   857 lemma image_subset_iff: "(f`A \<subseteq> B) = (\<forall>x\<in>A. f x \<in> B)"
   858   -- {* This rewrite rule would confuse users if made default. *}
   859   by blast
   860 
   861 lemma subset_image_iff: "(B \<subseteq> f`A) = (EX AA. AA \<subseteq> A & B = f`AA)"
   862   apply safe
   863    prefer 2 apply fast
   864   apply (rule_tac x = "{a. a : A & f a : B}" in exI, fast)
   865   done
   866 
   867 lemma image_subsetI: "(!!x. x \<in> A ==> f x \<in> B) ==> f`A \<subseteq> B"
   868   -- {* Replaces the three steps @{text subsetI}, @{text imageE},
   869     @{text hypsubst}, but breaks too many existing proofs. *}
   870   by blast
   871 
   872 text {*
   873   \medskip Range of a function -- just a translation for image!
   874 *}
   875 
   876 lemma range_eqI: "b = f x ==> b \<in> range f"
   877   by simp
   878 
   879 lemma rangeI: "f x \<in> range f"
   880   by simp
   881 
   882 lemma rangeE [elim?]: "b \<in> range (\<lambda>x. f x) ==> (!!x. b = f x ==> P) ==> P"
   883   by blast
   884 
   885 
   886 subsubsection {* Some proof tools *}
   887 
   888 text{* Elimination of @{text"{x. \<dots> & x=t & \<dots>}"}. *}
   889 
   890 lemma Collect_conv_if: "{x. x=a & P x} = (if P a then {a} else {})"
   891 by auto
   892 
   893 lemma Collect_conv_if2: "{x. a=x & P x} = (if P a then {a} else {})"
   894 by auto
   895 
   896 text {*
   897 Simproc for pulling @{text "x=t"} in @{text "{x. \<dots> & x=t & \<dots>}"}
   898 to the front (and similarly for @{text "t=x"}):
   899 *}
   900 
   901 ML{*
   902   local
   903     val Coll_perm_tac = rtac @{thm Collect_cong} 1 THEN rtac @{thm iffI} 1 THEN
   904     ALLGOALS(EVERY'[REPEAT_DETERM o (etac @{thm conjE}),
   905                     DEPTH_SOLVE_1 o (ares_tac [@{thm conjI}])])
   906   in
   907     val defColl_regroup = Simplifier.simproc @{theory}
   908       "defined Collect" ["{x. P x & Q x}"]
   909       (Quantifier1.rearrange_Coll Coll_perm_tac)
   910   end;
   911 
   912   Addsimprocs [defColl_regroup];
   913 *}
   914 
   915 text {*
   916   Rewrite rules for boolean case-splitting: faster than @{text
   917   "split_if [split]"}.
   918 *}
   919 
   920 lemma split_if_eq1: "((if Q then x else y) = b) = ((Q --> x = b) & (~ Q --> y = b))"
   921   by (rule split_if)
   922 
   923 lemma split_if_eq2: "(a = (if Q then x else y)) = ((Q --> a = x) & (~ Q --> a = y))"
   924   by (rule split_if)
   925 
   926 text {*
   927   Split ifs on either side of the membership relation.  Not for @{text
   928   "[simp]"} -- can cause goals to blow up!
   929 *}
   930 
   931 lemma split_if_mem1: "((if Q then x else y) : b) = ((Q --> x : b) & (~ Q --> y : b))"
   932   by (rule split_if)
   933 
   934 lemma split_if_mem2: "(a : (if Q then x else y)) = ((Q --> a : x) & (~ Q --> a : y))"
   935   by (rule split_if [where P="%S. a : S"])
   936 
   937 lemmas split_ifs = if_bool_eq_conj split_if_eq1 split_if_eq2 split_if_mem1 split_if_mem2
   938 
   939 (*Would like to add these, but the existing code only searches for the
   940   outer-level constant, which in this case is just "op :"; we instead need
   941   to use term-nets to associate patterns with rules.  Also, if a rule fails to
   942   apply, then the formula should be kept.
   943   [("HOL.uminus", Compl_iff RS iffD1), ("HOL.minus", [Diff_iff RS iffD1]),
   944    ("Int", [IntD1,IntD2]),
   945    ("Collect", [CollectD]), ("Inter", [InterD]), ("INTER", [INT_D])]
   946  *)
   947 
   948 ML {*
   949   val mksimps_pairs = [(@{const_name Ball}, @{thms bspec})] @ mksimps_pairs;
   950 *}
   951 declaration {* fn _ =>
   952   Simplifier.map_ss (fn ss => ss setmksimps (mksimps mksimps_pairs))
   953 *}
   954 
   955 
   956 subsection {* Complete lattices *}
   957 
   958 notation
   959   less_eq  (infix "\<sqsubseteq>" 50) and
   960   less (infix "\<sqsubset>" 50) and
   961   inf  (infixl "\<sqinter>" 70) and
   962   sup  (infixl "\<squnion>" 65)
   963 
   964 class complete_lattice = lattice + bot + top +
   965   fixes Inf :: "'a set \<Rightarrow> 'a" ("\<Sqinter>_" [900] 900)
   966     and Sup :: "'a set \<Rightarrow> 'a" ("\<Squnion>_" [900] 900)
   967   assumes Inf_lower: "x \<in> A \<Longrightarrow> \<Sqinter>A \<sqsubseteq> x"
   968      and Inf_greatest: "(\<And>x. x \<in> A \<Longrightarrow> z \<sqsubseteq> x) \<Longrightarrow> z \<sqsubseteq> \<Sqinter>A"
   969   assumes Sup_upper: "x \<in> A \<Longrightarrow> x \<sqsubseteq> \<Squnion>A"
   970      and Sup_least: "(\<And>x. x \<in> A \<Longrightarrow> x \<sqsubseteq> z) \<Longrightarrow> \<Squnion>A \<sqsubseteq> z"
   971 begin
   972 
   973 lemma Inf_Sup: "\<Sqinter>A = \<Squnion>{b. \<forall>a \<in> A. b \<le> a}"
   974   by (auto intro: antisym Inf_lower Inf_greatest Sup_upper Sup_least)
   975 
   976 lemma Sup_Inf:  "\<Squnion>A = \<Sqinter>{b. \<forall>a \<in> A. a \<le> b}"
   977   by (auto intro: antisym Inf_lower Inf_greatest Sup_upper Sup_least)
   978 
   979 lemma Inf_Univ: "\<Sqinter>UNIV = \<Squnion>{}"
   980   unfolding Sup_Inf by (auto simp add: UNIV_def)
   981 
   982 lemma Sup_Univ: "\<Squnion>UNIV = \<Sqinter>{}"
   983   unfolding Inf_Sup by (auto simp add: UNIV_def)
   984 
   985 lemma Inf_insert: "\<Sqinter>insert a A = a \<sqinter> \<Sqinter>A"
   986   by (auto intro: le_infI le_infI1 le_infI2 antisym Inf_greatest Inf_lower)
   987 
   988 lemma Sup_insert: "\<Squnion>insert a A = a \<squnion> \<Squnion>A"
   989   by (auto intro: le_supI le_supI1 le_supI2 antisym Sup_least Sup_upper)
   990 
   991 lemma Inf_singleton [simp]:
   992   "\<Sqinter>{a} = a"
   993   by (auto intro: antisym Inf_lower Inf_greatest)
   994 
   995 lemma Sup_singleton [simp]:
   996   "\<Squnion>{a} = a"
   997   by (auto intro: antisym Sup_upper Sup_least)
   998 
   999 lemma Inf_insert_simp:
  1000   "\<Sqinter>insert a A = (if A = {} then a else a \<sqinter> \<Sqinter>A)"
  1001   by (cases "A = {}") (simp_all, simp add: Inf_insert)
  1002 
  1003 lemma Sup_insert_simp:
  1004   "\<Squnion>insert a A = (if A = {} then a else a \<squnion> \<Squnion>A)"
  1005   by (cases "A = {}") (simp_all, simp add: Sup_insert)
  1006 
  1007 lemma Inf_binary:
  1008   "\<Sqinter>{a, b} = a \<sqinter> b"
  1009   by (auto simp add: Inf_insert_simp)
  1010 
  1011 lemma Sup_binary:
  1012   "\<Squnion>{a, b} = a \<squnion> b"
  1013   by (auto simp add: Sup_insert_simp)
  1014 
  1015 lemma bot_def:
  1016   "bot = \<Squnion>{}"
  1017   by (auto intro: antisym Sup_least)
  1018 
  1019 lemma top_def:
  1020   "top = \<Sqinter>{}"
  1021   by (auto intro: antisym Inf_greatest)
  1022 
  1023 lemma sup_bot [simp]:
  1024   "x \<squnion> bot = x"
  1025   using bot_least [of x] by (simp add: le_iff_sup sup_commute)
  1026 
  1027 lemma inf_top [simp]:
  1028   "x \<sqinter> top = x"
  1029   using top_greatest [of x] by (simp add: le_iff_inf inf_commute)
  1030 
  1031 definition SUPR :: "'b set \<Rightarrow> ('b \<Rightarrow> 'a) \<Rightarrow> 'a" where
  1032   "SUPR A f == \<Squnion> (f ` A)"
  1033 
  1034 definition INFI :: "'b set \<Rightarrow> ('b \<Rightarrow> 'a) \<Rightarrow> 'a" where
  1035   "INFI A f == \<Sqinter> (f ` A)"
  1036 
  1037 end
  1038 
  1039 syntax
  1040   "_SUP1"     :: "pttrns => 'b => 'b"           ("(3SUP _./ _)" [0, 10] 10)
  1041   "_SUP"      :: "pttrn => 'a set => 'b => 'b"  ("(3SUP _:_./ _)" [0, 10] 10)
  1042   "_INF1"     :: "pttrns => 'b => 'b"           ("(3INF _./ _)" [0, 10] 10)
  1043   "_INF"      :: "pttrn => 'a set => 'b => 'b"  ("(3INF _:_./ _)" [0, 10] 10)
  1044 
  1045 translations
  1046   "SUP x y. B"   == "SUP x. SUP y. B"
  1047   "SUP x. B"     == "CONST SUPR CONST UNIV (%x. B)"
  1048   "SUP x. B"     == "SUP x:CONST UNIV. B"
  1049   "SUP x:A. B"   == "CONST SUPR A (%x. B)"
  1050   "INF x y. B"   == "INF x. INF y. B"
  1051   "INF x. B"     == "CONST INFI CONST UNIV (%x. B)"
  1052   "INF x. B"     == "INF x:CONST UNIV. B"
  1053   "INF x:A. B"   == "CONST INFI A (%x. B)"
  1054 
  1055 (* To avoid eta-contraction of body: *)
  1056 print_translation {*
  1057 let
  1058   fun btr' syn (A :: Abs abs :: ts) =
  1059     let val (x,t) = atomic_abs_tr' abs
  1060     in list_comb (Syntax.const syn $ x $ A $ t, ts) end
  1061   val const_syntax_name = Sign.const_syntax_name @{theory} o fst o dest_Const
  1062 in
  1063 [(const_syntax_name @{term SUPR}, btr' "_SUP"),(const_syntax_name @{term "INFI"}, btr' "_INF")]
  1064 end
  1065 *}
  1066 
  1067 context complete_lattice
  1068 begin
  1069 
  1070 lemma le_SUPI: "i : A \<Longrightarrow> M i \<le> (SUP i:A. M i)"
  1071   by (auto simp add: SUPR_def intro: Sup_upper)
  1072 
  1073 lemma SUP_leI: "(\<And>i. i : A \<Longrightarrow> M i \<le> u) \<Longrightarrow> (SUP i:A. M i) \<le> u"
  1074   by (auto simp add: SUPR_def intro: Sup_least)
  1075 
  1076 lemma INF_leI: "i : A \<Longrightarrow> (INF i:A. M i) \<le> M i"
  1077   by (auto simp add: INFI_def intro: Inf_lower)
  1078 
  1079 lemma le_INFI: "(\<And>i. i : A \<Longrightarrow> u \<le> M i) \<Longrightarrow> u \<le> (INF i:A. M i)"
  1080   by (auto simp add: INFI_def intro: Inf_greatest)
  1081 
  1082 lemma SUP_const[simp]: "A \<noteq> {} \<Longrightarrow> (SUP i:A. M) = M"
  1083   by (auto intro: antisym SUP_leI le_SUPI)
  1084 
  1085 lemma INF_const[simp]: "A \<noteq> {} \<Longrightarrow> (INF i:A. M) = M"
  1086   by (auto intro: antisym INF_leI le_INFI)
  1087 
  1088 end
  1089 
  1090 
  1091 subsubsection {* @{typ bool} and @{typ "_ \<Rightarrow> _"} as complete lattice *}
  1092 
  1093 instantiation bool :: complete_lattice
  1094 begin
  1095 
  1096 definition
  1097   Inf_bool_def: "\<Sqinter>A \<longleftrightarrow> (\<forall>x\<in>A. x)"
  1098 
  1099 definition
  1100   Sup_bool_def: "\<Squnion>A \<longleftrightarrow> (\<exists>x\<in>A. x)"
  1101 
  1102 instance proof
  1103 qed (auto simp add: Inf_bool_def Sup_bool_def le_bool_def)
  1104 
  1105 end
  1106 
  1107 lemma Inf_empty_bool [simp]:
  1108   "\<Sqinter>{}"
  1109   unfolding Inf_bool_def by auto
  1110 
  1111 lemma not_Sup_empty_bool [simp]:
  1112   "\<not> \<Squnion>{}"
  1113   unfolding Sup_bool_def by auto
  1114 
  1115 instantiation "fun" :: (type, complete_lattice) complete_lattice
  1116 begin
  1117 
  1118 definition
  1119   Inf_fun_def [code del]: "\<Sqinter>A = (\<lambda>x. \<Sqinter>{y. \<exists>f\<in>A. y = f x})"
  1120 
  1121 definition
  1122   Sup_fun_def [code del]: "\<Squnion>A = (\<lambda>x. \<Squnion>{y. \<exists>f\<in>A. y = f x})"
  1123 
  1124 instance proof
  1125 qed (auto simp add: Inf_fun_def Sup_fun_def le_fun_def
  1126   intro: Inf_lower Sup_upper Inf_greatest Sup_least)
  1127 
  1128 end
  1129 
  1130 lemma Inf_empty_fun:
  1131   "\<Sqinter>{} = (\<lambda>_. \<Sqinter>{})"
  1132   by rule (simp add: Inf_fun_def, simp add: empty_def)
  1133 
  1134 lemma Sup_empty_fun:
  1135   "\<Squnion>{} = (\<lambda>_. \<Squnion>{})"
  1136   by rule (simp add: Sup_fun_def, simp add: empty_def)
  1137 
  1138 
  1139 subsubsection {* Unions of families *}
  1140 
  1141 definition UNION :: "'a set \<Rightarrow> ('a \<Rightarrow> 'b set) \<Rightarrow> 'b set" where
  1142   "UNION A B \<equiv> {y. \<exists>x\<in>A. y \<in> B x}"
  1143 
  1144 syntax
  1145   "@UNION1"     :: "pttrns => 'b set => 'b set"           ("(3UN _./ _)" [0, 10] 10)
  1146   "@UNION"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3UN _:_./ _)" [0, 10] 10)
  1147 
  1148 syntax (xsymbols)
  1149   "@UNION1"     :: "pttrns => 'b set => 'b set"           ("(3\<Union>_./ _)" [0, 10] 10)
  1150   "@UNION"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3\<Union>_\<in>_./ _)" [0, 10] 10)
  1151 
  1152 syntax (latex output)
  1153   "@UNION1"     :: "pttrns => 'b set => 'b set"           ("(3\<Union>(00\<^bsub>_\<^esub>)/ _)" [0, 10] 10)
  1154   "@UNION"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3\<Union>(00\<^bsub>_\<in>_\<^esub>)/ _)" [0, 10] 10)
  1155 
  1156 translations
  1157   "UN x y. B"   == "UN x. UN y. B"
  1158   "UN x. B"     == "CONST UNION CONST UNIV (%x. B)"
  1159   "UN x. B"     == "UN x:CONST UNIV. B"
  1160   "UN x:A. B"   == "CONST UNION A (%x. B)"
  1161 
  1162 text {*
  1163   Note the difference between ordinary xsymbol syntax of indexed
  1164   unions and intersections (e.g.\ @{text"\<Union>a\<^isub>1\<in>A\<^isub>1. B"})
  1165   and their \LaTeX\ rendition: @{term"\<Union>a\<^isub>1\<in>A\<^isub>1. B"}. The
  1166   former does not make the index expression a subscript of the
  1167   union/intersection symbol because this leads to problems with nested
  1168   subscripts in Proof General.
  1169 *}
  1170 
  1171 (* To avoid eta-contraction of body: *)
  1172 print_translation {*
  1173 let
  1174   fun btr' syn [A, Abs abs] =
  1175     let val (x, t) = atomic_abs_tr' abs
  1176     in Syntax.const syn $ x $ A $ t end
  1177 in [(@{const_syntax UNION}, btr' "@UNION")] end
  1178 *}
  1179 
  1180 declare UNION_def [noatp]
  1181 
  1182 lemma UN_iff [simp]: "(b: (UN x:A. B x)) = (EX x:A. b: B x)"
  1183   by (unfold UNION_def) blast
  1184 
  1185 lemma UN_I [intro]: "a:A ==> b: B a ==> b: (UN x:A. B x)"
  1186   -- {* The order of the premises presupposes that @{term A} is rigid;
  1187     @{term b} may be flexible. *}
  1188   by auto
  1189 
  1190 lemma UN_E [elim!]: "b : (UN x:A. B x) ==> (!!x. x:A ==> b: B x ==> R) ==> R"
  1191   by (unfold UNION_def) blast
  1192 
  1193 lemma UN_cong [cong]:
  1194     "A = B ==> (!!x. x:B ==> C x = D x) ==> (UN x:A. C x) = (UN x:B. D x)"
  1195   by (simp add: UNION_def)
  1196 
  1197 lemma strong_UN_cong:
  1198     "A = B ==> (!!x. x:B =simp=> C x = D x) ==> (UN x:A. C x) = (UN x:B. D x)"
  1199   by (simp add: UNION_def simp_implies_def)
  1200 
  1201 lemma image_eq_UN: "f`A = (UN x:A. {f x})"
  1202   by blast
  1203 
  1204 
  1205 subsubsection {* Intersections of families *}
  1206 
  1207 definition INTER :: "'a set \<Rightarrow> ('a \<Rightarrow> 'b set) \<Rightarrow> 'b set" where
  1208   "INTER A B \<equiv> {y. \<forall>x\<in>A. y \<in> B x}"
  1209 
  1210 syntax
  1211   "@INTER1"     :: "pttrns => 'b set => 'b set"           ("(3INT _./ _)" [0, 10] 10)
  1212   "@INTER"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3INT _:_./ _)" [0, 10] 10)
  1213 
  1214 syntax (xsymbols)
  1215   "@INTER1"     :: "pttrns => 'b set => 'b set"           ("(3\<Inter>_./ _)" [0, 10] 10)
  1216   "@INTER"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3\<Inter>_\<in>_./ _)" [0, 10] 10)
  1217 
  1218 syntax (latex output)
  1219   "@INTER1"     :: "pttrns => 'b set => 'b set"           ("(3\<Inter>(00\<^bsub>_\<^esub>)/ _)" [0, 10] 10)
  1220   "@INTER"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3\<Inter>(00\<^bsub>_\<in>_\<^esub>)/ _)" [0, 10] 10)
  1221 
  1222 translations
  1223   "INT x y. B"  == "INT x. INT y. B"
  1224   "INT x. B"    == "CONST INTER CONST UNIV (%x. B)"
  1225   "INT x. B"    == "INT x:CONST UNIV. B"
  1226   "INT x:A. B"  == "CONST INTER A (%x. B)"
  1227 
  1228 (* To avoid eta-contraction of body: *)
  1229 print_translation {*
  1230 let
  1231   fun btr' syn [A, Abs abs] =
  1232     let val (x, t) = atomic_abs_tr' abs
  1233     in Syntax.const syn $ x $ A $ t end
  1234 in [(@{const_syntax INTER}, btr' "@INTER")] end
  1235 *}
  1236 
  1237 lemma INT_iff [simp]: "(b: (INT x:A. B x)) = (ALL x:A. b: B x)"
  1238   by (unfold INTER_def) blast
  1239 
  1240 lemma INT_I [intro!]: "(!!x. x:A ==> b: B x) ==> b : (INT x:A. B x)"
  1241   by (unfold INTER_def) blast
  1242 
  1243 lemma INT_D [elim]: "b : (INT x:A. B x) ==> a:A ==> b: B a"
  1244   by auto
  1245 
  1246 lemma INT_E [elim]: "b : (INT x:A. B x) ==> (b: B a ==> R) ==> (a~:A ==> R) ==> R"
  1247   -- {* "Classical" elimination -- by the Excluded Middle on @{prop "a:A"}. *}
  1248   by (unfold INTER_def) blast
  1249 
  1250 lemma INT_cong [cong]:
  1251     "A = B ==> (!!x. x:B ==> C x = D x) ==> (INT x:A. C x) = (INT x:B. D x)"
  1252   by (simp add: INTER_def)
  1253 
  1254 
  1255 subsubsection {* Union *}
  1256 
  1257 definition Union :: "'a set set \<Rightarrow> 'a set" where
  1258   "Union S \<equiv> UNION S (\<lambda>x. x)"
  1259 
  1260 notation (xsymbols)
  1261   Union  ("\<Union>_" [90] 90)
  1262 
  1263 lemma Union_image_eq [simp]:
  1264   "\<Union>(B`A) = (\<Union>x\<in>A. B x)"
  1265   by (auto simp add: Union_def UNION_def image_def)
  1266 
  1267 lemma Union_eq:
  1268   "\<Union>A = {x. \<exists>B \<in> A. x \<in> B}"
  1269   by (simp add: Union_def UNION_def)
  1270 
  1271 lemma Sup_set_eq:
  1272   "\<Squnion>S = \<Union>S"
  1273 proof (rule set_ext)
  1274   fix x
  1275   have "(\<exists>Q\<in>{P. \<exists>A\<in>S. P \<longleftrightarrow> x \<in> A}. Q) \<longleftrightarrow> (\<exists>A\<in>S. x \<in> A)"
  1276     by auto
  1277   then show "x \<in> \<Squnion>S \<longleftrightarrow> x \<in> \<Union>S"
  1278     by (simp add: Union_eq Sup_fun_def Sup_bool_def) (simp add: mem_def)
  1279 qed
  1280 
  1281 lemma SUPR_set_eq:
  1282   "(SUP x:S. f x) = (\<Union>x\<in>S. f x)"
  1283   by (simp add: SUPR_def Sup_set_eq)
  1284 
  1285 lemma Union_iff [simp,noatp]: "(A : Union C) = (EX X:C. A:X)"
  1286   by (unfold Union_def) blast
  1287 
  1288 lemma UnionI [intro]: "X:C ==> A:X ==> A : Union C"
  1289   -- {* The order of the premises presupposes that @{term C} is rigid;
  1290     @{term A} may be flexible. *}
  1291   by auto
  1292 
  1293 lemma UnionE [elim!]: "A : Union C ==> (!!X. A:X ==> X:C ==> R) ==> R"
  1294   by (unfold Union_def) blast
  1295 
  1296 
  1297 subsubsection {* Inter *}
  1298 
  1299 definition Inter :: "'a set set \<Rightarrow> 'a set" where
  1300   "Inter S \<equiv> INTER S (\<lambda>x. x)"
  1301 
  1302 notation (xsymbols)
  1303   Inter  ("\<Inter>_" [90] 90)
  1304 
  1305 lemma Inter_image_eq [simp]:
  1306   "\<Inter>(B`A) = (\<Inter>x\<in>A. B x)"
  1307   by (auto simp add: Inter_def INTER_def image_def)
  1308 
  1309 lemma Inter_eq:
  1310   "\<Inter>A = {x. \<forall>B \<in> A. x \<in> B}"
  1311   by (simp add: Inter_def INTER_def)
  1312 
  1313 lemma Inf_set_eq:
  1314   "\<Sqinter>S = \<Inter>S"
  1315 proof (rule set_ext)
  1316   fix x
  1317   have "(\<forall>Q\<in>{P. \<exists>A\<in>S. P \<longleftrightarrow> x \<in> A}. Q) \<longleftrightarrow> (\<forall>A\<in>S. x \<in> A)"
  1318     by auto
  1319   then show "x \<in> \<Sqinter>S \<longleftrightarrow> x \<in> \<Inter>S"
  1320     by (simp add: Inter_eq Inf_fun_def Inf_bool_def) (simp add: mem_def)
  1321 qed
  1322 
  1323 lemma INFI_set_eq:
  1324   "(INF x:S. f x) = (\<Inter>x\<in>S. f x)"
  1325   by (simp add: INFI_def Inf_set_eq)
  1326 
  1327 lemma Inter_iff [simp,noatp]: "(A : Inter C) = (ALL X:C. A:X)"
  1328   by (unfold Inter_def) blast
  1329 
  1330 lemma InterI [intro!]: "(!!X. X:C ==> A:X) ==> A : Inter C"
  1331   by (simp add: Inter_def)
  1332 
  1333 text {*
  1334   \medskip A ``destruct'' rule -- every @{term X} in @{term C}
  1335   contains @{term A} as an element, but @{prop "A:X"} can hold when
  1336   @{prop "X:C"} does not!  This rule is analogous to @{text spec}.
  1337 *}
  1338 
  1339 lemma InterD [elim]: "A : Inter C ==> X:C ==> A:X"
  1340   by auto
  1341 
  1342 lemma InterE [elim]: "A : Inter C ==> (X~:C ==> R) ==> (A:X ==> R) ==> R"
  1343   -- {* ``Classical'' elimination rule -- does not require proving
  1344     @{prop "X:C"}. *}
  1345   by (unfold Inter_def) blast
  1346 
  1347 
  1348 no_notation
  1349   less_eq  (infix "\<sqsubseteq>" 50) and
  1350   less (infix "\<sqsubset>" 50) and
  1351   inf  (infixl "\<sqinter>" 70) and
  1352   sup  (infixl "\<squnion>" 65) and
  1353   Inf  ("\<Sqinter>_" [900] 900) and
  1354   Sup  ("\<Squnion>_" [900] 900)
  1355 
  1356 
  1357 subsection {* Further operations and lemmas *}
  1358 
  1359 subsubsection {* The ``proper subset'' relation *}
  1360 
  1361 lemma psubsetI [intro!,noatp]: "A \<subseteq> B ==> A \<noteq> B ==> A \<subset> B"
  1362   by (unfold less_le) blast
  1363 
  1364 lemma psubsetE [elim!,noatp]: 
  1365     "[|A \<subset> B;  [|A \<subseteq> B; ~ (B\<subseteq>A)|] ==> R|] ==> R"
  1366   by (unfold less_le) blast
  1367 
  1368 lemma psubset_insert_iff:
  1369   "(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)"
  1370   by (auto simp add: less_le subset_insert_iff)
  1371 
  1372 lemma psubset_eq: "(A \<subset> B) = (A \<subseteq> B & A \<noteq> B)"
  1373   by (simp only: less_le)
  1374 
  1375 lemma psubset_imp_subset: "A \<subset> B ==> A \<subseteq> B"
  1376   by (simp add: psubset_eq)
  1377 
  1378 lemma psubset_trans: "[| A \<subset> B; B \<subset> C |] ==> A \<subset> C"
  1379 apply (unfold less_le)
  1380 apply (auto dest: subset_antisym)
  1381 done
  1382 
  1383 lemma psubsetD: "[| A \<subset> B; c \<in> A |] ==> c \<in> B"
  1384 apply (unfold less_le)
  1385 apply (auto dest: subsetD)
  1386 done
  1387 
  1388 lemma psubset_subset_trans: "A \<subset> B ==> B \<subseteq> C ==> A \<subset> C"
  1389   by (auto simp add: psubset_eq)
  1390 
  1391 lemma subset_psubset_trans: "A \<subseteq> B ==> B \<subset> C ==> A \<subset> C"
  1392   by (auto simp add: psubset_eq)
  1393 
  1394 lemma psubset_imp_ex_mem: "A \<subset> B ==> \<exists>b. b \<in> (B - A)"
  1395   by (unfold less_le) blast
  1396 
  1397 lemma atomize_ball:
  1398     "(!!x. x \<in> A ==> P x) == Trueprop (\<forall>x\<in>A. P x)"
  1399   by (simp only: Ball_def atomize_all atomize_imp)
  1400 
  1401 lemmas [symmetric, rulify] = atomize_ball
  1402   and [symmetric, defn] = atomize_ball
  1403 
  1404 subsubsection {* Derived rules involving subsets. *}
  1405 
  1406 text {* @{text insert}. *}
  1407 
  1408 lemma subset_insertI: "B \<subseteq> insert a B"
  1409   by (rule subsetI) (erule insertI2)
  1410 
  1411 lemma subset_insertI2: "A \<subseteq> B \<Longrightarrow> A \<subseteq> insert b B"
  1412   by blast
  1413 
  1414 lemma subset_insert: "x \<notin> A ==> (A \<subseteq> insert x B) = (A \<subseteq> B)"
  1415   by blast
  1416 
  1417 
  1418 text {* \medskip Big Union -- least upper bound of a set. *}
  1419 
  1420 lemma Union_upper: "B \<in> A ==> B \<subseteq> Union A"
  1421   by (iprover intro: subsetI UnionI)
  1422 
  1423 lemma Union_least: "(!!X. X \<in> A ==> X \<subseteq> C) ==> Union A \<subseteq> C"
  1424   by (iprover intro: subsetI elim: UnionE dest: subsetD)
  1425 
  1426 
  1427 text {* \medskip General union. *}
  1428 
  1429 lemma UN_upper: "a \<in> A ==> B a \<subseteq> (\<Union>x\<in>A. B x)"
  1430   by blast
  1431 
  1432 lemma UN_least: "(!!x. x \<in> A ==> B x \<subseteq> C) ==> (\<Union>x\<in>A. B x) \<subseteq> C"
  1433   by (iprover intro: subsetI elim: UN_E dest: subsetD)
  1434 
  1435 
  1436 text {* \medskip Big Intersection -- greatest lower bound of a set. *}
  1437 
  1438 lemma Inter_lower: "B \<in> A ==> Inter A \<subseteq> B"
  1439   by blast
  1440 
  1441 lemma Inter_subset:
  1442   "[| !!X. X \<in> A ==> X \<subseteq> B; A ~= {} |] ==> \<Inter>A \<subseteq> B"
  1443   by blast
  1444 
  1445 lemma Inter_greatest: "(!!X. X \<in> A ==> C \<subseteq> X) ==> C \<subseteq> Inter A"
  1446   by (iprover intro: InterI subsetI dest: subsetD)
  1447 
  1448 lemma INT_lower: "a \<in> A ==> (\<Inter>x\<in>A. B x) \<subseteq> B a"
  1449   by blast
  1450 
  1451 lemma INT_greatest: "(!!x. x \<in> A ==> C \<subseteq> B x) ==> C \<subseteq> (\<Inter>x\<in>A. B x)"
  1452   by (iprover intro: INT_I subsetI dest: subsetD)
  1453 
  1454 
  1455 text {* \medskip Finite Union -- the least upper bound of two sets. *}
  1456 
  1457 lemma Un_upper1: "A \<subseteq> A \<union> B"
  1458   by blast
  1459 
  1460 lemma Un_upper2: "B \<subseteq> A \<union> B"
  1461   by blast
  1462 
  1463 lemma Un_least: "A \<subseteq> C ==> B \<subseteq> C ==> A \<union> B \<subseteq> C"
  1464   by blast
  1465 
  1466 
  1467 text {* \medskip Finite Intersection -- the greatest lower bound of two sets. *}
  1468 
  1469 lemma Int_lower1: "A \<inter> B \<subseteq> A"
  1470   by blast
  1471 
  1472 lemma Int_lower2: "A \<inter> B \<subseteq> B"
  1473   by blast
  1474 
  1475 lemma Int_greatest: "C \<subseteq> A ==> C \<subseteq> B ==> C \<subseteq> A \<inter> B"
  1476   by blast
  1477 
  1478 
  1479 text {* \medskip Set difference. *}
  1480 
  1481 lemma Diff_subset: "A - B \<subseteq> A"
  1482   by blast
  1483 
  1484 lemma Diff_subset_conv: "(A - B \<subseteq> C) = (A \<subseteq> B \<union> C)"
  1485 by blast
  1486 
  1487 
  1488 subsubsection {* Equalities involving union, intersection, inclusion, etc. *}
  1489 
  1490 text {* @{text "{}"}. *}
  1491 
  1492 lemma Collect_const [simp]: "{s. P} = (if P then UNIV else {})"
  1493   -- {* supersedes @{text "Collect_False_empty"} *}
  1494   by auto
  1495 
  1496 lemma subset_empty [simp]: "(A \<subseteq> {}) = (A = {})"
  1497   by blast
  1498 
  1499 lemma not_psubset_empty [iff]: "\<not> (A < {})"
  1500   by (unfold less_le) blast
  1501 
  1502 lemma Collect_empty_eq [simp]: "(Collect P = {}) = (\<forall>x. \<not> P x)"
  1503 by blast
  1504 
  1505 lemma empty_Collect_eq [simp]: "({} = Collect P) = (\<forall>x. \<not> P x)"
  1506 by blast
  1507 
  1508 lemma Collect_neg_eq: "{x. \<not> P x} = - {x. P x}"
  1509   by blast
  1510 
  1511 lemma Collect_disj_eq: "{x. P x | Q x} = {x. P x} \<union> {x. Q x}"
  1512   by blast
  1513 
  1514 lemma Collect_imp_eq: "{x. P x --> Q x} = -{x. P x} \<union> {x. Q x}"
  1515   by blast
  1516 
  1517 lemma Collect_conj_eq: "{x. P x & Q x} = {x. P x} \<inter> {x. Q x}"
  1518   by blast
  1519 
  1520 lemma Collect_all_eq: "{x. \<forall>y. P x y} = (\<Inter>y. {x. P x y})"
  1521   by blast
  1522 
  1523 lemma Collect_ball_eq: "{x. \<forall>y\<in>A. P x y} = (\<Inter>y\<in>A. {x. P x y})"
  1524   by blast
  1525 
  1526 lemma Collect_ex_eq [noatp]: "{x. \<exists>y. P x y} = (\<Union>y. {x. P x y})"
  1527   by blast
  1528 
  1529 lemma Collect_bex_eq [noatp]: "{x. \<exists>y\<in>A. P x y} = (\<Union>y\<in>A. {x. P x y})"
  1530   by blast
  1531 
  1532 
  1533 text {* \medskip @{text insert}. *}
  1534 
  1535 lemma insert_is_Un: "insert a A = {a} Un A"
  1536   -- {* NOT SUITABLE FOR REWRITING since @{text "{a} == insert a {}"} *}
  1537   by blast
  1538 
  1539 lemma insert_not_empty [simp]: "insert a A \<noteq> {}"
  1540   by blast
  1541 
  1542 lemmas empty_not_insert = insert_not_empty [symmetric, standard]
  1543 declare empty_not_insert [simp]
  1544 
  1545 lemma insert_absorb: "a \<in> A ==> insert a A = A"
  1546   -- {* @{text "[simp]"} causes recursive calls when there are nested inserts *}
  1547   -- {* with \emph{quadratic} running time *}
  1548   by blast
  1549 
  1550 lemma insert_absorb2 [simp]: "insert x (insert x A) = insert x A"
  1551   by blast
  1552 
  1553 lemma insert_commute: "insert x (insert y A) = insert y (insert x A)"
  1554   by blast
  1555 
  1556 lemma insert_subset [simp]: "(insert x A \<subseteq> B) = (x \<in> B & A \<subseteq> B)"
  1557   by blast
  1558 
  1559 lemma mk_disjoint_insert: "a \<in> A ==> \<exists>B. A = insert a B & a \<notin> B"
  1560   -- {* use new @{text B} rather than @{text "A - {a}"} to avoid infinite unfolding *}
  1561   apply (rule_tac x = "A - {a}" in exI, blast)
  1562   done
  1563 
  1564 lemma insert_Collect: "insert a (Collect P) = {u. u \<noteq> a --> P u}"
  1565   by auto
  1566 
  1567 lemma UN_insert_distrib: "u \<in> A ==> (\<Union>x\<in>A. insert a (B x)) = insert a (\<Union>x\<in>A. B x)"
  1568   by blast
  1569 
  1570 lemma insert_inter_insert[simp]: "insert a A \<inter> insert a B = insert a (A \<inter> B)"
  1571   by blast
  1572 
  1573 lemma insert_disjoint [simp,noatp]:
  1574  "(insert a A \<inter> B = {}) = (a \<notin> B \<and> A \<inter> B = {})"
  1575  "({} = insert a A \<inter> B) = (a \<notin> B \<and> {} = A \<inter> B)"
  1576   by auto
  1577 
  1578 lemma disjoint_insert [simp,noatp]:
  1579  "(B \<inter> insert a A = {}) = (a \<notin> B \<and> B \<inter> A = {})"
  1580  "({} = A \<inter> insert b B) = (b \<notin> A \<and> {} = A \<inter> B)"
  1581   by auto
  1582 
  1583 text {* \medskip @{text image}. *}
  1584 
  1585 lemma image_empty [simp]: "f`{} = {}"
  1586   by blast
  1587 
  1588 lemma image_insert [simp]: "f ` insert a B = insert (f a) (f`B)"
  1589   by blast
  1590 
  1591 lemma image_constant: "x \<in> A ==> (\<lambda>x. c) ` A = {c}"
  1592   by auto
  1593 
  1594 lemma image_constant_conv: "(%x. c) ` A = (if A = {} then {} else {c})"
  1595 by auto
  1596 
  1597 lemma image_image: "f ` (g ` A) = (\<lambda>x. f (g x)) ` A"
  1598 by blast
  1599 
  1600 lemma insert_image [simp]: "x \<in> A ==> insert (f x) (f`A) = f`A"
  1601 by blast
  1602 
  1603 lemma image_is_empty [iff]: "(f`A = {}) = (A = {})"
  1604 by blast
  1605 
  1606 lemma empty_is_image[iff]: "({} = f ` A) = (A = {})"
  1607 by blast
  1608 
  1609 
  1610 lemma image_Collect [noatp]: "f ` {x. P x} = {f x | x. P x}"
  1611   -- {* NOT suitable as a default simprule: the RHS isn't simpler than the LHS,
  1612       with its implicit quantifier and conjunction.  Also image enjoys better
  1613       equational properties than does the RHS. *}
  1614   by blast
  1615 
  1616 lemma if_image_distrib [simp]:
  1617   "(\<lambda>x. if P x then f x else g x) ` S
  1618     = (f ` (S \<inter> {x. P x})) \<union> (g ` (S \<inter> {x. \<not> P x}))"
  1619   by (auto simp add: image_def)
  1620 
  1621 lemma image_cong: "M = N ==> (!!x. x \<in> N ==> f x = g x) ==> f`M = g`N"
  1622   by (simp add: image_def)
  1623 
  1624 
  1625 text {* \medskip @{text range}. *}
  1626 
  1627 lemma full_SetCompr_eq [noatp]: "{u. \<exists>x. u = f x} = range f"
  1628   by auto
  1629 
  1630 lemma range_composition: "range (\<lambda>x. f (g x)) = f`range g"
  1631 by (subst image_image, simp)
  1632 
  1633 
  1634 text {* \medskip @{text Int} *}
  1635 
  1636 lemma Int_absorb [simp]: "A \<inter> A = A"
  1637   by blast
  1638 
  1639 lemma Int_left_absorb: "A \<inter> (A \<inter> B) = A \<inter> B"
  1640   by blast
  1641 
  1642 lemma Int_commute: "A \<inter> B = B \<inter> A"
  1643   by blast
  1644 
  1645 lemma Int_left_commute: "A \<inter> (B \<inter> C) = B \<inter> (A \<inter> C)"
  1646   by blast
  1647 
  1648 lemma Int_assoc: "(A \<inter> B) \<inter> C = A \<inter> (B \<inter> C)"
  1649   by blast
  1650 
  1651 lemmas Int_ac = Int_assoc Int_left_absorb Int_commute Int_left_commute
  1652   -- {* Intersection is an AC-operator *}
  1653 
  1654 lemma Int_absorb1: "B \<subseteq> A ==> A \<inter> B = B"
  1655   by blast
  1656 
  1657 lemma Int_absorb2: "A \<subseteq> B ==> A \<inter> B = A"
  1658   by blast
  1659 
  1660 lemma Int_empty_left [simp]: "{} \<inter> B = {}"
  1661   by blast
  1662 
  1663 lemma Int_empty_right [simp]: "A \<inter> {} = {}"
  1664   by blast
  1665 
  1666 lemma disjoint_eq_subset_Compl: "(A \<inter> B = {}) = (A \<subseteq> -B)"
  1667   by blast
  1668 
  1669 lemma disjoint_iff_not_equal: "(A \<inter> B = {}) = (\<forall>x\<in>A. \<forall>y\<in>B. x \<noteq> y)"
  1670   by blast
  1671 
  1672 lemma Int_UNIV_left [simp]: "UNIV \<inter> B = B"
  1673   by blast
  1674 
  1675 lemma Int_UNIV_right [simp]: "A \<inter> UNIV = A"
  1676   by blast
  1677 
  1678 lemma Int_eq_Inter: "A \<inter> B = \<Inter>{A, B}"
  1679   by blast
  1680 
  1681 lemma Int_Un_distrib: "A \<inter> (B \<union> C) = (A \<inter> B) \<union> (A \<inter> C)"
  1682   by blast
  1683 
  1684 lemma Int_Un_distrib2: "(B \<union> C) \<inter> A = (B \<inter> A) \<union> (C \<inter> A)"
  1685   by blast
  1686 
  1687 lemma Int_UNIV [simp,noatp]: "(A \<inter> B = UNIV) = (A = UNIV & B = UNIV)"
  1688   by blast
  1689 
  1690 lemma Int_subset_iff [simp]: "(C \<subseteq> A \<inter> B) = (C \<subseteq> A & C \<subseteq> B)"
  1691   by blast
  1692 
  1693 lemma Int_Collect: "(x \<in> A \<inter> {x. P x}) = (x \<in> A & P x)"
  1694   by blast
  1695 
  1696 
  1697 text {* \medskip @{text Un}. *}
  1698 
  1699 lemma Un_absorb [simp]: "A \<union> A = A"
  1700   by blast
  1701 
  1702 lemma Un_left_absorb: "A \<union> (A \<union> B) = A \<union> B"
  1703   by blast
  1704 
  1705 lemma Un_commute: "A \<union> B = B \<union> A"
  1706   by blast
  1707 
  1708 lemma Un_left_commute: "A \<union> (B \<union> C) = B \<union> (A \<union> C)"
  1709   by blast
  1710 
  1711 lemma Un_assoc: "(A \<union> B) \<union> C = A \<union> (B \<union> C)"
  1712   by blast
  1713 
  1714 lemmas Un_ac = Un_assoc Un_left_absorb Un_commute Un_left_commute
  1715   -- {* Union is an AC-operator *}
  1716 
  1717 lemma Un_absorb1: "A \<subseteq> B ==> A \<union> B = B"
  1718   by blast
  1719 
  1720 lemma Un_absorb2: "B \<subseteq> A ==> A \<union> B = A"
  1721   by blast
  1722 
  1723 lemma Un_empty_left [simp]: "{} \<union> B = B"
  1724   by blast
  1725 
  1726 lemma Un_empty_right [simp]: "A \<union> {} = A"
  1727   by blast
  1728 
  1729 lemma Un_UNIV_left [simp]: "UNIV \<union> B = UNIV"
  1730   by blast
  1731 
  1732 lemma Un_UNIV_right [simp]: "A \<union> UNIV = UNIV"
  1733   by blast
  1734 
  1735 lemma Un_eq_Union: "A \<union> B = \<Union>{A, B}"
  1736   by blast
  1737 
  1738 lemma Un_insert_left [simp]: "(insert a B) \<union> C = insert a (B \<union> C)"
  1739   by blast
  1740 
  1741 lemma Un_insert_right [simp]: "A \<union> (insert a B) = insert a (A \<union> B)"
  1742   by blast
  1743 
  1744 lemma Int_insert_left:
  1745     "(insert a B) Int C = (if a \<in> C then insert a (B \<inter> C) else B \<inter> C)"
  1746   by auto
  1747 
  1748 lemma Int_insert_right:
  1749     "A \<inter> (insert a B) = (if a \<in> A then insert a (A \<inter> B) else A \<inter> B)"
  1750   by auto
  1751 
  1752 lemma Un_Int_distrib: "A \<union> (B \<inter> C) = (A \<union> B) \<inter> (A \<union> C)"
  1753   by blast
  1754 
  1755 lemma Un_Int_distrib2: "(B \<inter> C) \<union> A = (B \<union> A) \<inter> (C \<union> A)"
  1756   by blast
  1757 
  1758 lemma Un_Int_crazy:
  1759     "(A \<inter> B) \<union> (B \<inter> C) \<union> (C \<inter> A) = (A \<union> B) \<inter> (B \<union> C) \<inter> (C \<union> A)"
  1760   by blast
  1761 
  1762 lemma subset_Un_eq: "(A \<subseteq> B) = (A \<union> B = B)"
  1763   by blast
  1764 
  1765 lemma Un_empty [iff]: "(A \<union> B = {}) = (A = {} & B = {})"
  1766   by blast
  1767 
  1768 lemma Un_subset_iff [simp]: "(A \<union> B \<subseteq> C) = (A \<subseteq> C & B \<subseteq> C)"
  1769   by blast
  1770 
  1771 lemma Un_Diff_Int: "(A - B) \<union> (A \<inter> B) = A"
  1772   by blast
  1773 
  1774 lemma Diff_Int2: "A \<inter> C - B \<inter> C = A \<inter> C - B"
  1775   by blast
  1776 
  1777 
  1778 text {* \medskip Set complement *}
  1779 
  1780 lemma Compl_disjoint [simp]: "A \<inter> -A = {}"
  1781   by blast
  1782 
  1783 lemma Compl_disjoint2 [simp]: "-A \<inter> A = {}"
  1784   by blast
  1785 
  1786 lemma Compl_partition: "A \<union> -A = UNIV"
  1787   by blast
  1788 
  1789 lemma Compl_partition2: "-A \<union> A = UNIV"
  1790   by blast
  1791 
  1792 lemma double_complement [simp]: "- (-A) = (A::'a set)"
  1793   by blast
  1794 
  1795 lemma Compl_Un [simp]: "-(A \<union> B) = (-A) \<inter> (-B)"
  1796   by blast
  1797 
  1798 lemma Compl_Int [simp]: "-(A \<inter> B) = (-A) \<union> (-B)"
  1799   by blast
  1800 
  1801 lemma Compl_UN [simp]: "-(\<Union>x\<in>A. B x) = (\<Inter>x\<in>A. -B x)"
  1802   by blast
  1803 
  1804 lemma Compl_INT [simp]: "-(\<Inter>x\<in>A. B x) = (\<Union>x\<in>A. -B x)"
  1805   by blast
  1806 
  1807 lemma subset_Compl_self_eq: "(A \<subseteq> -A) = (A = {})"
  1808   by blast
  1809 
  1810 lemma Un_Int_assoc_eq: "((A \<inter> B) \<union> C = A \<inter> (B \<union> C)) = (C \<subseteq> A)"
  1811   -- {* Halmos, Naive Set Theory, page 16. *}
  1812   by blast
  1813 
  1814 lemma Compl_UNIV_eq [simp]: "-UNIV = {}"
  1815   by blast
  1816 
  1817 lemma Compl_empty_eq [simp]: "-{} = UNIV"
  1818   by blast
  1819 
  1820 lemma Compl_subset_Compl_iff [iff]: "(-A \<subseteq> -B) = (B \<subseteq> A)"
  1821   by blast
  1822 
  1823 lemma Compl_eq_Compl_iff [iff]: "(-A = -B) = (A = (B::'a set))"
  1824   by blast
  1825 
  1826 
  1827 text {* \medskip @{text Union}. *}
  1828 
  1829 lemma Union_empty [simp]: "Union({}) = {}"
  1830   by blast
  1831 
  1832 lemma Union_UNIV [simp]: "Union UNIV = UNIV"
  1833   by blast
  1834 
  1835 lemma Union_insert [simp]: "Union (insert a B) = a \<union> \<Union>B"
  1836   by blast
  1837 
  1838 lemma Union_Un_distrib [simp]: "\<Union>(A Un B) = \<Union>A \<union> \<Union>B"
  1839   by blast
  1840 
  1841 lemma Union_Int_subset: "\<Union>(A \<inter> B) \<subseteq> \<Union>A \<inter> \<Union>B"
  1842   by blast
  1843 
  1844 lemma Union_empty_conv [simp,noatp]: "(\<Union>A = {}) = (\<forall>x\<in>A. x = {})"
  1845   by blast
  1846 
  1847 lemma empty_Union_conv [simp,noatp]: "({} = \<Union>A) = (\<forall>x\<in>A. x = {})"
  1848   by blast
  1849 
  1850 lemma Union_disjoint: "(\<Union>C \<inter> A = {}) = (\<forall>B\<in>C. B \<inter> A = {})"
  1851   by blast
  1852 
  1853 
  1854 text {* \medskip @{text Inter}. *}
  1855 
  1856 lemma Inter_empty [simp]: "\<Inter>{} = UNIV"
  1857   by blast
  1858 
  1859 lemma Inter_UNIV [simp]: "\<Inter>UNIV = {}"
  1860   by blast
  1861 
  1862 lemma Inter_insert [simp]: "\<Inter>(insert a B) = a \<inter> \<Inter>B"
  1863   by blast
  1864 
  1865 lemma Inter_Un_subset: "\<Inter>A \<union> \<Inter>B \<subseteq> \<Inter>(A \<inter> B)"
  1866   by blast
  1867 
  1868 lemma Inter_Un_distrib: "\<Inter>(A \<union> B) = \<Inter>A \<inter> \<Inter>B"
  1869   by blast
  1870 
  1871 lemma Inter_UNIV_conv [simp,noatp]:
  1872   "(\<Inter>A = UNIV) = (\<forall>x\<in>A. x = UNIV)"
  1873   "(UNIV = \<Inter>A) = (\<forall>x\<in>A. x = UNIV)"
  1874   by blast+
  1875 
  1876 
  1877 text {*
  1878   \medskip @{text UN} and @{text INT}.
  1879 
  1880   Basic identities: *}
  1881 
  1882 lemma UN_empty [simp,noatp]: "(\<Union>x\<in>{}. B x) = {}"
  1883   by blast
  1884 
  1885 lemma UN_empty2 [simp]: "(\<Union>x\<in>A. {}) = {}"
  1886   by blast
  1887 
  1888 lemma UN_singleton [simp]: "(\<Union>x\<in>A. {x}) = A"
  1889   by blast
  1890 
  1891 lemma UN_absorb: "k \<in> I ==> A k \<union> (\<Union>i\<in>I. A i) = (\<Union>i\<in>I. A i)"
  1892   by auto
  1893 
  1894 lemma INT_empty [simp]: "(\<Inter>x\<in>{}. B x) = UNIV"
  1895   by blast
  1896 
  1897 lemma INT_absorb: "k \<in> I ==> A k \<inter> (\<Inter>i\<in>I. A i) = (\<Inter>i\<in>I. A i)"
  1898   by blast
  1899 
  1900 lemma UN_insert [simp]: "(\<Union>x\<in>insert a A. B x) = B a \<union> UNION A B"
  1901   by blast
  1902 
  1903 lemma UN_Un[simp]: "(\<Union>i \<in> A \<union> B. M i) = (\<Union>i\<in>A. M i) \<union> (\<Union>i\<in>B. M i)"
  1904   by blast
  1905 
  1906 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)"
  1907   by blast
  1908 
  1909 lemma UN_subset_iff: "((\<Union>i\<in>I. A i) \<subseteq> B) = (\<forall>i\<in>I. A i \<subseteq> B)"
  1910   by blast
  1911 
  1912 lemma INT_subset_iff: "(B \<subseteq> (\<Inter>i\<in>I. A i)) = (\<forall>i\<in>I. B \<subseteq> A i)"
  1913   by blast
  1914 
  1915 lemma INT_insert [simp]: "(\<Inter>x \<in> insert a A. B x) = B a \<inter> INTER A B"
  1916   by blast
  1917 
  1918 lemma INT_Un: "(\<Inter>i \<in> A \<union> B. M i) = (\<Inter>i \<in> A. M i) \<inter> (\<Inter>i\<in>B. M i)"
  1919   by blast
  1920 
  1921 lemma INT_insert_distrib:
  1922     "u \<in> A ==> (\<Inter>x\<in>A. insert a (B x)) = insert a (\<Inter>x\<in>A. B x)"
  1923   by blast
  1924 
  1925 lemma image_Union: "f ` \<Union>S = (\<Union>x\<in>S. f ` x)"
  1926   by blast
  1927 
  1928 lemma UN_constant [simp]: "(\<Union>y\<in>A. c) = (if A = {} then {} else c)"
  1929   by auto
  1930 
  1931 lemma INT_constant [simp]: "(\<Inter>y\<in>A. c) = (if A = {} then UNIV else c)"
  1932   by auto
  1933 
  1934 lemma UN_eq: "(\<Union>x\<in>A. B x) = \<Union>({Y. \<exists>x\<in>A. Y = B x})"
  1935   by blast
  1936 
  1937 lemma INT_eq: "(\<Inter>x\<in>A. B x) = \<Inter>({Y. \<exists>x\<in>A. Y = B x})"
  1938   -- {* Look: it has an \emph{existential} quantifier *}
  1939   by blast
  1940 
  1941 lemma UNION_empty_conv[simp]:
  1942   "({} = (UN x:A. B x)) = (\<forall>x\<in>A. B x = {})"
  1943   "((UN x:A. B x) = {}) = (\<forall>x\<in>A. B x = {})"
  1944 by blast+
  1945 
  1946 lemma INTER_UNIV_conv[simp]:
  1947  "(UNIV = (INT x:A. B x)) = (\<forall>x\<in>A. B x = UNIV)"
  1948  "((INT x:A. B x) = UNIV) = (\<forall>x\<in>A. B x = UNIV)"
  1949 by blast+
  1950 
  1951 
  1952 text {* \medskip Distributive laws: *}
  1953 
  1954 lemma Int_Union: "A \<inter> \<Union>B = (\<Union>C\<in>B. A \<inter> C)"
  1955   by blast
  1956 
  1957 lemma Int_Union2: "\<Union>B \<inter> A = (\<Union>C\<in>B. C \<inter> A)"
  1958   by blast
  1959 
  1960 lemma Un_Union_image: "(\<Union>x\<in>C. A x \<union> B x) = \<Union>(A`C) \<union> \<Union>(B`C)"
  1961   -- {* Devlin, Fundamentals of Contemporary Set Theory, page 12, exercise 5: *}
  1962   -- {* Union of a family of unions *}
  1963   by blast
  1964 
  1965 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)"
  1966   -- {* Equivalent version *}
  1967   by blast
  1968 
  1969 lemma Un_Inter: "A \<union> \<Inter>B = (\<Inter>C\<in>B. A \<union> C)"
  1970   by blast
  1971 
  1972 lemma Int_Inter_image: "(\<Inter>x\<in>C. A x \<inter> B x) = \<Inter>(A`C) \<inter> \<Inter>(B`C)"
  1973   by blast
  1974 
  1975 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)"
  1976   -- {* Equivalent version *}
  1977   by blast
  1978 
  1979 lemma Int_UN_distrib: "B \<inter> (\<Union>i\<in>I. A i) = (\<Union>i\<in>I. B \<inter> A i)"
  1980   -- {* Halmos, Naive Set Theory, page 35. *}
  1981   by blast
  1982 
  1983 lemma Un_INT_distrib: "B \<union> (\<Inter>i\<in>I. A i) = (\<Inter>i\<in>I. B \<union> A i)"
  1984   by blast
  1985 
  1986 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)"
  1987   by blast
  1988 
  1989 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)"
  1990   by blast
  1991 
  1992 
  1993 text {* \medskip Bounded quantifiers.
  1994 
  1995   The following are not added to the default simpset because
  1996   (a) they duplicate the body and (b) there are no similar rules for @{text Int}. *}
  1997 
  1998 lemma ball_Un: "(\<forall>x \<in> A \<union> B. P x) = ((\<forall>x\<in>A. P x) & (\<forall>x\<in>B. P x))"
  1999   by blast
  2000 
  2001 lemma bex_Un: "(\<exists>x \<in> A \<union> B. P x) = ((\<exists>x\<in>A. P x) | (\<exists>x\<in>B. P x))"
  2002   by blast
  2003 
  2004 lemma ball_UN: "(\<forall>z \<in> UNION A B. P z) = (\<forall>x\<in>A. \<forall>z \<in> B x. P z)"
  2005   by blast
  2006 
  2007 lemma bex_UN: "(\<exists>z \<in> UNION A B. P z) = (\<exists>x\<in>A. \<exists>z\<in>B x. P z)"
  2008   by blast
  2009 
  2010 
  2011 text {* \medskip Set difference. *}
  2012 
  2013 lemma Diff_eq: "A - B = A \<inter> (-B)"
  2014   by blast
  2015 
  2016 lemma Diff_eq_empty_iff [simp,noatp]: "(A - B = {}) = (A \<subseteq> B)"
  2017   by blast
  2018 
  2019 lemma Diff_cancel [simp]: "A - A = {}"
  2020   by blast
  2021 
  2022 lemma Diff_idemp [simp]: "(A - B) - B = A - (B::'a set)"
  2023 by blast
  2024 
  2025 lemma Diff_triv: "A \<inter> B = {} ==> A - B = A"
  2026   by (blast elim: equalityE)
  2027 
  2028 lemma empty_Diff [simp]: "{} - A = {}"
  2029   by blast
  2030 
  2031 lemma Diff_empty [simp]: "A - {} = A"
  2032   by blast
  2033 
  2034 lemma Diff_UNIV [simp]: "A - UNIV = {}"
  2035   by blast
  2036 
  2037 lemma Diff_insert0 [simp,noatp]: "x \<notin> A ==> A - insert x B = A - B"
  2038   by blast
  2039 
  2040 lemma Diff_insert: "A - insert a B = A - B - {a}"
  2041   -- {* NOT SUITABLE FOR REWRITING since @{text "{a} == insert a 0"} *}
  2042   by blast
  2043 
  2044 lemma Diff_insert2: "A - insert a B = A - {a} - B"
  2045   -- {* NOT SUITABLE FOR REWRITING since @{text "{a} == insert a 0"} *}
  2046   by blast
  2047 
  2048 lemma insert_Diff_if: "insert x A - B = (if x \<in> B then A - B else insert x (A - B))"
  2049   by auto
  2050 
  2051 lemma insert_Diff1 [simp]: "x \<in> B ==> insert x A - B = A - B"
  2052   by blast
  2053 
  2054 lemma insert_Diff_single[simp]: "insert a (A - {a}) = insert a A"
  2055 by blast
  2056 
  2057 lemma insert_Diff: "a \<in> A ==> insert a (A - {a}) = A"
  2058   by blast
  2059 
  2060 lemma Diff_insert_absorb: "x \<notin> A ==> (insert x A) - {x} = A"
  2061   by auto
  2062 
  2063 lemma Diff_disjoint [simp]: "A \<inter> (B - A) = {}"
  2064   by blast
  2065 
  2066 lemma Diff_partition: "A \<subseteq> B ==> A \<union> (B - A) = B"
  2067   by blast
  2068 
  2069 lemma double_diff: "A \<subseteq> B ==> B \<subseteq> C ==> B - (C - A) = A"
  2070   by blast
  2071 
  2072 lemma Un_Diff_cancel [simp]: "A \<union> (B - A) = A \<union> B"
  2073   by blast
  2074 
  2075 lemma Un_Diff_cancel2 [simp]: "(B - A) \<union> A = B \<union> A"
  2076   by blast
  2077 
  2078 lemma Diff_Un: "A - (B \<union> C) = (A - B) \<inter> (A - C)"
  2079   by blast
  2080 
  2081 lemma Diff_Int: "A - (B \<inter> C) = (A - B) \<union> (A - C)"
  2082   by blast
  2083 
  2084 lemma Un_Diff: "(A \<union> B) - C = (A - C) \<union> (B - C)"
  2085   by blast
  2086 
  2087 lemma Int_Diff: "(A \<inter> B) - C = A \<inter> (B - C)"
  2088   by blast
  2089 
  2090 lemma Diff_Int_distrib: "C \<inter> (A - B) = (C \<inter> A) - (C \<inter> B)"
  2091   by blast
  2092 
  2093 lemma Diff_Int_distrib2: "(A - B) \<inter> C = (A \<inter> C) - (B \<inter> C)"
  2094   by blast
  2095 
  2096 lemma Diff_Compl [simp]: "A - (- B) = A \<inter> B"
  2097   by auto
  2098 
  2099 lemma Compl_Diff_eq [simp]: "- (A - B) = -A \<union> B"
  2100   by blast
  2101 
  2102 
  2103 text {* \medskip Quantification over type @{typ bool}. *}
  2104 
  2105 lemma bool_induct: "P True \<Longrightarrow> P False \<Longrightarrow> P x"
  2106   by (cases x) auto
  2107 
  2108 lemma all_bool_eq: "(\<forall>b. P b) \<longleftrightarrow> P True \<and> P False"
  2109   by (auto intro: bool_induct)
  2110 
  2111 lemma bool_contrapos: "P x \<Longrightarrow> \<not> P False \<Longrightarrow> P True"
  2112   by (cases x) auto
  2113 
  2114 lemma ex_bool_eq: "(\<exists>b. P b) \<longleftrightarrow> P True \<or> P False"
  2115   by (auto intro: bool_contrapos)
  2116 
  2117 lemma Un_eq_UN: "A \<union> B = (\<Union>b. if b then A else B)"
  2118   by (auto simp add: split_if_mem2)
  2119 
  2120 lemma UN_bool_eq: "(\<Union>b::bool. A b) = (A True \<union> A False)"
  2121   by (auto intro: bool_contrapos)
  2122 
  2123 lemma INT_bool_eq: "(\<Inter>b::bool. A b) = (A True \<inter> A False)"
  2124   by (auto intro: bool_induct)
  2125 
  2126 text {* \medskip @{text Pow} *}
  2127 
  2128 lemma Pow_empty [simp]: "Pow {} = {{}}"
  2129   by (auto simp add: Pow_def)
  2130 
  2131 lemma Pow_insert: "Pow (insert a A) = Pow A \<union> (insert a ` Pow A)"
  2132   by (blast intro: image_eqI [where ?x = "u - {a}", standard])
  2133 
  2134 lemma Pow_Compl: "Pow (- A) = {-B | B. A \<in> Pow B}"
  2135   by (blast intro: exI [where ?x = "- u", standard])
  2136 
  2137 lemma Pow_UNIV [simp]: "Pow UNIV = UNIV"
  2138   by blast
  2139 
  2140 lemma Un_Pow_subset: "Pow A \<union> Pow B \<subseteq> Pow (A \<union> B)"
  2141   by blast
  2142 
  2143 lemma UN_Pow_subset: "(\<Union>x\<in>A. Pow (B x)) \<subseteq> Pow (\<Union>x\<in>A. B x)"
  2144   by blast
  2145 
  2146 lemma subset_Pow_Union: "A \<subseteq> Pow (\<Union>A)"
  2147   by blast
  2148 
  2149 lemma Union_Pow_eq [simp]: "\<Union>(Pow A) = A"
  2150   by blast
  2151 
  2152 lemma Pow_Int_eq [simp]: "Pow (A \<inter> B) = Pow A \<inter> Pow B"
  2153   by blast
  2154 
  2155 lemma Pow_INT_eq: "Pow (\<Inter>x\<in>A. B x) = (\<Inter>x\<in>A. Pow (B x))"
  2156   by blast
  2157 
  2158 
  2159 text {* \medskip Miscellany. *}
  2160 
  2161 lemma set_eq_subset: "(A = B) = (A \<subseteq> B & B \<subseteq> A)"
  2162   by blast
  2163 
  2164 lemma subset_iff: "(A \<subseteq> B) = (\<forall>t. t \<in> A --> t \<in> B)"
  2165   by blast
  2166 
  2167 lemma subset_iff_psubset_eq: "(A \<subseteq> B) = ((A \<subset> B) | (A = B))"
  2168   by (unfold less_le) blast
  2169 
  2170 lemma all_not_in_conv [simp]: "(\<forall>x. x \<notin> A) = (A = {})"
  2171   by blast
  2172 
  2173 lemma ex_in_conv: "(\<exists>x. x \<in> A) = (A \<noteq> {})"
  2174   by blast
  2175 
  2176 lemma distinct_lemma: "f x \<noteq> f y ==> x \<noteq> y"
  2177   by iprover
  2178 
  2179 
  2180 text {* \medskip Miniscoping: pushing in quantifiers and big Unions
  2181            and Intersections. *}
  2182 
  2183 lemma UN_simps [simp]:
  2184   "!!a B C. (UN x:C. insert a (B x)) = (if C={} then {} else insert a (UN x:C. B x))"
  2185   "!!A B C. (UN x:C. A x Un B)   = ((if C={} then {} else (UN x:C. A x) Un B))"
  2186   "!!A B C. (UN x:C. A Un B x)   = ((if C={} then {} else A Un (UN x:C. B x)))"
  2187   "!!A B C. (UN x:C. A x Int B)  = ((UN x:C. A x) Int B)"
  2188   "!!A B C. (UN x:C. A Int B x)  = (A Int (UN x:C. B x))"
  2189   "!!A B C. (UN x:C. A x - B)    = ((UN x:C. A x) - B)"
  2190   "!!A B C. (UN x:C. A - B x)    = (A - (INT x:C. B x))"
  2191   "!!A B. (UN x: Union A. B x) = (UN y:A. UN x:y. B x)"
  2192   "!!A B C. (UN z: UNION A B. C z) = (UN  x:A. UN z: B(x). C z)"
  2193   "!!A B f. (UN x:f`A. B x)     = (UN a:A. B (f a))"
  2194   by auto
  2195 
  2196 lemma INT_simps [simp]:
  2197   "!!A B C. (INT x:C. A x Int B) = (if C={} then UNIV else (INT x:C. A x) Int B)"
  2198   "!!A B C. (INT x:C. A Int B x) = (if C={} then UNIV else A Int (INT x:C. B x))"
  2199   "!!A B C. (INT x:C. A x - B)   = (if C={} then UNIV else (INT x:C. A x) - B)"
  2200   "!!A B C. (INT x:C. A - B x)   = (if C={} then UNIV else A - (UN x:C. B x))"
  2201   "!!a B C. (INT x:C. insert a (B x)) = insert a (INT x:C. B x)"
  2202   "!!A B C. (INT x:C. A x Un B)  = ((INT x:C. A x) Un B)"
  2203   "!!A B C. (INT x:C. A Un B x)  = (A Un (INT x:C. B x))"
  2204   "!!A B. (INT x: Union A. B x) = (INT y:A. INT x:y. B x)"
  2205   "!!A B C. (INT z: UNION A B. C z) = (INT x:A. INT z: B(x). C z)"
  2206   "!!A B f. (INT x:f`A. B x)    = (INT a:A. B (f a))"
  2207   by auto
  2208 
  2209 lemma ball_simps [simp,noatp]:
  2210   "!!A P Q. (ALL x:A. P x | Q) = ((ALL x:A. P x) | Q)"
  2211   "!!A P Q. (ALL x:A. P | Q x) = (P | (ALL x:A. Q x))"
  2212   "!!A P Q. (ALL x:A. P --> Q x) = (P --> (ALL x:A. Q x))"
  2213   "!!A P Q. (ALL x:A. P x --> Q) = ((EX x:A. P x) --> Q)"
  2214   "!!P. (ALL x:{}. P x) = True"
  2215   "!!P. (ALL x:UNIV. P x) = (ALL x. P x)"
  2216   "!!a B P. (ALL x:insert a B. P x) = (P a & (ALL x:B. P x))"
  2217   "!!A P. (ALL x:Union A. P x) = (ALL y:A. ALL x:y. P x)"
  2218   "!!A B P. (ALL x: UNION A B. P x) = (ALL a:A. ALL x: B a. P x)"
  2219   "!!P Q. (ALL x:Collect Q. P x) = (ALL x. Q x --> P x)"
  2220   "!!A P f. (ALL x:f`A. P x) = (ALL x:A. P (f x))"
  2221   "!!A P. (~(ALL x:A. P x)) = (EX x:A. ~P x)"
  2222   by auto
  2223 
  2224 lemma bex_simps [simp,noatp]:
  2225   "!!A P Q. (EX x:A. P x & Q) = ((EX x:A. P x) & Q)"
  2226   "!!A P Q. (EX x:A. P & Q x) = (P & (EX x:A. Q x))"
  2227   "!!P. (EX x:{}. P x) = False"
  2228   "!!P. (EX x:UNIV. P x) = (EX x. P x)"
  2229   "!!a B P. (EX x:insert a B. P x) = (P(a) | (EX x:B. P x))"
  2230   "!!A P. (EX x:Union A. P x) = (EX y:A. EX x:y. P x)"
  2231   "!!A B P. (EX x: UNION A B. P x) = (EX a:A. EX x:B a. P x)"
  2232   "!!P Q. (EX x:Collect Q. P x) = (EX x. Q x & P x)"
  2233   "!!A P f. (EX x:f`A. P x) = (EX x:A. P (f x))"
  2234   "!!A P. (~(EX x:A. P x)) = (ALL x:A. ~P x)"
  2235   by auto
  2236 
  2237 lemma ball_conj_distrib:
  2238   "(ALL x:A. P x & Q x) = ((ALL x:A. P x) & (ALL x:A. Q x))"
  2239   by blast
  2240 
  2241 lemma bex_disj_distrib:
  2242   "(EX x:A. P x | Q x) = ((EX x:A. P x) | (EX x:A. Q x))"
  2243   by blast
  2244 
  2245 
  2246 text {* \medskip Maxiscoping: pulling out big Unions and Intersections. *}
  2247 
  2248 lemma UN_extend_simps:
  2249   "!!a B C. insert a (UN x:C. B x) = (if C={} then {a} else (UN x:C. insert a (B x)))"
  2250   "!!A B C. (UN x:C. A x) Un B    = (if C={} then B else (UN x:C. A x Un B))"
  2251   "!!A B C. A Un (UN x:C. B x)   = (if C={} then A else (UN x:C. A Un B x))"
  2252   "!!A B C. ((UN x:C. A x) Int B) = (UN x:C. A x Int B)"
  2253   "!!A B C. (A Int (UN x:C. B x)) = (UN x:C. A Int B x)"
  2254   "!!A B C. ((UN x:C. A x) - B) = (UN x:C. A x - B)"
  2255   "!!A B C. (A - (INT x:C. B x)) = (UN x:C. A - B x)"
  2256   "!!A B. (UN y:A. UN x:y. B x) = (UN x: Union A. B x)"
  2257   "!!A B C. (UN  x:A. UN z: B(x). C z) = (UN z: UNION A B. C z)"
  2258   "!!A B f. (UN a:A. B (f a)) = (UN x:f`A. B x)"
  2259   by auto
  2260 
  2261 lemma INT_extend_simps:
  2262   "!!A B C. (INT x:C. A x) Int B = (if C={} then B else (INT x:C. A x Int B))"
  2263   "!!A B C. A Int (INT x:C. B x) = (if C={} then A else (INT x:C. A Int B x))"
  2264   "!!A B C. (INT x:C. A x) - B   = (if C={} then UNIV-B else (INT x:C. A x - B))"
  2265   "!!A B C. A - (UN x:C. B x)   = (if C={} then A else (INT x:C. A - B x))"
  2266   "!!a B C. insert a (INT x:C. B x) = (INT x:C. insert a (B x))"
  2267   "!!A B C. ((INT x:C. A x) Un B)  = (INT x:C. A x Un B)"
  2268   "!!A B C. A Un (INT x:C. B x)  = (INT x:C. A Un B x)"
  2269   "!!A B. (INT y:A. INT x:y. B x) = (INT x: Union A. B x)"
  2270   "!!A B C. (INT x:A. INT z: B(x). C z) = (INT z: UNION A B. C z)"
  2271   "!!A B f. (INT a:A. B (f a))    = (INT x:f`A. B x)"
  2272   by auto
  2273 
  2274 
  2275 subsubsection {* Monotonicity of various operations *}
  2276 
  2277 lemma image_mono: "A \<subseteq> B ==> f`A \<subseteq> f`B"
  2278   by blast
  2279 
  2280 lemma Pow_mono: "A \<subseteq> B ==> Pow A \<subseteq> Pow B"
  2281   by blast
  2282 
  2283 lemma Union_mono: "A \<subseteq> B ==> \<Union>A \<subseteq> \<Union>B"
  2284   by blast
  2285 
  2286 lemma Inter_anti_mono: "B \<subseteq> A ==> \<Inter>A \<subseteq> \<Inter>B"
  2287   by blast
  2288 
  2289 lemma UN_mono:
  2290   "A \<subseteq> B ==> (!!x. x \<in> A ==> f x \<subseteq> g x) ==>
  2291     (\<Union>x\<in>A. f x) \<subseteq> (\<Union>x\<in>B. g x)"
  2292   by (blast dest: subsetD)
  2293 
  2294 lemma INT_anti_mono:
  2295   "B \<subseteq> A ==> (!!x. x \<in> A ==> f x \<subseteq> g x) ==>
  2296     (\<Inter>x\<in>A. f x) \<subseteq> (\<Inter>x\<in>A. g x)"
  2297   -- {* The last inclusion is POSITIVE! *}
  2298   by (blast dest: subsetD)
  2299 
  2300 lemma insert_mono: "C \<subseteq> D ==> insert a C \<subseteq> insert a D"
  2301   by blast
  2302 
  2303 lemma Un_mono: "A \<subseteq> C ==> B \<subseteq> D ==> A \<union> B \<subseteq> C \<union> D"
  2304   by blast
  2305 
  2306 lemma Int_mono: "A \<subseteq> C ==> B \<subseteq> D ==> A \<inter> B \<subseteq> C \<inter> D"
  2307   by blast
  2308 
  2309 lemma Diff_mono: "A \<subseteq> C ==> D \<subseteq> B ==> A - B \<subseteq> C - D"
  2310   by blast
  2311 
  2312 lemma Compl_anti_mono: "A \<subseteq> B ==> -B \<subseteq> -A"
  2313   by blast
  2314 
  2315 text {* \medskip Monotonicity of implications. *}
  2316 
  2317 lemma in_mono: "A \<subseteq> B ==> x \<in> A --> x \<in> B"
  2318   apply (rule impI)
  2319   apply (erule subsetD, assumption)
  2320   done
  2321 
  2322 lemma conj_mono: "P1 --> Q1 ==> P2 --> Q2 ==> (P1 & P2) --> (Q1 & Q2)"
  2323   by iprover
  2324 
  2325 lemma disj_mono: "P1 --> Q1 ==> P2 --> Q2 ==> (P1 | P2) --> (Q1 | Q2)"
  2326   by iprover
  2327 
  2328 lemma imp_mono: "Q1 --> P1 ==> P2 --> Q2 ==> (P1 --> P2) --> (Q1 --> Q2)"
  2329   by iprover
  2330 
  2331 lemma imp_refl: "P --> P" ..
  2332 
  2333 lemma ex_mono: "(!!x. P x --> Q x) ==> (EX x. P x) --> (EX x. Q x)"
  2334   by iprover
  2335 
  2336 lemma all_mono: "(!!x. P x --> Q x) ==> (ALL x. P x) --> (ALL x. Q x)"
  2337   by iprover
  2338 
  2339 lemma Collect_mono: "(!!x. P x --> Q x) ==> Collect P \<subseteq> Collect Q"
  2340   by blast
  2341 
  2342 lemma Int_Collect_mono:
  2343     "A \<subseteq> B ==> (!!x. x \<in> A ==> P x --> Q x) ==> A \<inter> Collect P \<subseteq> B \<inter> Collect Q"
  2344   by blast
  2345 
  2346 lemmas basic_monos =
  2347   subset_refl imp_refl disj_mono conj_mono
  2348   ex_mono Collect_mono in_mono
  2349 
  2350 lemma eq_to_mono: "a = b ==> c = d ==> b --> d ==> a --> c"
  2351   by iprover
  2352 
  2353 lemma eq_to_mono2: "a = b ==> c = d ==> ~ b --> ~ d ==> ~ a --> ~ c"
  2354   by iprover
  2355 
  2356 
  2357 subsubsection {* Inverse image of a function *}
  2358 
  2359 constdefs
  2360   vimage :: "('a => 'b) => 'b set => 'a set"    (infixr "-`" 90)
  2361   [code del]: "f -` B == {x. f x : B}"
  2362 
  2363 lemma vimage_eq [simp]: "(a : f -` B) = (f a : B)"
  2364   by (unfold vimage_def) blast
  2365 
  2366 lemma vimage_singleton_eq: "(a : f -` {b}) = (f a = b)"
  2367   by simp
  2368 
  2369 lemma vimageI [intro]: "f a = b ==> b:B ==> a : f -` B"
  2370   by (unfold vimage_def) blast
  2371 
  2372 lemma vimageI2: "f a : A ==> a : f -` A"
  2373   by (unfold vimage_def) fast
  2374 
  2375 lemma vimageE [elim!]: "a: f -` B ==> (!!x. f a = x ==> x:B ==> P) ==> P"
  2376   by (unfold vimage_def) blast
  2377 
  2378 lemma vimageD: "a : f -` A ==> f a : A"
  2379   by (unfold vimage_def) fast
  2380 
  2381 lemma vimage_empty [simp]: "f -` {} = {}"
  2382   by blast
  2383 
  2384 lemma vimage_Compl: "f -` (-A) = -(f -` A)"
  2385   by blast
  2386 
  2387 lemma vimage_Un [simp]: "f -` (A Un B) = (f -` A) Un (f -` B)"
  2388   by blast
  2389 
  2390 lemma vimage_Int [simp]: "f -` (A Int B) = (f -` A) Int (f -` B)"
  2391   by fast
  2392 
  2393 lemma vimage_Union: "f -` (Union A) = (UN X:A. f -` X)"
  2394   by blast
  2395 
  2396 lemma vimage_UN: "f-`(UN x:A. B x) = (UN x:A. f -` B x)"
  2397   by blast
  2398 
  2399 lemma vimage_INT: "f-`(INT x:A. B x) = (INT x:A. f -` B x)"
  2400   by blast
  2401 
  2402 lemma vimage_Collect_eq [simp]: "f -` Collect P = {y. P (f y)}"
  2403   by blast
  2404 
  2405 lemma vimage_Collect: "(!!x. P (f x) = Q x) ==> f -` (Collect P) = Collect Q"
  2406   by blast
  2407 
  2408 lemma vimage_insert: "f-`(insert a B) = (f-`{a}) Un (f-`B)"
  2409   -- {* NOT suitable for rewriting because of the recurrence of @{term "{a}"}. *}
  2410   by blast
  2411 
  2412 lemma vimage_Diff: "f -` (A - B) = (f -` A) - (f -` B)"
  2413   by blast
  2414 
  2415 lemma vimage_UNIV [simp]: "f -` UNIV = UNIV"
  2416   by blast
  2417 
  2418 lemma vimage_eq_UN: "f-`B = (UN y: B. f-`{y})"
  2419   -- {* NOT suitable for rewriting *}
  2420   by blast
  2421 
  2422 lemma vimage_mono: "A \<subseteq> B ==> f -` A \<subseteq> f -` B"
  2423   -- {* monotonicity *}
  2424   by blast
  2425 
  2426 lemma vimage_image_eq [noatp]: "f -` (f ` A) = {y. EX x:A. f x = f y}"
  2427 by (blast intro: sym)
  2428 
  2429 lemma image_vimage_subset: "f ` (f -` A) <= A"
  2430 by blast
  2431 
  2432 lemma image_vimage_eq [simp]: "f ` (f -` A) = A Int range f"
  2433 by blast
  2434 
  2435 lemma image_Int_subset: "f`(A Int B) <= f`A Int f`B"
  2436 by blast
  2437 
  2438 lemma image_diff_subset: "f`A - f`B <= f`(A - B)"
  2439 by blast
  2440 
  2441 lemma image_UN: "(f ` (UNION A B)) = (UN x:A.(f ` (B x)))"
  2442 by blast
  2443 
  2444 
  2445 subsubsection {* Getting the Contents of a Singleton Set *}
  2446 
  2447 definition contents :: "'a set \<Rightarrow> 'a" where
  2448   [code del]: "contents X = (THE x. X = {x})"
  2449 
  2450 lemma contents_eq [simp]: "contents {x} = x"
  2451   by (simp add: contents_def)
  2452 
  2453 
  2454 subsubsection {* Least value operator *}
  2455 
  2456 lemma Least_mono:
  2457   "mono (f::'a::order => 'b::order) ==> EX x:S. ALL y:S. x <= y
  2458     ==> (LEAST y. y : f ` S) = f (LEAST x. x : S)"
  2459     -- {* Courtesy of Stephan Merz *}
  2460   apply clarify
  2461   apply (erule_tac P = "%x. x : S" in LeastI2_order, fast)
  2462   apply (rule LeastI2_order)
  2463   apply (auto elim: monoD intro!: order_antisym)
  2464   done
  2465 
  2466 subsection {* Misc *}
  2467 
  2468 text {* Rudimentary code generation *}
  2469 
  2470 lemma empty_code [code]: "{} x \<longleftrightarrow> False"
  2471   unfolding empty_def Collect_def ..
  2472 
  2473 lemma UNIV_code [code]: "UNIV x \<longleftrightarrow> True"
  2474   unfolding UNIV_def Collect_def ..
  2475 
  2476 lemma insert_code [code]: "insert y A x \<longleftrightarrow> y = x \<or> A x"
  2477   unfolding insert_def Collect_def mem_def Un_def by auto
  2478 
  2479 lemma inter_code [code]: "(A \<inter> B) x \<longleftrightarrow> A x \<and> B x"
  2480   unfolding Int_def Collect_def mem_def ..
  2481 
  2482 lemma union_code [code]: "(A \<union> B) x \<longleftrightarrow> A x \<or> B x"
  2483   unfolding Un_def Collect_def mem_def ..
  2484 
  2485 lemma vimage_code [code]: "(f -` A) x = A (f x)"
  2486   unfolding vimage_def Collect_def mem_def ..
  2487 
  2488 text {* Misc theorem and ML bindings *}
  2489 
  2490 lemmas equalityI = subset_antisym
  2491 lemmas mem_simps =
  2492   insert_iff empty_iff Un_iff Int_iff Compl_iff Diff_iff
  2493   mem_Collect_eq UN_iff Union_iff INT_iff Inter_iff
  2494   -- {* Each of these has ALREADY been added @{text "[simp]"} above. *}
  2495 
  2496 ML {*
  2497 val Ball_def = @{thm Ball_def}
  2498 val Bex_def = @{thm Bex_def}
  2499 val CollectD = @{thm CollectD}
  2500 val CollectE = @{thm CollectE}
  2501 val CollectI = @{thm CollectI}
  2502 val Collect_conj_eq = @{thm Collect_conj_eq}
  2503 val Collect_mem_eq = @{thm Collect_mem_eq}
  2504 val IntD1 = @{thm IntD1}
  2505 val IntD2 = @{thm IntD2}
  2506 val IntE = @{thm IntE}
  2507 val IntI = @{thm IntI}
  2508 val Int_Collect = @{thm Int_Collect}
  2509 val UNIV_I = @{thm UNIV_I}
  2510 val UNIV_witness = @{thm UNIV_witness}
  2511 val UnE = @{thm UnE}
  2512 val UnI1 = @{thm UnI1}
  2513 val UnI2 = @{thm UnI2}
  2514 val ballE = @{thm ballE}
  2515 val ballI = @{thm ballI}
  2516 val bexCI = @{thm bexCI}
  2517 val bexE = @{thm bexE}
  2518 val bexI = @{thm bexI}
  2519 val bex_triv = @{thm bex_triv}
  2520 val bspec = @{thm bspec}
  2521 val contra_subsetD = @{thm contra_subsetD}
  2522 val distinct_lemma = @{thm distinct_lemma}
  2523 val eq_to_mono = @{thm eq_to_mono}
  2524 val eq_to_mono2 = @{thm eq_to_mono2}
  2525 val equalityCE = @{thm equalityCE}
  2526 val equalityD1 = @{thm equalityD1}
  2527 val equalityD2 = @{thm equalityD2}
  2528 val equalityE = @{thm equalityE}
  2529 val equalityI = @{thm equalityI}
  2530 val imageE = @{thm imageE}
  2531 val imageI = @{thm imageI}
  2532 val image_Un = @{thm image_Un}
  2533 val image_insert = @{thm image_insert}
  2534 val insert_commute = @{thm insert_commute}
  2535 val insert_iff = @{thm insert_iff}
  2536 val mem_Collect_eq = @{thm mem_Collect_eq}
  2537 val rangeE = @{thm rangeE}
  2538 val rangeI = @{thm rangeI}
  2539 val range_eqI = @{thm range_eqI}
  2540 val subsetCE = @{thm subsetCE}
  2541 val subsetD = @{thm subsetD}
  2542 val subsetI = @{thm subsetI}
  2543 val subset_refl = @{thm subset_refl}
  2544 val subset_trans = @{thm subset_trans}
  2545 val vimageD = @{thm vimageD}
  2546 val vimageE = @{thm vimageE}
  2547 val vimageI = @{thm vimageI}
  2548 val vimageI2 = @{thm vimageI2}
  2549 val vimage_Collect = @{thm vimage_Collect}
  2550 val vimage_Int = @{thm vimage_Int}
  2551 val vimage_Un = @{thm vimage_Un}
  2552 *}
  2553 
  2554 end