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