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