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