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